services/sync/tests/unit/test_service_attributes.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial