michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest."); michael@0: michael@0: function run_test() { michael@0: // Test must run at startup for migration to occur, so we can only test michael@0: // one migration per test file michael@0: initApp(); michael@0: michael@0: // NOTE: none of the manifests here can have a workerURL set, or we attempt michael@0: // to create a FrameWorker and that fails under xpcshell... michael@0: let manifest = { // normal provider michael@0: name: "provider 1", michael@0: origin: "https://example1.com", michael@0: builtin: true // as of fx22 this should be true for default prefs michael@0: }; michael@0: michael@0: DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); michael@0: michael@0: // Set both providers active and flag the first one as "current" michael@0: let activeVal = Cc["@mozilla.org/supports-string;1"]. michael@0: createInstance(Ci.nsISupportsString); michael@0: let active = {}; michael@0: active[manifest.origin] = 1; michael@0: // bad.origin tests that a missing manifest does not break migration, bug 859715 michael@0: active["bad.origin"] = 1; michael@0: activeVal.data = JSON.stringify(active); michael@0: Services.prefs.setComplexValue("social.activeProviders", michael@0: Ci.nsISupportsString, activeVal); michael@0: michael@0: Cu.import("resource://gre/modules/SocialService.jsm"); michael@0: michael@0: let runner = new AsyncRunner(); michael@0: let next = runner.next.bind(runner); michael@0: runner.appendIterator(testMigration(manifest, next)); michael@0: runner.next(); michael@0: } michael@0: michael@0: function testMigration(manifest, next) { michael@0: // look at social.activeProviders, we should have migrated into that, and michael@0: // we should be set as a user level pref after migration michael@0: do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); michael@0: // we need to access the providers for everything to initialize michael@0: yield SocialService.getProviderList(next); michael@0: do_check_true(SocialService.enabled); michael@0: do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); michael@0: michael@0: let activeProviders; michael@0: let pref = Services.prefs.getComplexValue("social.activeProviders", michael@0: Ci.nsISupportsString); michael@0: activeProviders = JSON.parse(pref); michael@0: do_check_true(activeProviders[manifest.origin]); michael@0: do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); michael@0: do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin); michael@0: michael@0: let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin)); michael@0: do_check_true(parseInt(userPref.updateDate) > 0); michael@0: // migrated providers wont have an installDate michael@0: do_check_true(userPref.installDate === 0); michael@0: michael@0: // bug 859715, this should have been removed during migration michael@0: do_check_false(!!activeProviders["bad.origin"]); michael@0: }