toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.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_SocialServiceMigration21.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     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 +const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest.");
    1.11 +
    1.12 +function run_test() {
    1.13 +  // Test must run at startup for migration to occur, so we can only test
    1.14 +  // one migration per test file
    1.15 +  initApp();
    1.16 +
    1.17 +  // NOTE: none of the manifests here can have a workerURL set, or we attempt
    1.18 +  // to create a FrameWorker and that fails under xpcshell...
    1.19 +  let manifest = { // normal provider
    1.20 +    name: "provider 1",
    1.21 +    origin: "https://example1.com",
    1.22 +    builtin: true // as of fx22 this should be true for default prefs
    1.23 +  };
    1.24 +
    1.25 +  DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest));
    1.26 +  Services.prefs.setBoolPref("social.active", true);
    1.27 +
    1.28 +  Cu.import("resource://gre/modules/SocialService.jsm");
    1.29 +
    1.30 +  let runner = new AsyncRunner();
    1.31 +  let next = runner.next.bind(runner);
    1.32 +  runner.appendIterator(testMigration(manifest, next));
    1.33 +  runner.next();
    1.34 +}
    1.35 +
    1.36 +function testMigration(manifest, next) {
    1.37 +  // look at social.activeProviders, we should have migrated into that, and
    1.38 +  // we should be set as a user level pref after migration
    1.39 +  do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    1.40 +  // we need to access the providers for everything to initialize
    1.41 +  yield SocialService.getProviderList(next);
    1.42 +  do_check_true(SocialService.enabled);
    1.43 +  do_check_true(Services.prefs.prefHasUserValue("social.activeProviders"));
    1.44 +
    1.45 +  let activeProviders;
    1.46 +  let pref = Services.prefs.getComplexValue("social.activeProviders",
    1.47 +                                            Ci.nsISupportsString);
    1.48 +  activeProviders = JSON.parse(pref);
    1.49 +  do_check_true(activeProviders[manifest.origin]);
    1.50 +  do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
    1.51 +  do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
    1.52 +
    1.53 +  let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin));
    1.54 +  do_check_true(parseInt(userPref.updateDate) > 0);
    1.55 +  // migrated providers wont have an installDate
    1.56 +  do_check_true(userPref.installDate === 0);
    1.57 +}

mercurial