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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +Cu.import("resource://gre/modules/Services.jsm");
     1.9 +
    1.10 +
    1.11 +function run_test() {
    1.12 +  // Test must run at startup for migration to occur, so we can only test
    1.13 +  // one migration per test file
    1.14 +  initApp();
    1.15 +
    1.16 +  // NOTE: none of the manifests here can have a workerURL set, or we attempt
    1.17 +  // to create a FrameWorker and that fails under xpcshell...
    1.18 +  let manifest = { // normal provider
    1.19 +    name: "provider 1",
    1.20 +    origin: "https://example1.com",
    1.21 +  };
    1.22 +
    1.23 +  MANIFEST_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest));
    1.24 +
    1.25 +  // Set both providers active and flag the first one as "current"
    1.26 +  let activeVal = Cc["@mozilla.org/supports-string;1"].
    1.27 +             createInstance(Ci.nsISupportsString);
    1.28 +  let active = {};
    1.29 +  active[manifest.origin] = 1;
    1.30 +  activeVal.data = JSON.stringify(active);
    1.31 +  Services.prefs.setComplexValue("social.activeProviders",
    1.32 +                                 Ci.nsISupportsString, activeVal);
    1.33 +
    1.34 +  // social.enabled pref is the key focus of this test. We set the user pref,
    1.35 +  // and then migration should a) remove the provider from activeProviders and
    1.36 +  // b) unset social.enabled
    1.37 +  Services.prefs.setBoolPref("social.enabled", false);
    1.38 +
    1.39 +  Cu.import("resource://gre/modules/SocialService.jsm");
    1.40 +
    1.41 +  let runner = new AsyncRunner();
    1.42 +  let next = runner.next.bind(runner);
    1.43 +  runner.appendIterator(testMigration(manifest, next));
    1.44 +  runner.next();
    1.45 +}
    1.46 +
    1.47 +function testMigration(manifest, next) {
    1.48 +  // look at social.activeProviders, we should have migrated into that, and
    1.49 +  // we should be set as a user level pref after migration
    1.50 +  do_check_true(Services.prefs.prefHasUserValue("social.enabled"));
    1.51 +  do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    1.52 +  // we need to access the providers for everything to initialize
    1.53 +  yield SocialService.getProviderList(next);
    1.54 +  do_check_false(SocialService.enabled);
    1.55 +  do_check_false(Services.prefs.prefHasUserValue("social.enabled"));
    1.56 +  do_check_true(Services.prefs.prefHasUserValue("social.activeProviders"));
    1.57 +
    1.58 +  let activeProviders;
    1.59 +  let pref = Services.prefs.getComplexValue("social.activeProviders",
    1.60 +                                            Ci.nsISupportsString).data;
    1.61 +  activeProviders = JSON.parse(pref);
    1.62 +  do_check_true(activeProviders[manifest.origin] == undefined);
    1.63 +  do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    1.64 +}

mercurial