Thu, 22 Jan 2015 13:21:57 +0100
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 | 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 | Services.prefs.setBoolPref("social.active", true); |
michael@0 | 24 | |
michael@0 | 25 | Cu.import("resource://gre/modules/SocialService.jsm"); |
michael@0 | 26 | |
michael@0 | 27 | let runner = new AsyncRunner(); |
michael@0 | 28 | let next = runner.next.bind(runner); |
michael@0 | 29 | runner.appendIterator(testMigration(manifest, next)); |
michael@0 | 30 | runner.next(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function testMigration(manifest, next) { |
michael@0 | 34 | // look at social.activeProviders, we should have migrated into that, and |
michael@0 | 35 | // we should be set as a user level pref after migration |
michael@0 | 36 | do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); |
michael@0 | 37 | // we need to access the providers for everything to initialize |
michael@0 | 38 | yield SocialService.getProviderList(next); |
michael@0 | 39 | do_check_true(SocialService.enabled); |
michael@0 | 40 | do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); |
michael@0 | 41 | |
michael@0 | 42 | let activeProviders; |
michael@0 | 43 | let pref = Services.prefs.getComplexValue("social.activeProviders", |
michael@0 | 44 | Ci.nsISupportsString); |
michael@0 | 45 | activeProviders = JSON.parse(pref); |
michael@0 | 46 | do_check_true(activeProviders[manifest.origin]); |
michael@0 | 47 | do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); |
michael@0 | 48 | do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin); |
michael@0 | 49 | |
michael@0 | 50 | let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin)); |
michael@0 | 51 | do_check_true(parseInt(userPref.updateDate) > 0); |
michael@0 | 52 | // migrated providers wont have an installDate |
michael@0 | 53 | do_check_true(userPref.installDate === 0); |
michael@0 | 54 | } |