forked from gsalucci/firefox-profiles-to-ram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-persistence.sh
More file actions
executable file
·118 lines (95 loc) · 4.07 KB
/
test-persistence.sh
File metadata and controls
executable file
·118 lines (95 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# Firefox Tab Persistence Test
# Verifies that data is correctly synced between RAM and Disk
set -euo pipefail
readonly PROFILES_HOME="$HOME/.config/mozilla/firefox"
readonly PROFILES_RAM="/dev/shm/$USER/browser-profiles"
readonly TEST_FILE="test-persistence-$(date +%s).txt"
# Colors
readonly GREEN='\033[0;32m'
readonly RED='\033[0;31m'
readonly NC='\033[0m'
info() { echo -e "[INFO] $*"; }
success() { echo -e "${GREEN}[SUCCESS] $*${NC}"; }
error() { echo -e "${RED}[ERROR] $*${NC}" >&2; return 1; }
main() {
info "Firefox Persistence Test"
info "========================"
# 0. Find a profile to test
if [[ ! -d "$PROFILES_RAM" ]]; then
error "RAM directory not found: $PROFILES_RAM. Is the service initialized?"
exit 1
fi
# Get the first directory in PROFILES_RAM
local TEST_PROFILE_PATH=$(find "$PROFILES_RAM" -mindepth 1 -maxdepth 1 -type d | head -n 1)
if [[ -z "$TEST_PROFILE_PATH" ]]; then
error "No profiles found in RAM ($PROFILES_RAM). Run 'browser-to-ram-utils init' first."
exit 1
fi
local TEST_PROFILE=$(basename "$TEST_PROFILE_PATH")
info "Testing with profile: $TEST_PROFILE"
# Step 0.5: Ensure service is running (simulating user login)
info "Step 0.5: Ensuring service is active..."
if ! systemctl --user is-active --quiet browser-to-ram-utils.service; then
info "Service not active. Starting it..."
systemctl --user start browser-to-ram-utils.service
success "Service started."
else
info "Service already active."
fi
# Step 1: Create a test file in RAM
info "Step 1: Creating test file in RAM..."
echo "TEST_DATA_$(date +%s)" > "$TEST_PROFILE_PATH/$TEST_FILE"
success "Created: $TEST_PROFILE_PATH/$TEST_FILE"
# Step 2: Verify it's NOT in the backup yet
info "Step 2: Verify file not yet in backup..."
if [[ -f "$PROFILES_HOME/$TEST_PROFILE.bak/$TEST_FILE" ]]; then
error "File should not be in backup yet!"
exit 1
fi
success "File correctly NOT in backup yet"
# Step 3: Stop the service (triggers ExecStop -> store)
info "Step 3: Stopping service (triggers profile store)..."
systemctl --user stop browser-to-ram-utils.service
# Wait a moment for the sync to complete (systemctl stop blocks until ExecStop finishes, but just in case)
sleep 1
success "Service stopped."
# Step 4: Verify file is now in the backup
info "Step 4: Verify file was stored to backup..."
if [[ ! -f "$PROFILES_HOME/$TEST_PROFILE.bak/$TEST_FILE" ]]; then
error "File was not stored to backup! ExecStop may not have run or failed."
exit 1
fi
success "File correctly stored in backup: $PROFILES_HOME/$TEST_PROFILE.bak/$TEST_FILE"
# Step 5: Restart service (loads from backup to RAM)
# Note: When we stopped the service, the RAM might have been cleared or not depending on implementation.
# But 'load' should ensure it's consistent.
info "Step 5: Restarting service to reload profile..."
systemctl --user start browser-to-ram-utils.service
sleep 1
success "Service restarted"
# Step 6: Verify file is back in RAM
info "Step 6: Verify file reloaded from backup to RAM..."
if [[ ! -f "$TEST_PROFILE_PATH/$TEST_FILE" ]]; then
error "File was not reloaded to RAM!"
exit 1
fi
success "File correctly reloaded to RAM"
# Step 7: Compare contents
info "Step 7: Verifying data integrity..."
RAM_CONTENT=$(cat "$TEST_PROFILE_PATH/$TEST_FILE")
BACKUP_CONTENT=$(cat "$PROFILES_HOME/$TEST_PROFILE.bak/$TEST_FILE")
if [[ "$RAM_CONTENT" != "$BACKUP_CONTENT" ]]; then
error "Data mismatch! RAM: $RAM_CONTENT, BACKUP: $BACKUP_CONTENT"
exit 1
fi
success "Data integrity verified: $RAM_CONTENT"
# Cleanup
info "Cleanup: Removing test file..."
rm "$TEST_PROFILE_PATH/$TEST_FILE"
rm "$PROFILES_HOME/$TEST_PROFILE.bak/$TEST_FILE"
success "Test files removed"
info "========================"
success "All tests passed!"
}
main "$@"