PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/services/sync/tests/unit/test_service_wipeClient.js

http://github.com/zpao/v8monkey
JavaScript | 76 lines | 59 code | 15 blank | 2 comment | 0 complexity | 18e29bf1c476c57b67e091ca90df9bc1 MD5 | raw file
 1Cu.import("resource://services-sync/record.js");
 2Cu.import("resource://services-sync/engines.js");
 3Cu.import("resource://services-sync/util.js");
 4
 5Svc.DefaultPrefs.set("registerEngines", "");
 6Cu.import("resource://services-sync/service.js");
 7
 8
 9function CanDecryptEngine() {
10  SyncEngine.call(this, "CanDecrypt");
11}
12CanDecryptEngine.prototype = {
13  __proto__: SyncEngine.prototype,
14
15  // Override these methods with mocks for the test
16  canDecrypt: function canDecrypt() {
17    return true;
18  },
19
20  wasWiped: false,
21  wipeClient: function wipeClient() {
22    this.wasWiped = true;
23  }
24};
25Engines.register(CanDecryptEngine);
26
27
28function CannotDecryptEngine() {
29  SyncEngine.call(this, "CannotDecrypt");
30}
31CannotDecryptEngine.prototype = {
32  __proto__: SyncEngine.prototype,
33
34  // Override these methods with mocks for the test
35  canDecrypt: function canDecrypt() {
36    return false;
37  },
38
39  wasWiped: false,
40  wipeClient: function wipeClient() {
41    this.wasWiped = true;
42  }
43};
44Engines.register(CannotDecryptEngine);
45
46
47function test_withEngineList() {
48  try {
49    _("Ensure initial scenario.");
50    do_check_false(Engines.get("candecrypt").wasWiped);
51    do_check_false(Engines.get("cannotdecrypt").wasWiped);
52    
53    _("Wipe local engine data.");
54    Service.wipeClient(["candecrypt", "cannotdecrypt"]);
55
56    _("Ensure only the engine that can decrypt was wiped.");
57    do_check_true(Engines.get("candecrypt").wasWiped);
58    do_check_false(Engines.get("cannotdecrypt").wasWiped);
59  } finally {
60    Engines.get("candecrypt").wasWiped = false;
61    Engines.get("cannotdecrypt").wasWiped = false;
62    Service.startOver();
63  }
64}
65
66function test_startOver_clears_keys() {
67  generateNewKeys();
68  do_check_true(!!CollectionKeys.keyForCollection());
69  Service.startOver();
70  do_check_false(!!CollectionKeys.keyForCollection());
71}
72
73function run_test() {
74  test_withEngineList();
75  test_startOver_clears_keys();
76}