toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 Cu.import("resource://gre/modules/Services.jsm");
     7 const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest.");
     9 function run_test() {
    10   // Test must run at startup for migration to occur, so we can only test
    11   // one migration per test file
    12   initApp();
    14   // NOTE: none of the manifests here can have a workerURL set, or we attempt
    15   // to create a FrameWorker and that fails under xpcshell...
    16   let manifest = { // normal provider
    17     name: "provider 1",
    18     origin: "https://example1.com",
    19     builtin: true // as of fx22 this should be true for default prefs
    20   };
    22   DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest));
    24   // Set both providers active and flag the first one as "current"
    25   let activeVal = Cc["@mozilla.org/supports-string;1"].
    26              createInstance(Ci.nsISupportsString);
    27   let active = {};
    28   active[manifest.origin] = 1;
    29   // bad.origin tests that a missing manifest does not break migration, bug 859715
    30   active["bad.origin"] = 1;
    31   activeVal.data = JSON.stringify(active);
    32   Services.prefs.setComplexValue("social.activeProviders",
    33                                  Ci.nsISupportsString, activeVal);
    35   Cu.import("resource://gre/modules/SocialService.jsm");
    37   let runner = new AsyncRunner();
    38   let next = runner.next.bind(runner);
    39   runner.appendIterator(testMigration(manifest, next));
    40   runner.next();
    41 }
    43 function testMigration(manifest, next) {
    44   // look at social.activeProviders, we should have migrated into that, and
    45   // we should be set as a user level pref after migration
    46   do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    47   // we need to access the providers for everything to initialize
    48   yield SocialService.getProviderList(next);
    49   do_check_true(SocialService.enabled);
    50   do_check_true(Services.prefs.prefHasUserValue("social.activeProviders"));
    52   let activeProviders;
    53   let pref = Services.prefs.getComplexValue("social.activeProviders",
    54                                             Ci.nsISupportsString);
    55   activeProviders = JSON.parse(pref);
    56   do_check_true(activeProviders[manifest.origin]);
    57   do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    58   do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
    60   let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin));
    61   do_check_true(parseInt(userPref.updateDate) > 0);
    62   // migrated providers wont have an installDate
    63   do_check_true(userPref.installDate === 0);
    65   // bug 859715, this should have been removed during migration
    66   do_check_false(!!activeProviders["bad.origin"]);
    67 }

mercurial