toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.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

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 Cu.import("resource://gre/modules/Services.jsm");
michael@0 6
michael@0 7
michael@0 8 function run_test() {
michael@0 9 // Test must run at startup for migration to occur, so we can only test
michael@0 10 // one migration per test file
michael@0 11 initApp();
michael@0 12
michael@0 13 // NOTE: none of the manifests here can have a workerURL set, or we attempt
michael@0 14 // to create a FrameWorker and that fails under xpcshell...
michael@0 15 let manifest = { // normal provider
michael@0 16 name: "provider 1",
michael@0 17 origin: "https://example1.com",
michael@0 18 };
michael@0 19
michael@0 20 MANIFEST_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest));
michael@0 21
michael@0 22 // Set both providers active and flag the first one as "current"
michael@0 23 let activeVal = Cc["@mozilla.org/supports-string;1"].
michael@0 24 createInstance(Ci.nsISupportsString);
michael@0 25 let active = {};
michael@0 26 active[manifest.origin] = 1;
michael@0 27 activeVal.data = JSON.stringify(active);
michael@0 28 Services.prefs.setComplexValue("social.activeProviders",
michael@0 29 Ci.nsISupportsString, activeVal);
michael@0 30
michael@0 31 // social.enabled pref is the key focus of this test. We set the user pref,
michael@0 32 // and then migration should a) remove the provider from activeProviders and
michael@0 33 // b) unset social.enabled
michael@0 34 Services.prefs.setBoolPref("social.enabled", false);
michael@0 35
michael@0 36 Cu.import("resource://gre/modules/SocialService.jsm");
michael@0 37
michael@0 38 let runner = new AsyncRunner();
michael@0 39 let next = runner.next.bind(runner);
michael@0 40 runner.appendIterator(testMigration(manifest, next));
michael@0 41 runner.next();
michael@0 42 }
michael@0 43
michael@0 44 function testMigration(manifest, next) {
michael@0 45 // look at social.activeProviders, we should have migrated into that, and
michael@0 46 // we should be set as a user level pref after migration
michael@0 47 do_check_true(Services.prefs.prefHasUserValue("social.enabled"));
michael@0 48 do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
michael@0 49 // we need to access the providers for everything to initialize
michael@0 50 yield SocialService.getProviderList(next);
michael@0 51 do_check_false(SocialService.enabled);
michael@0 52 do_check_false(Services.prefs.prefHasUserValue("social.enabled"));
michael@0 53 do_check_true(Services.prefs.prefHasUserValue("social.activeProviders"));
michael@0 54
michael@0 55 let activeProviders;
michael@0 56 let pref = Services.prefs.getComplexValue("social.activeProviders",
michael@0 57 Ci.nsISupportsString).data;
michael@0 58 activeProviders = JSON.parse(pref);
michael@0 59 do_check_true(activeProviders[manifest.origin] == undefined);
michael@0 60 do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
michael@0 61 }

mercurial