/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

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