mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-08-10 05:00:43 +02:00
test: cleanup
This commit is contained in:
@@ -1030,8 +1030,135 @@ mod tests {
|
||||
let (manager, _temp_dir) = create_test_profile_manager();
|
||||
let profiles_dir = manager.get_profiles_dir();
|
||||
|
||||
assert!(profiles_dir.to_string_lossy().contains("DonutBrowser"));
|
||||
assert!(profiles_dir.to_string_lossy().contains("profiles"));
|
||||
assert!(
|
||||
profiles_dir.to_string_lossy().contains("DonutBrowser"),
|
||||
"Profiles dir should contain DonutBrowser"
|
||||
);
|
||||
assert!(
|
||||
profiles_dir.to_string_lossy().contains("profiles"),
|
||||
"Profiles dir should contain profiles"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_profiles_empty() {
|
||||
let (manager, _temp_dir) = create_test_profile_manager();
|
||||
|
||||
let result = manager.list_profiles();
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Should successfully list profiles even when empty"
|
||||
);
|
||||
|
||||
let profiles = result.unwrap();
|
||||
assert!(
|
||||
profiles.is_empty(),
|
||||
"Should return empty vector when no profiles exist"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_common_firefox_preferences() {
|
||||
let (manager, _temp_dir) = create_test_profile_manager();
|
||||
|
||||
let prefs = manager.get_common_firefox_preferences();
|
||||
assert!(!prefs.is_empty(), "Should return non-empty preferences");
|
||||
|
||||
// Check for some expected preferences
|
||||
let prefs_string = prefs.join("\n");
|
||||
assert!(
|
||||
prefs_string.contains("browser.shell.checkDefaultBrowser"),
|
||||
"Should contain default browser check preference"
|
||||
);
|
||||
assert!(
|
||||
prefs_string.contains("app.update.enabled"),
|
||||
"Should contain update preference"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_binaries_dir() {
|
||||
let (manager, _temp_dir) = create_test_profile_manager();
|
||||
|
||||
let binaries_dir = manager.get_binaries_dir();
|
||||
let path_str = binaries_dir.to_string_lossy();
|
||||
|
||||
assert!(
|
||||
path_str.contains("DonutBrowser"),
|
||||
"Binaries dir should contain DonutBrowser"
|
||||
);
|
||||
assert!(
|
||||
path_str.contains("binaries"),
|
||||
"Binaries dir should contain binaries"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_disable_proxy_settings_in_profile() {
|
||||
let (manager, temp_dir) = create_test_profile_manager();
|
||||
|
||||
// Create a test profile directory
|
||||
let profile_dir = temp_dir.path().join("test_profile");
|
||||
fs::create_dir_all(&profile_dir).expect("Should create profile directory");
|
||||
|
||||
let result = manager.disable_proxy_settings_in_profile(&profile_dir);
|
||||
assert!(result.is_ok(), "Should successfully disable proxy settings");
|
||||
|
||||
// Check that user.js was created
|
||||
let user_js_path = profile_dir.join("user.js");
|
||||
assert!(user_js_path.exists(), "user.js should be created");
|
||||
|
||||
let content = fs::read_to_string(&user_js_path).expect("Should read user.js");
|
||||
assert!(
|
||||
content.contains("network.proxy.type"),
|
||||
"Should contain proxy type setting"
|
||||
);
|
||||
assert!(
|
||||
content.contains("0"),
|
||||
"Should set proxy type to 0 (no proxy)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_apply_proxy_settings_to_profile() {
|
||||
let (manager, temp_dir) = create_test_profile_manager();
|
||||
|
||||
// Create a test profile directory structure
|
||||
let uuid_dir = temp_dir.path().join("test_uuid");
|
||||
let profile_dir = uuid_dir.join("profile");
|
||||
fs::create_dir_all(&profile_dir).expect("Should create profile directory");
|
||||
|
||||
let proxy_settings = ProxySettings {
|
||||
proxy_type: "http".to_string(),
|
||||
host: "proxy.example.com".to_string(),
|
||||
port: 8080,
|
||||
username: Some("user".to_string()),
|
||||
password: Some("pass".to_string()),
|
||||
};
|
||||
|
||||
let result = manager.apply_proxy_settings_to_profile(&profile_dir, &proxy_settings, None);
|
||||
assert!(result.is_ok(), "Should successfully apply proxy settings");
|
||||
|
||||
// Check that user.js was created
|
||||
let user_js_path = profile_dir.join("user.js");
|
||||
assert!(user_js_path.exists(), "user.js should be created");
|
||||
|
||||
let content = fs::read_to_string(&user_js_path).expect("Should read user.js");
|
||||
assert!(
|
||||
content.contains("network.proxy.type"),
|
||||
"Should contain proxy type setting"
|
||||
);
|
||||
assert!(content.contains("2"), "Should set proxy type to 2 (PAC)");
|
||||
|
||||
// Check that PAC file was created
|
||||
let pac_path = uuid_dir.join("proxy.pac");
|
||||
assert!(pac_path.exists(), "proxy.pac should be created");
|
||||
|
||||
let pac_content = fs::read_to_string(&pac_path).expect("Should read proxy.pac");
|
||||
assert!(
|
||||
pac_content.contains("FindProxyForURL"),
|
||||
"PAC file should contain FindProxyForURL function"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user