diff options
Diffstat (limited to 'browser/modules/test/unit')
10 files changed, 645 insertions, 0 deletions
diff --git a/browser/modules/test/unit/social/.eslintrc.js b/browser/modules/test/unit/social/.eslintrc.js new file mode 100644 index 000000000..d35787cd2 --- /dev/null +++ b/browser/modules/test/unit/social/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../../testing/xpcshell/xpcshell.eslintrc.js" + ] +}; diff --git a/browser/modules/test/unit/social/blocklist.xml b/browser/modules/test/unit/social/blocklist.xml new file mode 100644 index 000000000..c8d72d624 --- /dev/null +++ b/browser/modules/test/unit/social/blocklist.xml @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist"> + <emItems> + <emItem blockID="s1" id="bad.com@services.mozilla.org"></emItem> + </emItems> +</blocklist> diff --git a/browser/modules/test/unit/social/head.js b/browser/modules/test/unit/social/head.js new file mode 100644 index 000000000..0beabb685 --- /dev/null +++ b/browser/modules/test/unit/social/head.js @@ -0,0 +1,210 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +var Social, SocialService; + +var manifests = [ + { + name: "provider 1", + origin: "https://example1.com", + sidebarURL: "https://example1.com/sidebar/", + }, + { + name: "provider 2", + origin: "https://example2.com", + sidebarURL: "https://example1.com/sidebar/", + } +]; + +const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest."); + +// SocialProvider class relies on blocklisting being enabled. To enable +// blocklisting, we have to setup an app and initialize the blocklist (see +// initApp below). +const gProfD = do_get_profile(); + +function createAppInfo(ID, name, version, platformVersion="1.0") { + let tmp = {}; + Cu.import("resource://testing-common/AppInfo.jsm", tmp); + tmp.updateAppInfo({ + ID, name, version, platformVersion, + crashReporter: true, + }); + gAppInfo = tmp.getAppInfo(); +} + +function initApp() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); + // prepare a blocklist file for the blocklist service + var blocklistFile = gProfD.clone(); + blocklistFile.append("blocklist.xml"); + if (blocklistFile.exists()) + blocklistFile.remove(false); + var source = do_get_file("blocklist.xml"); + source.copyTo(gProfD, "blocklist.xml"); + blocklistFile.lastModifiedTime = Date.now(); + + + let internalManager = Cc["@mozilla.org/addons/integration;1"]. + getService(Ci.nsIObserver). + QueryInterface(Ci.nsITimerCallback); + + internalManager.observe(null, "addons-startup", null); +} + +function setManifestPref(manifest) { + let string = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + string.data = JSON.stringify(manifest); + Services.prefs.setComplexValue("social.manifest." + manifest.origin, Ci.nsISupportsString, string); +} + +function do_wait_observer(obsTopic, cb) { + function observer(subject, topic, data) { + Services.obs.removeObserver(observer, topic); + cb(); + } + Services.obs.addObserver(observer, obsTopic, false); +} + +function do_add_providers(cb) { + // run only after social is already initialized + SocialService.addProvider(manifests[0], function() { + do_wait_observer("social:providers-changed", function() { + do_check_eq(Social.providers.length, 2, "2 providers installed"); + do_execute_soon(cb); + }); + SocialService.addProvider(manifests[1]); + }); +} + +function do_initialize_social(enabledOnStartup, cb) { + initApp(); + + if (enabledOnStartup) { + // set prefs before initializing social + manifests.forEach(function (manifest) { + setManifestPref(manifest); + }); + // Set both providers active and flag the first one as "current" + let activeVal = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + let active = {}; + for (let m of manifests) + active[m.origin] = 1; + activeVal.data = JSON.stringify(active); + Services.prefs.setComplexValue("social.activeProviders", + Ci.nsISupportsString, activeVal); + + do_register_cleanup(function() { + manifests.forEach(function (manifest) { + Services.prefs.clearUserPref("social.manifest." + manifest.origin); + }); + Services.prefs.clearUserPref("social.activeProviders"); + }); + + // expecting 2 providers installed + do_wait_observer("social:providers-changed", function() { + do_check_eq(Social.providers.length, 2, "2 providers installed"); + do_execute_soon(cb); + }); + } + + // import and initialize everything + SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; + do_check_eq(enabledOnStartup, SocialService.hasEnabledProviders, "Service has enabled providers"); + Social = Cu.import("resource:///modules/Social.jsm", {}).Social; + do_check_false(Social.initialized, "Social is not initialized"); + Social.init(); + do_check_true(Social.initialized, "Social is initialized"); + if (!enabledOnStartup) + do_execute_soon(cb); +} + +function AsyncRunner() { + do_test_pending(); + do_register_cleanup(() => this.destroy()); + + this._callbacks = { + done: do_test_finished, + error: function (err) { + // xpcshell test functions like do_check_eq throw NS_ERROR_ABORT on + // failure. Ignore those so they aren't rethrown here. + if (err !== Cr.NS_ERROR_ABORT) { + if (err.stack) { + err = err + " - See following stack:\n" + err.stack + + "\nUseless do_throw stack"; + } + do_throw(err); + } + }, + consoleError: function (scriptErr) { + // Try to ensure the error is related to the test. + let filename = scriptErr.sourceName || scriptErr.toString() || ""; + if (filename.indexOf("/toolkit/components/social/") >= 0) + do_throw(scriptErr); + }, + }; + this._iteratorQueue = []; + + // This catches errors reported to the console, e.g., via Cu.reportError, but + // not on the runner's stack. + Cc["@mozilla.org/consoleservice;1"]. + getService(Ci.nsIConsoleService). + registerListener(this); +} + +AsyncRunner.prototype = { + + appendIterator: function appendIterator(iter) { + this._iteratorQueue.push(iter); + }, + + next: function next(arg) { + if (!this._iteratorQueue.length) { + this.destroy(); + this._callbacks.done(); + return; + } + + try { + var { done, value: val } = this._iteratorQueue[0].next(arg); + if (done) { + this._iteratorQueue.shift(); + this.next(); + return; + } + } + catch (err) { + this._callbacks.error(err); + } + + // val is an iterator => prepend it to the queue and start on it + // val is otherwise truthy => call next + if (val) { + if (typeof(val) != "boolean") + this._iteratorQueue.unshift(val); + this.next(); + } + }, + + destroy: function destroy() { + Cc["@mozilla.org/consoleservice;1"]. + getService(Ci.nsIConsoleService). + unregisterListener(this); + this.destroy = function alreadyDestroyed() {}; + }, + + observe: function observe(msg) { + if (msg instanceof Ci.nsIScriptError && + !(msg.flags & Ci.nsIScriptError.warningFlag)) + { + this._callbacks.consoleError(msg); + } + }, +}; diff --git a/browser/modules/test/unit/social/test_SocialService.js b/browser/modules/test/unit/social/test_SocialService.js new file mode 100644 index 000000000..e6f354fed --- /dev/null +++ b/browser/modules/test/unit/social/test_SocialService.js @@ -0,0 +1,166 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Cu.import("resource://gre/modules/Services.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm"); + +function run_test() { + initApp(); + + // NOTE: none of the manifests here can have a workerURL set, or we attempt + // to create a FrameWorker and that fails under xpcshell... + let manifests = [ + { // normal provider + name: "provider 1", + origin: "https://example1.com", + shareURL: "https://example1.com/share/", + }, + { // provider without workerURL + name: "provider 2", + origin: "https://example2.com", + shareURL: "https://example2.com/share/", + } + ]; + + Cu.import("resource:///modules/SocialService.jsm"); + + let runner = new AsyncRunner(); + let next = runner.next.bind(runner); + runner.appendIterator(testAddProviders(manifests, next)); + runner.appendIterator(testGetProvider(manifests, next)); + runner.appendIterator(testGetProviderList(manifests, next)); + runner.appendIterator(testAddRemoveProvider(manifests, next)); + runner.appendIterator(testIsSameOrigin(manifests, next)); + runner.appendIterator(testResolveUri (manifests, next)); + runner.appendIterator(testOrderedProviders(manifests, next)); + runner.appendIterator(testRemoveProviders(manifests, next)); + runner.next(); +} + +function* testAddProviders(manifests, next) { + do_check_false(SocialService.enabled); + let provider = yield SocialService.addProvider(manifests[0], next); + do_check_true(SocialService.enabled); + do_check_false(provider.enabled); + provider = yield SocialService.addProvider(manifests[1], next); + do_check_false(provider.enabled); +} + +function* testRemoveProviders(manifests, next) { + do_check_true(SocialService.enabled); + yield SocialService.disableProvider(manifests[0].origin, next); + yield SocialService.disableProvider(manifests[1].origin, next); + do_check_false(SocialService.enabled); +} + +function* testGetProvider(manifests, next) { + for (let i = 0; i < manifests.length; i++) { + let manifest = manifests[i]; + let provider = yield SocialService.getProvider(manifest.origin, next); + do_check_neq(provider, null); + do_check_eq(provider.name, manifest.name); + do_check_eq(provider.workerURL, manifest.workerURL); + do_check_eq(provider.origin, manifest.origin); + } + do_check_eq((yield SocialService.getProvider("bogus", next)), null); +} + +function* testGetProviderList(manifests, next) { + let providers = yield SocialService.getProviderList(next); + do_check_true(providers.length >= manifests.length); + for (let i = 0; i < manifests.length; i++) { + let providerIdx = providers.map(p => p.origin).indexOf(manifests[i].origin); + let provider = providers[providerIdx]; + do_check_true(!!provider); + do_check_false(provider.enabled); + do_check_eq(provider.workerURL, manifests[i].workerURL); + do_check_eq(provider.name, manifests[i].name); + } +} + +function* testAddRemoveProvider(manifests, next) { + var threw; + try { + // Adding a provider whose origin already exists should fail + SocialService.addProvider(manifests[0]); + } catch (ex) { + threw = ex; + } + do_check_neq(threw.toString().indexOf("SocialService.addProvider: provider with this origin already exists"), -1); + + let originalProviders = yield SocialService.getProviderList(next); + + // Check that provider installation succeeds + let newProvider = yield SocialService.addProvider({ + name: "foo", + origin: "http://example3.com" + }, next); + let retrievedNewProvider = yield SocialService.getProvider(newProvider.origin, next); + do_check_eq(newProvider, retrievedNewProvider); + + let providersAfter = yield SocialService.getProviderList(next); + do_check_eq(providersAfter.length, originalProviders.length + 1); + do_check_neq(providersAfter.indexOf(newProvider), -1); + + // Now remove the provider + yield SocialService.disableProvider(newProvider.origin, next); + providersAfter = yield SocialService.getProviderList(next); + do_check_eq(providersAfter.length, originalProviders.length); + do_check_eq(providersAfter.indexOf(newProvider), -1); + newProvider = yield SocialService.getProvider(newProvider.origin, next); + do_check_true(!newProvider); +} + +function* testIsSameOrigin(manifests, next) { + let providers = yield SocialService.getProviderList(next); + let provider = providers[0]; + // provider.origin is a string. + do_check_true(provider.isSameOrigin(provider.origin)); + do_check_true(provider.isSameOrigin(Services.io.newURI(provider.origin, null, null))); + do_check_true(provider.isSameOrigin(provider.origin + "/some-sub-page")); + do_check_true(provider.isSameOrigin(Services.io.newURI(provider.origin + "/some-sub-page", null, null))); + do_check_false(provider.isSameOrigin("http://something.com")); + do_check_false(provider.isSameOrigin(Services.io.newURI("http://something.com", null, null))); + do_check_false(provider.isSameOrigin("data:text/html,<p>hi")); + do_check_true(provider.isSameOrigin("data:text/html,<p>hi", true)); + do_check_false(provider.isSameOrigin(Services.io.newURI("data:text/html,<p>hi", null, null))); + do_check_true(provider.isSameOrigin(Services.io.newURI("data:text/html,<p>hi", null, null), true)); + // we explicitly handle null and return false + do_check_false(provider.isSameOrigin(null)); +} + +function* testResolveUri(manifests, next) { + let providers = yield SocialService.getProviderList(next); + let provider = providers[0]; + do_check_eq(provider.resolveUri(provider.origin).spec, provider.origin + "/"); + do_check_eq(provider.resolveUri("foo.html").spec, provider.origin + "/foo.html"); + do_check_eq(provider.resolveUri("/foo.html").spec, provider.origin + "/foo.html"); + do_check_eq(provider.resolveUri("http://somewhereelse.com/foo.html").spec, "http://somewhereelse.com/foo.html"); + do_check_eq(provider.resolveUri("data:text/html,<p>hi").spec, "data:text/html,<p>hi"); +} + +function* testOrderedProviders(manifests, next) { + let providers = yield SocialService.getProviderList(next); + + // add visits for only one of the providers + let visits = []; + let startDate = Date.now() * 1000; + for (let i = 0; i < 10; i++) { + visits.push({ + uri: Services.io.newURI(providers[1].shareURL + i, null, null), + visitDate: startDate + i + }); + } + + PlacesTestUtils.addVisits(visits).then(next); + yield; + let orderedProviders = yield SocialService.getOrderedProviderList(next); + do_check_eq(orderedProviders[0], providers[1]); + do_check_eq(orderedProviders[1], providers[0]); + do_check_true(orderedProviders[0].frecency > orderedProviders[1].frecency); + PlacesTestUtils.clearHistory().then(next); + yield; +} diff --git a/browser/modules/test/unit/social/test_SocialServiceMigration21.js b/browser/modules/test/unit/social/test_SocialServiceMigration21.js new file mode 100644 index 000000000..dfe6183bf --- /dev/null +++ b/browser/modules/test/unit/social/test_SocialServiceMigration21.js @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Cu.import("resource://gre/modules/Services.jsm"); + +const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest."); + +function run_test() { + // Test must run at startup for migration to occur, so we can only test + // one migration per test file + initApp(); + + // NOTE: none of the manifests here can have a workerURL set, or we attempt + // to create a FrameWorker and that fails under xpcshell... + let manifest = { // normal provider + name: "provider 1", + origin: "https://example1.com", + builtin: true // as of fx22 this should be true for default prefs + }; + + DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); + Services.prefs.setBoolPref("social.active", true); + + Cu.import("resource:///modules/SocialService.jsm"); + + let runner = new AsyncRunner(); + let next = runner.next.bind(runner); + runner.appendIterator(testMigration(manifest, next)); + runner.next(); +} + +function* testMigration(manifest, next) { + // look at social.activeProviders, we should have migrated into that, and + // we should be set as a user level pref after migration + do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); + // we need to access the providers for everything to initialize + yield SocialService.getProviderList(next); + do_check_true(SocialService.enabled); + do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); + + let activeProviders; + let pref = Services.prefs.getComplexValue("social.activeProviders", + Ci.nsISupportsString); + activeProviders = JSON.parse(pref); + do_check_true(activeProviders[manifest.origin]); + do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); + do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin); + + let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin)); + do_check_true(parseInt(userPref.updateDate) > 0); + // migrated providers wont have an installDate + do_check_true(userPref.installDate === 0); +} diff --git a/browser/modules/test/unit/social/test_SocialServiceMigration22.js b/browser/modules/test/unit/social/test_SocialServiceMigration22.js new file mode 100644 index 000000000..1a3953175 --- /dev/null +++ b/browser/modules/test/unit/social/test_SocialServiceMigration22.js @@ -0,0 +1,67 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Cu.import("resource://gre/modules/Services.jsm"); + +const DEFAULT_PREFS = Services.prefs.getDefaultBranch("social.manifest."); + +function run_test() { + // Test must run at startup for migration to occur, so we can only test + // one migration per test file + initApp(); + + // NOTE: none of the manifests here can have a workerURL set, or we attempt + // to create a FrameWorker and that fails under xpcshell... + let manifest = { // normal provider + name: "provider 1", + origin: "https://example1.com", + builtin: true // as of fx22 this should be true for default prefs + }; + + DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); + + // Set both providers active and flag the first one as "current" + let activeVal = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + let active = {}; + active[manifest.origin] = 1; + // bad.origin tests that a missing manifest does not break migration, bug 859715 + active["bad.origin"] = 1; + activeVal.data = JSON.stringify(active); + Services.prefs.setComplexValue("social.activeProviders", + Ci.nsISupportsString, activeVal); + + Cu.import("resource:///modules/SocialService.jsm"); + + let runner = new AsyncRunner(); + let next = runner.next.bind(runner); + runner.appendIterator(testMigration(manifest, next)); + runner.next(); +} + +function* testMigration(manifest, next) { + // look at social.activeProviders, we should have migrated into that, and + // we should be set as a user level pref after migration + do_check_false(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); + // we need to access the providers for everything to initialize + yield SocialService.getProviderList(next); + do_check_true(SocialService.enabled); + do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); + + let activeProviders; + let pref = Services.prefs.getComplexValue("social.activeProviders", + Ci.nsISupportsString); + activeProviders = JSON.parse(pref); + do_check_true(activeProviders[manifest.origin]); + do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); + do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin); + + let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin)); + do_check_true(parseInt(userPref.updateDate) > 0); + // migrated providers wont have an installDate + do_check_true(userPref.installDate === 0); + + // bug 859715, this should have been removed during migration + do_check_false(!!activeProviders["bad.origin"]); +} diff --git a/browser/modules/test/unit/social/test_SocialServiceMigration29.js b/browser/modules/test/unit/social/test_SocialServiceMigration29.js new file mode 100644 index 000000000..824673ddf --- /dev/null +++ b/browser/modules/test/unit/social/test_SocialServiceMigration29.js @@ -0,0 +1,61 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Cu.import("resource://gre/modules/Services.jsm"); + + +function run_test() { + // Test must run at startup for migration to occur, so we can only test + // one migration per test file + initApp(); + + // NOTE: none of the manifests here can have a workerURL set, or we attempt + // to create a FrameWorker and that fails under xpcshell... + let manifest = { // normal provider + name: "provider 1", + origin: "https://example1.com", + }; + + MANIFEST_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); + + // Set both providers active and flag the first one as "current" + let activeVal = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + let active = {}; + active[manifest.origin] = 1; + activeVal.data = JSON.stringify(active); + Services.prefs.setComplexValue("social.activeProviders", + Ci.nsISupportsString, activeVal); + + // social.enabled pref is the key focus of this test. We set the user pref, + // and then migration should a) remove the provider from activeProviders and + // b) unset social.enabled + Services.prefs.setBoolPref("social.enabled", false); + + Cu.import("resource:///modules/SocialService.jsm"); + + let runner = new AsyncRunner(); + let next = runner.next.bind(runner); + runner.appendIterator(testMigration(manifest, next)); + runner.next(); +} + +function* testMigration(manifest, next) { + // look at social.activeProviders, we should have migrated into that, and + // we should be set as a user level pref after migration + do_check_true(Services.prefs.prefHasUserValue("social.enabled")); + do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); + // we need to access the providers for everything to initialize + yield SocialService.getProviderList(next); + do_check_false(SocialService.enabled); + do_check_false(Services.prefs.prefHasUserValue("social.enabled")); + do_check_true(Services.prefs.prefHasUserValue("social.activeProviders")); + + let activeProviders; + let pref = Services.prefs.getComplexValue("social.activeProviders", + Ci.nsISupportsString).data; + activeProviders = JSON.parse(pref); + do_check_true(activeProviders[manifest.origin] == undefined); + do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin)); +} diff --git a/browser/modules/test/unit/social/test_social.js b/browser/modules/test/unit/social/test_social.js new file mode 100644 index 000000000..3117306c1 --- /dev/null +++ b/browser/modules/test/unit/social/test_social.js @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function run_test() { + // we are testing worker startup specifically + do_test_pending(); + add_test(testStartupEnabled); + add_test(testDisableAfterStartup); + do_initialize_social(true, run_next_test); +} + +function testStartupEnabled() { + // wait on startup before continuing + do_check_eq(Social.providers.length, 2, "two social providers enabled"); + do_check_true(Social.providers[0].enabled, "provider 0 is enabled"); + do_check_true(Social.providers[1].enabled, "provider 1 is enabled"); + run_next_test(); +} + +function testDisableAfterStartup() { + let SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; + SocialService.disableProvider(Social.providers[0].origin, function() { + do_wait_observer("social:providers-changed", function() { + do_check_eq(Social.enabled, false, "Social is disabled"); + do_check_eq(Social.providers.length, 0, "no social providers available"); + do_test_finished(); + run_next_test(); + }); + SocialService.disableProvider(Social.providers[0].origin) + }); +} diff --git a/browser/modules/test/unit/social/test_socialDisabledStartup.js b/browser/modules/test/unit/social/test_socialDisabledStartup.js new file mode 100644 index 000000000..a2f7a1d5a --- /dev/null +++ b/browser/modules/test/unit/social/test_socialDisabledStartup.js @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function run_test() { + // we are testing worker startup specifically + do_test_pending(); + add_test(testStartupDisabled); + add_test(testEnableAfterStartup); + do_initialize_social(false, run_next_test); +} + +function testStartupDisabled() { + // wait on startup before continuing + do_check_false(Social.enabled, "Social is disabled"); + do_check_eq(Social.providers.length, 0, "zero social providers available"); + run_next_test(); +} + +function testEnableAfterStartup() { + do_add_providers(function () { + do_check_true(Social.enabled, "Social is enabled"); + do_check_eq(Social.providers.length, 2, "two social providers available"); + do_check_true(Social.providers[0].enabled, "provider 0 is enabled"); + do_check_true(Social.providers[1].enabled, "provider 1 is enabled"); + do_test_finished(); + run_next_test(); + }); +} diff --git a/browser/modules/test/unit/social/xpcshell.ini b/browser/modules/test/unit/social/xpcshell.ini new file mode 100644 index 000000000..277dd4f49 --- /dev/null +++ b/browser/modules/test/unit/social/xpcshell.ini @@ -0,0 +1,13 @@ +[DEFAULT] +head = head.js +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' +support-files = blocklist.xml + +[test_social.js] +[test_socialDisabledStartup.js] +[test_SocialService.js] +[test_SocialServiceMigration21.js] +[test_SocialServiceMigration22.js] +[test_SocialServiceMigration29.js] |