Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://services-sync/constants.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 7 | Cu.import("resource://testing-common/services/sync/fakeservices.js"); |
michael@0 | 8 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 9 | |
michael@0 | 10 | function test_urls() { |
michael@0 | 11 | _("URL related Service properties correspond to preference settings."); |
michael@0 | 12 | try { |
michael@0 | 13 | ensureLegacyIdentityManager(); |
michael@0 | 14 | do_check_true(!!Service.serverURL); // actual value may change |
michael@0 | 15 | do_check_eq(Service.clusterURL, ""); |
michael@0 | 16 | do_check_eq(Service.userBaseURL, undefined); |
michael@0 | 17 | do_check_eq(Service.infoURL, undefined); |
michael@0 | 18 | do_check_eq(Service.storageURL, undefined); |
michael@0 | 19 | do_check_eq(Service.metaURL, undefined); |
michael@0 | 20 | |
michael@0 | 21 | _("The 'clusterURL' attribute updates preferences and cached URLs."); |
michael@0 | 22 | Service.identity.username = "johndoe"; |
michael@0 | 23 | |
michael@0 | 24 | // Since we don't have a cluster URL yet, these will still not be defined. |
michael@0 | 25 | do_check_eq(Service.infoURL, undefined); |
michael@0 | 26 | do_check_eq(Service.userBaseURL, undefined); |
michael@0 | 27 | do_check_eq(Service.storageURL, undefined); |
michael@0 | 28 | do_check_eq(Service.metaURL, undefined); |
michael@0 | 29 | |
michael@0 | 30 | Service.serverURL = "http://weave.server/"; |
michael@0 | 31 | Service.clusterURL = "http://weave.cluster/"; |
michael@0 | 32 | do_check_eq(Svc.Prefs.get("clusterURL"), "http://weave.cluster/"); |
michael@0 | 33 | |
michael@0 | 34 | do_check_eq(Service.userBaseURL, "http://weave.cluster/1.1/johndoe/"); |
michael@0 | 35 | do_check_eq(Service.infoURL, |
michael@0 | 36 | "http://weave.cluster/1.1/johndoe/info/collections"); |
michael@0 | 37 | do_check_eq(Service.storageURL, |
michael@0 | 38 | "http://weave.cluster/1.1/johndoe/storage/"); |
michael@0 | 39 | do_check_eq(Service.metaURL, |
michael@0 | 40 | "http://weave.cluster/1.1/johndoe/storage/meta/global"); |
michael@0 | 41 | |
michael@0 | 42 | _("The 'miscURL' and 'userURL' attributes can be relative to 'serverURL' or absolute."); |
michael@0 | 43 | Svc.Prefs.set("miscURL", "relative/misc/"); |
michael@0 | 44 | Svc.Prefs.set("userURL", "relative/user/"); |
michael@0 | 45 | do_check_eq(Service.miscAPI, |
michael@0 | 46 | "http://weave.server/relative/misc/1.0/"); |
michael@0 | 47 | do_check_eq(Service.userAPIURI, |
michael@0 | 48 | "http://weave.server/relative/user/1.0/"); |
michael@0 | 49 | |
michael@0 | 50 | Svc.Prefs.set("miscURL", "http://weave.misc.services/"); |
michael@0 | 51 | Svc.Prefs.set("userURL", "http://weave.user.services/"); |
michael@0 | 52 | do_check_eq(Service.miscAPI, "http://weave.misc.services/1.0/"); |
michael@0 | 53 | do_check_eq(Service.userAPIURI, "http://weave.user.services/1.0/"); |
michael@0 | 54 | |
michael@0 | 55 | do_check_eq(Service.pwResetURL, |
michael@0 | 56 | "http://weave.server/weave-password-reset"); |
michael@0 | 57 | |
michael@0 | 58 | _("Empty/false value for 'username' resets preference."); |
michael@0 | 59 | Service.identity.username = ""; |
michael@0 | 60 | do_check_eq(Svc.Prefs.get("username"), undefined); |
michael@0 | 61 | do_check_eq(Service.identity.username, null); |
michael@0 | 62 | |
michael@0 | 63 | _("The 'serverURL' attributes updates/resets preferences."); |
michael@0 | 64 | // Identical value doesn't do anything |
michael@0 | 65 | Service.serverURL = Service.serverURL; |
michael@0 | 66 | do_check_eq(Svc.Prefs.get("clusterURL"), "http://weave.cluster/"); |
michael@0 | 67 | |
michael@0 | 68 | Service.serverURL = "http://different.auth.node/"; |
michael@0 | 69 | do_check_eq(Svc.Prefs.get("serverURL"), "http://different.auth.node/"); |
michael@0 | 70 | do_check_eq(Svc.Prefs.get("clusterURL"), undefined); |
michael@0 | 71 | |
michael@0 | 72 | } finally { |
michael@0 | 73 | Svc.Prefs.resetBranch(""); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | |
michael@0 | 78 | function test_syncID() { |
michael@0 | 79 | _("Service.syncID is auto-generated, corresponds to preference."); |
michael@0 | 80 | new FakeGUIDService(); |
michael@0 | 81 | |
michael@0 | 82 | try { |
michael@0 | 83 | // Ensure pristine environment |
michael@0 | 84 | do_check_eq(Svc.Prefs.get("client.syncID"), undefined); |
michael@0 | 85 | |
michael@0 | 86 | // Performing the first get on the attribute will generate a new GUID. |
michael@0 | 87 | do_check_eq(Service.syncID, "fake-guid-0"); |
michael@0 | 88 | do_check_eq(Svc.Prefs.get("client.syncID"), "fake-guid-0"); |
michael@0 | 89 | |
michael@0 | 90 | Svc.Prefs.set("client.syncID", Utils.makeGUID()); |
michael@0 | 91 | do_check_eq(Svc.Prefs.get("client.syncID"), "fake-guid-1"); |
michael@0 | 92 | do_check_eq(Service.syncID, "fake-guid-1"); |
michael@0 | 93 | } finally { |
michael@0 | 94 | Svc.Prefs.resetBranch(""); |
michael@0 | 95 | new FakeGUIDService(); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function test_locked() { |
michael@0 | 100 | _("The 'locked' attribute can be toggled with lock() and unlock()"); |
michael@0 | 101 | |
michael@0 | 102 | // Defaults to false |
michael@0 | 103 | do_check_eq(Service.locked, false); |
michael@0 | 104 | |
michael@0 | 105 | do_check_eq(Service.lock(), true); |
michael@0 | 106 | do_check_eq(Service.locked, true); |
michael@0 | 107 | |
michael@0 | 108 | // Locking again will return false |
michael@0 | 109 | do_check_eq(Service.lock(), false); |
michael@0 | 110 | |
michael@0 | 111 | Service.unlock(); |
michael@0 | 112 | do_check_eq(Service.locked, false); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function run_test() { |
michael@0 | 116 | test_urls(); |
michael@0 | 117 | test_syncID(); |
michael@0 | 118 | test_locked(); |
michael@0 | 119 | } |