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
use crate::auth::TestClient;
use crate::testing::TestGroup;
use anyhow::Result;
use tabs::{ClientRemoteTabs, DeviceType, RemoteTab, TabsEngine};
pub fn verify_tabs(tabs_engine: &TabsEngine, expected: &ClientRemoteTabs) {
let remote_tabs = tabs_engine
.remote_tabs()
.expect("should have synced already");
let equivalent = remote_tabs
.iter()
.find(|rt| rt.client_id == expected.client_id)
.expect("should have found the remote tabs");
assert_remote_tabs_equiv(&equivalent, expected);
}
pub fn assert_remote_tabs_equiv(l: &ClientRemoteTabs, r: &ClientRemoteTabs) {
assert_eq!(l.client_id, r.client_id);
assert_eq!(l.remote_tabs.len(), r.remote_tabs.len());
let iter = l.remote_tabs.iter().zip(r.remote_tabs.iter());
for (l, r) in iter {
assert_eq!(l.title, r.title);
assert_eq!(l.icon, r.icon);
assert_eq!(l.url_history, r.url_history);
assert_eq!((l.last_used / 1000) * 1000, (r.last_used / 1000) * 1000);
}
}
pub fn sync_tabs(client: &mut TestClient) -> Result<()> {
let (init, key, device_id) = client.data_for_sync()?;
client.tabs_engine.sync(&init, &key, &device_id)?;
Ok(())
}
fn test_tabs(c0: &mut TestClient, c1: &mut TestClient) {
log::info!("Update tabs on c0");
let t0 = RemoteTab {
icon: None,
last_used: 1_572_265_044_661,
title: "Welcome to Bobo".to_owned(),
url_history: vec!["https://bobo.moz".to_owned()],
};
c0.tabs_engine.update_local_state(vec![t0.clone()]);
sync_tabs(c0).expect("c0 sync to work");
sync_tabs(c1).expect("c1 sync to work");
verify_tabs(
&c1.tabs_engine,
&ClientRemoteTabs {
client_id: c0.fxa.get_current_device_id().unwrap(),
client_name: String::new(),
device_type: DeviceType::Mobile,
remote_tabs: vec![t0],
},
);
let t1 = RemoteTab {
icon: None,
last_used: 1_572_267_197_207,
title: "Foo".to_owned(),
url_history: vec!["https://foo.org".to_owned()],
};
let t2 = RemoteTab {
icon: None,
last_used: 1_572_267_191_104,
title: "Bar".to_owned(),
url_history: vec!["https://bar.org".to_owned()],
};
c1.tabs_engine
.update_local_state(vec![t1.clone(), t2.clone()]);
sync_tabs(c1).expect("c1 sync to work");
sync_tabs(c0).expect("c0 sync to work");
verify_tabs(
&c0.tabs_engine,
&ClientRemoteTabs {
client_id: c1.fxa.get_current_device_id().unwrap(),
client_name: String::new(),
device_type: DeviceType::Mobile,
remote_tabs: vec![t1, t2],
},
);
}
pub fn get_test_group() -> TestGroup {
TestGroup::new("tabs", vec![("test_tabs", test_tabs)])
}