From ed35ca6be4bd5dfe332d57301f6023f0e7a96447 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Tue, 16 Aug 2016 14:34:06 -0700 Subject: [PATCH] Bug 1289549 P3 socialapi move toolkit component to browser, r=florian MozReview-Commit-ID: JosyCE9HAac --HG-- rename : toolkit/components/social/SocialService.jsm => browser/modules/SocialService.jsm rename : toolkit/components/social/test/xpcshell/test_SocialService.js => browser/modules/test/unit/social/test_SocialService.js rename : toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js => browser/modules/test/unit/social/test_SocialServiceMigration21.js rename : toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js => browser/modules/test/unit/social/test_SocialServiceMigration22.js rename : toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.js => browser/modules/test/unit/social/test_SocialServiceMigration29.js --- .../social/browser_aboutHome_activation.js | 2 +- .../content/test/social/browser_addons.js | 2 +- .../content/test/social/browser_blocklist.js | 2 +- .../base/content/test/social/browser_share.js | 2 +- .../test/social/browser_social_activation.js | 2 +- browser/base/content/test/social/head.js | 4 +- browser/modules/Social.jsm | 2 +- .../modules}/SocialService.jsm | 0 browser/modules/moz.build | 1 + browser/modules/test/unit/social/head.js | 85 +++++++++++- .../test/unit/social}/test_SocialService.js | 2 +- .../social}/test_SocialServiceMigration21.js | 2 +- .../social}/test_SocialServiceMigration22.js | 2 +- .../social}/test_SocialServiceMigration29.js | 2 +- .../modules/test/unit/social/test_social.js | 2 +- browser/modules/test/unit/social/xpcshell.ini | 4 + toolkit/components/moz.build | 3 - toolkit/components/social/moz.build | 16 --- .../social/test/xpcshell/blocklist.xml | 6 - .../components/social/test/xpcshell/head.js | 125 ------------------ .../social/test/xpcshell/xpcshell.ini | 13 -- 21 files changed, 102 insertions(+), 177 deletions(-) rename {toolkit/components/social => browser/modules}/SocialService.jsm (100%) rename {toolkit/components/social/test/xpcshell => browser/modules/test/unit/social}/test_SocialService.js (99%) rename {toolkit/components/social/test/xpcshell => browser/modules/test/unit/social}/test_SocialServiceMigration21.js (97%) rename {toolkit/components/social/test/xpcshell => browser/modules/test/unit/social}/test_SocialServiceMigration22.js (97%) rename {toolkit/components/social/test/xpcshell => browser/modules/test/unit/social}/test_SocialServiceMigration29.js (97%) delete mode 100644 toolkit/components/social/moz.build delete mode 100644 toolkit/components/social/test/xpcshell/blocklist.xml delete mode 100644 toolkit/components/social/test/xpcshell/head.js delete mode 100644 toolkit/components/social/test/xpcshell/xpcshell.ini diff --git a/browser/base/content/test/social/browser_aboutHome_activation.js b/browser/base/content/test/social/browser_aboutHome_activation.js index 615d19c6faea..9789c306bb0d 100644 --- a/browser/base/content/test/social/browser_aboutHome_activation.js +++ b/browser/base/content/test/social/browser_aboutHome_activation.js @@ -2,7 +2,7 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; +var SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); diff --git a/browser/base/content/test/social/browser_addons.js b/browser/base/content/test/social/browser_addons.js index 6d74d6875516..abbfbe35166a 100644 --- a/browser/base/content/test/social/browser_addons.js +++ b/browser/base/content/test/social/browser_addons.js @@ -1,5 +1,5 @@ var AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm", {}).AddonManager; -var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; +var SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; var manifest = { name: "provider 1", diff --git a/browser/base/content/test/social/browser_blocklist.js b/browser/base/content/test/social/browser_blocklist.js index 94968e06d7e3..9825e016bd90 100644 --- a/browser/base/content/test/social/browser_blocklist.js +++ b/browser/base/content/test/social/browser_blocklist.js @@ -4,7 +4,7 @@ // a place for miscellaneous social tests -var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; +var SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; var blocklistURL = "http://example.com/browser/browser/base/content/test/social/blocklist.xml"; diff --git a/browser/base/content/test/social/browser_share.js b/browser/base/content/test/social/browser_share.js index 9eba851083b1..3b0e3aa934f0 100644 --- a/browser/base/content/test/social/browser_share.js +++ b/browser/base/content/test/social/browser_share.js @@ -1,5 +1,5 @@ -var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; +var SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; var baseURL = "https://example.com/browser/browser/base/content/test/social/"; diff --git a/browser/base/content/test/social/browser_social_activation.js b/browser/base/content/test/social/browser_social_activation.js index dcd7408dc45f..ea8963f52a31 100644 --- a/browser/base/content/test/social/browser_social_activation.js +++ b/browser/base/content/test/social/browser_social_activation.js @@ -10,7 +10,7 @@ thisTestLeaksUncaughtRejectionsAndShouldBeFixed("TypeError: Assert is null"); -var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; +var SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; var tabsToRemove = []; diff --git a/browser/base/content/test/social/head.js b/browser/base/content/test/social/head.js index 2a296ede4fc9..0e9be7a3293a 100644 --- a/browser/base/content/test/social/head.js +++ b/browser/base/content/test/social/head.js @@ -56,7 +56,7 @@ function defaultFinishChecks() { function runSocialTestWithProvider(manifest, callback, finishcallback) { - let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; + let SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; let manifests = Array.isArray(manifest) ? manifest : [manifest]; @@ -193,7 +193,7 @@ function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) { // A fairly large hammer which checks all aspects of the SocialUI for // internal consistency. function checkSocialUI(win) { - let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; + let SocialService = Cu.import("resource:///modules/SocialService.jsm", {}).SocialService; // if we have enabled providers, we should also have instances of those // providers if (SocialService.hasEnabledProviders) { diff --git a/browser/modules/Social.jsm b/browser/modules/Social.jsm index a6a998f88718..1569e01220f9 100644 --- a/browser/modules/Social.jsm +++ b/browser/modules/Social.jsm @@ -22,7 +22,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI", "resource:///modules/CustomizableUI.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "SocialService", - "resource://gre/modules/SocialService.jsm"); + "resource:///modules/SocialService.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PageMetadata", "resource://gre/modules/PageMetadata.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", diff --git a/toolkit/components/social/SocialService.jsm b/browser/modules/SocialService.jsm similarity index 100% rename from toolkit/components/social/SocialService.jsm rename to browser/modules/SocialService.jsm diff --git a/browser/modules/moz.build b/browser/modules/moz.build index c7af7f480e4e..87fa63ea6963 100644 --- a/browser/modules/moz.build +++ b/browser/modules/moz.build @@ -42,6 +42,7 @@ EXTRA_JS_MODULES += [ 'SelfSupportBackend.jsm', 'SitePermissions.jsm', 'Social.jsm', + 'SocialService.jsm', 'TabGroupsMigrator.jsm', 'TransientPrefs.jsm', 'URLBarZoom.jsm', diff --git a/browser/modules/test/unit/social/head.js b/browser/modules/test/unit/social/head.js index b09d6733e0a8..9a35bd31f2ce 100644 --- a/browser/modules/test/unit/social/head.js +++ b/browser/modules/test/unit/social/head.js @@ -116,7 +116,7 @@ function do_initialize_social(enabledOnStartup, cb) { } // import and initialize everything - SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; + 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"); @@ -125,3 +125,86 @@ function do_initialize_social(enabledOnStartup, cb) { 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/toolkit/components/social/test/xpcshell/test_SocialService.js b/browser/modules/test/unit/social/test_SocialService.js similarity index 99% rename from toolkit/components/social/test/xpcshell/test_SocialService.js rename to browser/modules/test/unit/social/test_SocialService.js index ce6eab930bfc..e6f354fed338 100644 --- a/toolkit/components/social/test/xpcshell/test_SocialService.js +++ b/browser/modules/test/unit/social/test_SocialService.js @@ -25,7 +25,7 @@ function run_test() { } ]; - Cu.import("resource://gre/modules/SocialService.jsm"); + Cu.import("resource:///modules/SocialService.jsm"); let runner = new AsyncRunner(); let next = runner.next.bind(runner); diff --git a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js b/browser/modules/test/unit/social/test_SocialServiceMigration21.js similarity index 97% rename from toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js rename to browser/modules/test/unit/social/test_SocialServiceMigration21.js index d2a996ddbbfe..dfe6183bf2f4 100644 --- a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js +++ b/browser/modules/test/unit/social/test_SocialServiceMigration21.js @@ -22,7 +22,7 @@ function run_test() { DEFAULT_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); Services.prefs.setBoolPref("social.active", true); - Cu.import("resource://gre/modules/SocialService.jsm"); + Cu.import("resource:///modules/SocialService.jsm"); let runner = new AsyncRunner(); let next = runner.next.bind(runner); diff --git a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js b/browser/modules/test/unit/social/test_SocialServiceMigration22.js similarity index 97% rename from toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js rename to browser/modules/test/unit/social/test_SocialServiceMigration22.js index a0e80e9083d4..1a39531756e3 100644 --- a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js +++ b/browser/modules/test/unit/social/test_SocialServiceMigration22.js @@ -32,7 +32,7 @@ function run_test() { Services.prefs.setComplexValue("social.activeProviders", Ci.nsISupportsString, activeVal); - Cu.import("resource://gre/modules/SocialService.jsm"); + Cu.import("resource:///modules/SocialService.jsm"); let runner = new AsyncRunner(); let next = runner.next.bind(runner); diff --git a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.js b/browser/modules/test/unit/social/test_SocialServiceMigration29.js similarity index 97% rename from toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.js rename to browser/modules/test/unit/social/test_SocialServiceMigration29.js index 37d61d75f02d..824673ddfd56 100644 --- a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration29.js +++ b/browser/modules/test/unit/social/test_SocialServiceMigration29.js @@ -33,7 +33,7 @@ function run_test() { // b) unset social.enabled Services.prefs.setBoolPref("social.enabled", false); - Cu.import("resource://gre/modules/SocialService.jsm"); + Cu.import("resource:///modules/SocialService.jsm"); let runner = new AsyncRunner(); let next = runner.next.bind(runner); diff --git a/browser/modules/test/unit/social/test_social.js b/browser/modules/test/unit/social/test_social.js index ec5f28366ad3..3117306c1df5 100644 --- a/browser/modules/test/unit/social/test_social.js +++ b/browser/modules/test/unit/social/test_social.js @@ -19,7 +19,7 @@ function testStartupEnabled() { } function testDisableAfterStartup() { - let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; + 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"); diff --git a/browser/modules/test/unit/social/xpcshell.ini b/browser/modules/test/unit/social/xpcshell.ini index 55e708eb164d..3154d99845db 100644 --- a/browser/modules/test/unit/social/xpcshell.ini +++ b/browser/modules/test/unit/social/xpcshell.ini @@ -7,3 +7,7 @@ support-files = blocklist.xml [test_social.js] [test_socialDisabledStartup.js] +[test_SocialService.js] +[test_SocialServiceMigration21.js] +[test_SocialServiceMigration22.js] +[test_SocialServiceMigration29.js] diff --git a/toolkit/components/moz.build b/toolkit/components/moz.build index 6a64bd2338cf..ab3f840ecb9b 100644 --- a/toolkit/components/moz.build +++ b/toolkit/components/moz.build @@ -75,9 +75,6 @@ if CONFIG['MOZ_BUILD_APP'] != 'mobile/android': if CONFIG['MOZ_CRASHREPORTER']: DIRS += ['crashes'] -if CONFIG['MOZ_SOCIAL']: - DIRS += ['social'] - if CONFIG['BUILD_CTYPES']: DIRS += ['ctypes'] diff --git a/toolkit/components/social/moz.build b/toolkit/components/social/moz.build deleted file mode 100644 index 8f74b2d6166a..000000000000 --- a/toolkit/components/social/moz.build +++ /dev/null @@ -1,16 +0,0 @@ -# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini'] - -if CONFIG['MOZ_SOCIAL']: - # social is turned off for android - EXTRA_JS_MODULES += [ - 'SocialService.jsm', - ] - -with Files('**'): - BUG_COMPONENT = ('Firefox', 'SocialAPI') diff --git a/toolkit/components/social/test/xpcshell/blocklist.xml b/toolkit/components/social/test/xpcshell/blocklist.xml deleted file mode 100644 index c8d72d624224..000000000000 --- a/toolkit/components/social/test/xpcshell/blocklist.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/toolkit/components/social/test/xpcshell/head.js b/toolkit/components/social/test/xpcshell/head.js deleted file mode 100644 index 098a41a90195..000000000000 --- a/toolkit/components/social/test/xpcshell/head.js +++ /dev/null @@ -1,125 +0,0 @@ -/* 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"); - -XPCOMUtils.defineLazyModuleGetter(this, "Promise", - "resource://gre/modules/Promise.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", - "resource://gre/modules/PlacesUtils.jsm"); - -const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest."); -const gProfD = do_get_profile(); - -const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; -const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"); - -var gAppInfo = null; - -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(); -} - -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/toolkit/components/social/test/xpcshell/xpcshell.ini b/toolkit/components/social/test/xpcshell/xpcshell.ini deleted file mode 100644 index 7fd75b043930..000000000000 --- a/toolkit/components/social/test/xpcshell/xpcshell.ini +++ /dev/null @@ -1,13 +0,0 @@ -[DEFAULT] -head = head.js -tail = -skip-if = toolkit == 'android' || toolkit == 'gonk' -support-files = blocklist.xml - -[test_SocialService.js] - -[test_SocialServiceMigration21.js] - -[test_SocialServiceMigration22.js] - -[test_SocialServiceMigration29.js]