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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest.");
michael@0 8
michael@0 9 function run_test() {
michael@0 10 // Test must run at startup for migration to occur, so we can only test
michael@0 11 // one migration per test file
michael@0 12 initApp();
michael@0 13
michael@0 14 // NOTE: none of the manifests here can have a workerURL set, or we attempt
michael@0 15 // to create a FrameWorker and that fails under xpcshell...
michael@0 16 let manifest = { // normal provider
michael@0 17 name: "provider 1",
michael@0 18 origin: "https://example1.com",
michael@0 19 builtin: true // as of fx22 this should be true for default prefs
michael@0 20 };
michael@0 21
michael@0 22 DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest));
michael@0 23
michael@0 24 // Set both providers active and flag the first one as "current"
michael@0 25 let activeVal = Cc["@mozilla.org/supports-string;1"].
michael@0 26 createInstance(Ci.nsISupportsString);
michael@0 27 let active = {};
michael@0 28 active[manifest.origin] = 1;
michael@0 29 // bad.origin tests that a missing manifest does not break migration, bug 859715
michael@0 30 active["bad.origin"] = 1;
michael@0 31 activeVal.data = JSON.stringify(active);
michael@0 32 Services.prefs.setComplexValue("social.activeProviders",
michael@0 33 Ci.nsISupportsString, activeVal);
michael@0 34
michael@0 35 Cu.import("resource://gre/modules/SocialService.jsm");
michael@0 36
michael@0 37 let runner = new AsyncRunner();
michael@0 38 let next = runner.next.bind(runner);
michael@0 39 runner.appendIterator(testMigration(manifest, next));
michael@0 40 runner.next();
michael@0 41 }
michael@0 42
michael@0 43 function testMigration(manifest, next) {
michael@0 44 // look at social.activeProviders, we should have migrated into that, and
michael@0 45 // we should be set as a user level pref after migration
michael@0 46 do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
michael@0 47 // we need to access the providers for everything to initialize
michael@0 48 yield SocialService.getProviderList(next);
michael@0 49 do_check_true(SocialService.enabled);
michael@0 50 do_check_true(Services.prefs.prefHasUserValue("social.activeProviders"));
michael@0 51
michael@0 52 let activeProviders;
michael@0 53 let pref = Services.prefs.getComplexValue("social.activeProviders",
michael@0 54 Ci.nsISupportsString);
michael@0 55 activeProviders = JSON.parse(pref);
michael@0 56 do_check_true(activeProviders[manifest.origin]);
michael@0 57 do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
michael@0 58 do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
michael@0 59
michael@0 60 let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin));
michael@0 61 do_check_true(parseInt(userPref.updateDate) > 0);
michael@0 62 // migrated providers wont have an installDate
michael@0 63 do_check_true(userPref.installDate === 0);
michael@0 64
michael@0 65 // bug 859715, this should have been removed during migration
michael@0 66 do_check_false(!!activeProviders["bad.origin"]);
michael@0 67 }

mercurial