BlueGit

ict rusty-teams

Files

rusty-teams / crates / browser / tests / kvt_live_chrome.rs

kvt_live_chrome.rs

kvt_live_chrome.rs 1.6 KiB Download Raw
1//! KVT-fork: the extra sign-in tab (`kvt_open_tab`) on a real Chrome.
2
3use std::time::Duration;
4
5use browser::{Browser, Config};
6
7const TEST_PORT: u16 = 9445;
8
9#[tokio::test]
10#[ignore = "starts a real Chrome on port 9445 with a throwaway profile"]
11async fn kvt_tab_opens_the_exact_url_evaluates_and_closes() {
12 let profile_name = format!("rusty-teams-kvt-test-{}", std::process::id());
13 let config = Config::detect()
14 .unwrap()
15 .with_port(TEST_PORT)
16 .with_profile_name(&profile_name);
17 let mode_file = config.mode_file.clone();
18 let profile_directory = mode_file.with_extension("");
19 let browser = Browser::new(config);
20 assert!(!browser.is_running().await, "port {TEST_PORT} is in use");
21
22 let outcome = async {
23 browser.ensure_running().await.unwrap();
24 let url = "data:text/html,<p>ok</p><script>window.kvt=location.href</script>#a=1&b=%20c";
25 let tab = browser.kvt_open_tab(url).await.unwrap();
26 tokio::time::sleep(Duration::from_secs(1)).await;
27 let href = browser.kvt_evaluate(&tab, "window.kvt").await.unwrap();
28 assert_eq!(href.as_str(), Some(url));
29 let tabs_before = browser.tabs().await.unwrap().len();
30 browser.kvt_close_tab(&tab).await.unwrap();
31 tokio::time::sleep(Duration::from_millis(500)).await;
32 assert_eq!(browser.tabs().await.unwrap().len(), tabs_before - 1);
33 browser.stop().await.unwrap();
34 }
35 .await;
36
37 let _ = browser.stop().await;
38 tokio::time::sleep(Duration::from_secs(2)).await;
39 let _ = std::fs::remove_dir_all(&profile_directory);
40 let _ = std::fs::remove_file(&mode_file);
41 outcome
42}