use browsing::browser::{Browser, BrowserProfile};
#[test]
fn test_browser_selects_page_target() {
let profile = BrowserProfile::default();
assert_eq!(profile.headless, None);
assert_eq!(profile.user_data_dir, None);
let target_types = vec!["page", "iframe", "service_worker", "worker"];
for target_type in target_types {
assert!(!target_type.is_empty());
}
assert_eq!("page", "page");
}
#[test]
fn test_get_current_url_returns_actual_url() {
let test_urls = vec![
("https://example.com", true, true),
("http://localhost:8080", true, true),
("about:blank", false, false),
("chrome://newtab", false, false),
("chrome-extension://abc123/popup.html", false, false),
("data:text/html,<test>", false, false),
];
for (url, is_http_https, should_navigate) in test_urls {
let is_valid = url.starts_with("http://") || url.starts_with("https://");
assert_eq!(
is_valid, is_http_https,
"URL {} should be valid http/https",
url
);
}
let url = "https://www.example.com/path?query=value";
assert!(url.contains("example.com"));
assert!(url.contains("/path"));
assert!(url.contains("query=value"));
}
#[test]
fn test_full_navigation_workflow() {
let navigation_steps = vec![
"https://example.com",
"https://www.bing.com",
"https://www.github.com",
"https://www.stackoverflow.com",
];
for url in &navigation_steps {
assert!(url.starts_with("https://"), "URL {} should be https", url);
assert!(!url.is_empty());
}
assert_eq!(navigation_steps.len(), 4);
let domains: Vec<&str> = navigation_steps
.iter()
.map(|url| url.split("://").nth(1).unwrap_or(""))
.collect();
assert_eq!(domains.len(), 4);
}
#[test]
fn test_page_title_and_url_retrieval() {
let test_pages = vec![
("https://example.com", "Example Domain"),
("https://www.bing.com", "Bing"),
("https://www.github.com", "GitHub"),
];
for (url, expected_title_part) in test_pages {
assert!(url.starts_with("https://"));
assert!(!url.is_empty());
assert!(!expected_title_part.is_empty());
}
let page_titles = vec![
"Example Domain",
"Bing",
"GitHub: Where the world builds software",
"Stack Overflow - Where Developers Learn, Share, & Build",
];
for title in page_titles {
assert!(!title.is_empty());
assert!(title.len() > 3);
}
}
#[test]
fn test_screenshot_with_correct_cdp_parameters() {
let screenshot_tests = vec![
(true, None, None), (false, Some("#main"), None), (false, None, Some(0)), ];
for (full_page, selector, element_index) in screenshot_tests {
assert!((!full_page) || (selector.is_none() && element_index.is_none()));
if let Some(sel) = selector {
assert!(!sel.is_empty());
}
}
let valid_paths = vec![
"/tmp/screenshot.png",
"screenshot.jpg",
"./images/capture.png",
];
for path in valid_paths {
assert!(!path.is_empty());
assert!(path.ends_with(".png") || path.ends_with(".jpg") || path.ends_with(".jpeg"));
}
}
#[test]
fn test_multiple_navigation_operations() {
let urls = vec![
"https://example.com",
"https://www.bing.com",
"https://www.github.com",
"https://www.stackoverflow.com",
];
for url in &urls {
assert!(url.starts_with("https://"));
assert!(!url.is_empty());
}
let domains: Vec<&str> = urls
.iter()
.map(|url| {
url.split("://")
.nth(1)
.and_then(|s| s.split('/').next())
.unwrap_or("")
})
.collect();
let expected_domains = vec![
"example.com",
"www.bing.com",
"www.github.com",
"www.stackoverflow.com",
];
assert_eq!(domains.len(), expected_domains.len());
for (domain, expected) in domains.iter().zip(expected_domains.iter()) {
assert_eq!(domain, expected);
}
}