in components/sync15/src/clients_engine/engine.rs [406:557]
fn test_clients_sync() {
let processor = TestProcessor {
settings: Settings {
fxa_device_id: "deviceAAAAAA".into(),
device_name: "Laptop".into(),
device_type: DeviceType::Desktop,
},
outgoing_commands: [
Command::Wipe("bookmarks".into()),
Command::Reset("history".into()),
]
.iter()
.cloned()
.collect(),
};
let config = InfoConfiguration::default();
let mut driver = Driver::new(&processor, &NeverInterrupts, &config);
let inbound = inbound_from_clients(json!([{
"id": "deviceBBBBBB",
"name": "iPhone",
"type": "mobile",
"commands": [{
"command": "resetEngine",
"args": ["history"],
}],
"fxaDeviceId": "iPhooooooone",
"protocols": ["1.5"],
"device": "iPhone",
}, {
"id": "deviceCCCCCC",
"name": "Fenix",
"type": "mobile",
"commands": [],
"fxaDeviceId": "deviceCCCCCC",
}, {
"id": "deviceAAAAAA",
"name": "Laptop with a different name",
"type": "desktop",
"commands": [{
"command": "wipeEngine",
"args": ["logins"]
}, {
"command": "displayURI",
"args": ["http://example.com", "Fennec", "Example page"],
"flowID": "flooooooooow",
}, {
"command": "resetEngine",
"args": ["forms"],
}, {
"command": "logout",
"args": [],
}],
"fxaDeviceId": "deviceAAAAAA",
}]));
// Passing false for `should_refresh_client` - it should be ignored
// because we've changed the commands.
let mut outgoing = driver.sync(inbound, false).expect("Should sync clients");
outgoing.sort_by(|a, b| a.envelope.id.cmp(&b.envelope.id));
// Make sure the list of recently synced remote clients is correct.
let expected_ids = &["deviceAAAAAA", "deviceBBBBBB", "deviceCCCCCC"];
let mut actual_ids = driver.recent_clients.keys().collect::<Vec<&String>>();
actual_ids.sort();
assert_eq!(actual_ids, expected_ids);
let expected_remote_clients = &[
RemoteClient {
fxa_device_id: Some("deviceAAAAAA".to_string()),
device_name: "Laptop".into(),
device_type: DeviceType::Desktop,
},
RemoteClient {
fxa_device_id: Some("iPhooooooone".to_string()),
device_name: "iPhone".into(),
device_type: DeviceType::Mobile,
},
RemoteClient {
fxa_device_id: Some("deviceCCCCCC".to_string()),
device_name: "Fenix".into(),
device_type: DeviceType::Mobile,
},
];
let actual_remote_clients = expected_ids
.iter()
.filter_map(|&id| driver.recent_clients.get(id))
.cloned()
.collect::<Vec<RemoteClient>>();
assert_eq!(actual_remote_clients, expected_remote_clients);
let expected = json!([{
"id": "deviceAAAAAA",
"name": "Laptop",
"type": "desktop",
"commands": [{
"command": "displayURI",
"args": ["http://example.com", "Fennec", "Example page"],
"flowID": "flooooooooow",
}, {
"command": "resetEngine",
"args": ["forms"],
}, {
"command": "logout",
"args": [],
}],
"fxaDeviceId": "deviceAAAAAA",
"protocols": ["1.5"],
}, {
"id": "deviceBBBBBB",
"name": "iPhone",
"type": "mobile",
"commands": [{
"command": "resetEngine",
"args": ["history"],
}, {
"command": "wipeEngine",
"args": ["bookmarks"],
}],
"fxaDeviceId": "iPhooooooone",
"protocols": ["1.5"],
"device": "iPhone",
}, {
"id": "deviceCCCCCC",
"name": "Fenix",
"type": "mobile",
"commands": [{
"command": "wipeEngine",
"args": ["bookmarks"],
}, {
"command": "resetEngine",
"args": ["history"],
}],
"fxaDeviceId": "deviceCCCCCC",
}]);
// turn outgoing into an incoming payload.
let incoming = outgoing
.into_iter()
.map(|c| OutgoingBso::to_test_incoming(&c))
.collect::<Vec<IncomingBso>>();
if let Value::Array(expected) = expected {
for (incoming_cleartext, exp_client) in zip(incoming, expected) {
let incoming_client: ClientRecord =
incoming_cleartext.into_content().content().unwrap();
assert_eq!(incoming_client, serde_json::from_value(exp_client).unwrap());
}
} else {
unreachable!("`expected_clients` must be an array of client records")
}
}