use playwright_rs::protocol::{BrowserContextOptions, ProxySettings, Viewport};
#[test]
fn test_proxy_settings_serialization() {
let proxy = ProxySettings::new("http://proxy.example.com:8080")
.bypass(".example.com, localhost")
.username("user")
.password("secret");
let json = serde_json::to_value(&proxy).expect("Failed to serialize");
assert_eq!(json["server"], "http://proxy.example.com:8080");
assert_eq!(json["bypass"], ".example.com, localhost");
assert_eq!(json["username"], "user");
assert_eq!(json["password"], "secret");
}
#[test]
fn test_proxy_settings_minimal() {
let proxy = ProxySettings::new("socks5://proxy:1080");
let json = serde_json::to_value(&proxy).expect("Failed to serialize");
assert_eq!(json["server"], "socks5://proxy:1080");
assert!(json.get("bypass").is_none());
assert!(json.get("username").is_none());
assert!(json.get("password").is_none());
}
#[test]
fn test_browser_context_options_with_proxy() {
let options = BrowserContextOptions::builder()
.proxy(ProxySettings::new("http://localhost:8888"))
.build();
assert!(options.proxy.is_some());
assert_eq!(options.proxy.unwrap().server, "http://localhost:8888");
}
#[test]
fn test_browser_context_options_serialization_with_proxy() {
let options = BrowserContextOptions::builder()
.viewport(Viewport {
width: 1920,
height: 1080,
})
.proxy(ProxySettings::new("http://proxy:3128").bypass(".internal.com"))
.build();
let json = serde_json::to_value(&options).expect("Failed to serialize");
assert_eq!(json["viewport"]["width"], 1920);
assert_eq!(json["viewport"]["height"], 1080);
assert_eq!(json["proxy"]["server"], "http://proxy:3128");
assert_eq!(json["proxy"]["bypass"], ".internal.com");
}
#[test]
fn test_proxy_settings_backward_compat_import() {
use playwright_rs::api::ProxySettings as ApiProxySettings;
let proxy = ApiProxySettings::new("http://test:8080");
assert_eq!(proxy.server, "http://test:8080");
}