1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 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 + 1.27 + // Set both providers active and flag the first one as "current" 1.28 + let activeVal = Cc["@mozilla.org/supports-string;1"]. 1.29 + createInstance(Ci.nsISupportsString); 1.30 + let active = {}; 1.31 + active[manifest.origin] = 1; 1.32 + // bad.origin tests that a missing manifest does not break migration, bug 859715 1.33 + active["bad.origin"] = 1; 1.34 + activeVal.data = JSON.stringify(active); 1.35 + Services.prefs.setComplexValue("social.activeProviders", 1.36 + Ci.nsISupportsString, activeVal); 1.37 + 1.38 + Cu.import("resource://gre/modules/SocialService.jsm"); 1.39 + 1.40 + let runner = new AsyncRunner(); 1.41 + let next = runner.next.bind(runner); 1.42 + runner.appendIterator(testMigration(manifest, next)); 1.43 + runner.next(); 1.44 +} 1.45 + 1.46 +function testMigration(manifest, next) { 1.47 + // look at social.activeProviders, we should have migrated into that, and 1.48 + // we should be set as a user level pref after migration 1.49 + do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); 1.50 + // we need to access the providers for everything to initialize 1.51 + yield SocialService.getProviderList(next); 1.52 + do_check_true(SocialService.enabled); 1.53 + do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); 1.54 + 1.55 + let activeProviders; 1.56 + let pref = Services.prefs.getComplexValue("social.activeProviders", 1.57 + Ci.nsISupportsString); 1.58 + activeProviders = JSON.parse(pref); 1.59 + do_check_true(activeProviders[manifest.origin]); 1.60 + do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); 1.61 + do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin); 1.62 + 1.63 + let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin)); 1.64 + do_check_true(parseInt(userPref.updateDate) > 0); 1.65 + // migrated providers wont have an installDate 1.66 + do_check_true(userPref.installDate === 0); 1.67 + 1.68 + // bug 859715, this should have been removed during migration 1.69 + do_check_false(!!activeProviders["bad.origin"]); 1.70 +}