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