Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 Cu.import("resource://services-sync/identity.js");
5 Cu.import("resource://services-sync/engines.js");
6 Cu.import("resource://services-sync/record.js");
7 Cu.import("resource://services-sync/service.js");
8 Cu.import("resource://services-sync/util.js");
9 Cu.import("resource://testing-common/services/sync/utils.js");
11 Service.engineManager.clear();
13 function CanDecryptEngine() {
14 SyncEngine.call(this, "CanDecrypt", Service);
15 }
16 CanDecryptEngine.prototype = {
17 __proto__: SyncEngine.prototype,
19 // Override these methods with mocks for the test
20 canDecrypt: function canDecrypt() {
21 return true;
22 },
24 wasWiped: false,
25 wipeClient: function wipeClient() {
26 this.wasWiped = true;
27 }
28 };
29 Service.engineManager.register(CanDecryptEngine);
32 function CannotDecryptEngine() {
33 SyncEngine.call(this, "CannotDecrypt", Service);
34 }
35 CannotDecryptEngine.prototype = {
36 __proto__: SyncEngine.prototype,
38 // Override these methods with mocks for the test
39 canDecrypt: function canDecrypt() {
40 return false;
41 },
43 wasWiped: false,
44 wipeClient: function wipeClient() {
45 this.wasWiped = true;
46 }
47 };
48 Service.engineManager.register(CannotDecryptEngine);
51 add_test(function test_withEngineList() {
52 try {
53 _("Ensure initial scenario.");
54 do_check_false(Service.engineManager.get("candecrypt").wasWiped);
55 do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped);
57 _("Wipe local engine data.");
58 Service.wipeClient(["candecrypt", "cannotdecrypt"]);
60 _("Ensure only the engine that can decrypt was wiped.");
61 do_check_true(Service.engineManager.get("candecrypt").wasWiped);
62 do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped);
63 } finally {
64 Service.engineManager.get("candecrypt").wasWiped = false;
65 Service.engineManager.get("cannotdecrypt").wasWiped = false;
66 Service.startOver();
67 }
69 run_next_test();
70 });
72 add_test(function test_startOver_clears_keys() {
73 generateNewKeys(Service.collectionKeys);
74 do_check_true(!!Service.collectionKeys.keyForCollection());
75 Service.startOver();
76 do_check_false(!!Service.collectionKeys.keyForCollection());
78 run_next_test();
79 });
81 add_test(function test_credentials_preserved() {
82 _("Ensure that credentials are preserved if client is wiped.");
84 // Required for wipeClient().
85 ensureLegacyIdentityManager();
86 Service.identity.account = "testaccount";
87 Service.identity.basicPassword = "testpassword";
88 Service.clusterURL = "http://dummy:9000/";
89 let key = Utils.generatePassphrase();
90 Service.identity.syncKey = key;
91 Service.identity.persistCredentials();
93 // Simulate passwords engine wipe without all the overhead. To do this
94 // properly would require extra test infrastructure.
95 Services.logins.removeAllLogins();
96 Service.wipeClient();
98 let id = new IdentityManager();
99 do_check_eq(id.account, "testaccount");
100 do_check_eq(id.basicPassword, "testpassword");
101 do_check_eq(id.syncKey, key);
103 Service.startOver();
105 run_next_test();
106 });
108 function run_test() {
109 initTestLogging();
111 run_next_test();
112 }