diff options
Diffstat (limited to 'toolkit/mozapps/extensions/test/browser/head.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/browser/head.js | 163 |
1 files changed, 44 insertions, 119 deletions
diff --git a/toolkit/mozapps/extensions/test/browser/head.js b/toolkit/mozapps/extensions/test/browser/head.js index 5a749099d..8e96b9b3f 100644 --- a/toolkit/mozapps/extensions/test/browser/head.js +++ b/toolkit/mozapps/extensions/test/browser/head.js @@ -1,16 +1,15 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -/* globals end_test*/ Components.utils.import("resource://gre/modules/NetUtil.jsm"); -var tmp = {}; +let tmp = {}; Components.utils.import("resource://gre/modules/AddonManager.jsm", tmp); Components.utils.import("resource://gre/modules/Log.jsm", tmp); -var AddonManager = tmp.AddonManager; -var AddonManagerPrivate = tmp.AddonManagerPrivate; -var Log = tmp.Log; +let AddonManager = tmp.AddonManager; +let AddonManagerPrivate = tmp.AddonManagerPrivate; +let Log = tmp.Log; var pathParts = gTestPath.split("/"); // Drop the test filename @@ -26,16 +25,13 @@ if (gTestInWindow) { const RELATIVE_DIR = pathParts.slice(4).join("/") + "/"; const TESTROOT = "http://example.com/" + RELATIVE_DIR; -const SECURE_TESTROOT = "https://example.com/" + RELATIVE_DIR; const TESTROOT2 = "http://example.org/" + RELATIVE_DIR; -const SECURE_TESTROOT2 = "https://example.org/" + RELATIVE_DIR; const CHROMEROOT = pathParts.join("/") + "/"; const PREF_DISCOVERURL = "extensions.webservice.discoverURL"; const PREF_DISCOVER_ENABLED = "extensions.getAddons.showPane"; const PREF_XPI_ENABLED = "xpinstall.enabled"; const PREF_UPDATEURL = "extensions.update.url"; const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; -const PREF_CUSTOM_XPINSTALL_CONFIRMATION_UI = "xpinstall.customConfirmationUI"; const PREF_UI_LASTCATEGORY = "extensions.ui.lastCategory"; const MANAGER_URI = "about:addons"; @@ -52,8 +48,7 @@ var PREF_CHECK_COMPATIBILITY; } catch (e) { } if (channel != "aurora" && channel != "beta" && - channel != "release" && - channel != "esr") { + channel != "release") { var version = "nightly"; } else { version = Services.appinfo.version.replace(/^([^\.]+\.[0-9]+[a-z]*).*/gi, "$1"); @@ -68,7 +63,6 @@ var gTestStart = null; var gUseInContentUI = !gTestInWindow && ("switchToTabHavingURI" in window); var gRestorePrefs = [{name: PREF_LOGGING_ENABLED}, - {name: PREF_CUSTOM_XPINSTALL_CONFIRMATION_UI}, {name: "extensions.webservice.discoverURL"}, {name: "extensions.update.url"}, {name: "extensions.update.background.url"}, @@ -80,6 +74,7 @@ var gRestorePrefs = [{name: PREF_LOGGING_ENABLED}, {name: "extensions.getAddons.search.url"}, {name: "extensions.getAddons.cache.enabled"}, {name: "devtools.chrome.enabled"}, + {name: "devtools.debugger.remote-enabled"}, {name: PREF_SEARCH_MAXRESULTS}, {name: PREF_STRICT_COMPAT}, {name: PREF_CHECK_COMPATIBILITY}]; @@ -101,8 +96,6 @@ for (let pref of gRestorePrefs) { // Turn logging on for all tests Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true); -Services.prefs.setBoolPref(PREF_CUSTOM_XPINSTALL_CONFIRMATION_UI, false); - // Helper to register test failures and close windows if any are left open function checkOpenWindows(aWindowID) { let windows = Services.wm.getEnumerator(aWindowID); @@ -120,16 +113,16 @@ function checkOpenWindows(aWindowID) { // Tools to disable and re-enable the background update and blocklist timers // so that tests can protect themselves from unwanted timer events. -var gCatMan = Components.classes["@mozilla.org/categorymanager;1"] +let gCatMan = Components.classes["@mozilla.org/categorymanager;1"] .getService(Components.interfaces.nsICategoryManager); // Default values from toolkit/mozapps/extensions/extensions.manifest, but disable*UpdateTimer() // records the actual value so we can put it back in enable*UpdateTimer() -var backgroundUpdateConfig = "@mozilla.org/addons/integration;1,getService,addon-background-update-timer,extensions.update.interval,86400"; -var blocklistUpdateConfig = "@mozilla.org/extensions/blocklist;1,getService,blocklist-background-update-timer,extensions.blocklist.interval,86400"; +let backgroundUpdateConfig = "@mozilla.org/addons/integration;1,getService,addon-background-update-timer,extensions.update.interval,86400"; +let blocklistUpdateConfig = "@mozilla.org/extensions/blocklist;1,getService,blocklist-background-update-timer,extensions.blocklist.interval,86400"; -var UTIMER = "update-timer"; -var AMANAGER = "addonManager"; -var BLOCKLIST = "nsBlocklistService"; +let UTIMER = "update-timer"; +let AMANAGER = "addonManager"; +let BLOCKLIST = "nsBlocklistService"; function disableBackgroundUpdateTimer() { info("Disabling " + UTIMER + " " + AMANAGER); @@ -230,50 +223,13 @@ function run_next_test() { executeSoon(() => log_exceptions(test)); } -var get_tooltip_info = Task.async(function*(addon) { - let managerWindow = addon.ownerDocument.defaultView; - - // The popup code uses a triggering event's target to set the - // document.tooltipNode property. - let nameNode = addon.ownerDocument.getAnonymousElementByAttribute(addon, "anonid", "name"); - let event = new managerWindow.CustomEvent("TriggerEvent"); - nameNode.dispatchEvent(event); - - let tooltip = managerWindow.document.getElementById("addonitem-tooltip"); - - let promise = BrowserTestUtils.waitForEvent(tooltip, "popupshown"); - tooltip.openPopup(nameNode, "after_start", 0, 0, false, false, event); - yield promise; - - let tiptext = tooltip.label; - - promise = BrowserTestUtils.waitForEvent(tooltip, "popuphidden"); - tooltip.hidePopup(); - yield promise; - - let expectedName = addon.getAttribute("name"); - ok(tiptext.substring(0, expectedName.length), expectedName, - "Tooltip should always start with the expected name"); - - if (expectedName.length == tiptext.length) { - return { - name: tiptext, - version: undefined - }; - } - return { - name: tiptext.substring(0, expectedName.length), - version: tiptext.substring(expectedName.length + 1) - }; -}); - function get_addon_file_url(aFilename) { try { var cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. getService(Ci.nsIChromeRegistry); var fileurl = cr.convertChromeURL(makeURI(CHROMEROOT + "addons/" + aFilename)); return fileurl.QueryInterface(Ci.nsIFileURL); - } catch (ex) { + } catch(ex) { var jar = getJar(CHROMEROOT + "addons/" + aFilename); var tmpDir = extractJarToTmp(jar); tmpDir.append(aFilename); @@ -282,19 +238,10 @@ function get_addon_file_url(aFilename) { } } -function get_current_view(aManager) { - let view = aManager.document.getElementById("view-port").selectedPanel; - if (view.id == "headered-views") { - view = aManager.document.getElementById("headered-views-content").selectedPanel; - } - is(view, aManager.gViewController.displayedView, "view controller is tracking the displayed view correctly"); - return view; -} - function get_test_items_in_list(aManager) { var tests = "@tests.mozilla.org"; - let view = get_current_view(aManager); + let view = aManager.document.getElementById("view-port").selectedPanel; let listid = view.id == "search-view" ? "search-list" : "addon-list"; let item = aManager.document.getElementById(listid).firstChild; let items = []; @@ -315,7 +262,7 @@ function get_test_items_in_list(aManager) { function check_all_in_list(aManager, aIds, aIgnoreExtras) { var doc = aManager.document; - var view = get_current_view(aManager); + var view = doc.getElementById("view-port").selectedPanel; var listid = view.id == "search-view" ? "search-list" : "addon-list"; var list = doc.getElementById(listid); @@ -343,7 +290,7 @@ function check_all_in_list(aManager, aIds, aIgnoreExtras) { function get_addon_element(aManager, aId) { var doc = aManager.document; - var view = get_current_view(aManager); + var view = doc.getElementById("view-port").selectedPanel; var listid = "addon-list"; if (view.id == "search-view") listid = "search-list"; @@ -451,7 +398,7 @@ function close_manager(aManagerWindow, aCallback, aLongerTimeout) { dump("Manager window unload handler\n"); this.removeEventListener("unload", arguments.callee, false); resolve(); - } catch (e) { + } catch(e) { reject(e); } }, false); @@ -504,11 +451,14 @@ function get_string(aName, ...aArgs) { } function formatDate(aDate) { - const locale = Cc["@mozilla.org/chrome/chrome-registry;1"] - .getService(Ci.nsIXULChromeRegistry) - .getSelectedLocale("global", true); - const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' }; - return aDate.toLocaleDateString(locale, dtOptions); + return Cc["@mozilla.org/intl/scriptabledateformat;1"] + .getService(Ci.nsIScriptableDateFormat) + .FormatDate("", + Ci.nsIScriptableDateFormat.dateFormatLong, + aDate.getFullYear(), + aDate.getMonth() + 1, + aDate.getDate() + ); } function is_hidden(aElement) { @@ -535,17 +485,6 @@ function is_element_hidden(aElement, aMsg) { ok(is_hidden(aElement), aMsg || (aElement + " should be hidden")); } -function promiseAddonByID(aId) { - return new Promise(resolve => { - AddonManager.getAddonByID(aId, resolve); - }); -} - -function promiseAddonsByIDs(aIDs) { - return new Promise(resolve => { - AddonManager.getAddonsByIDs(aIDs, resolve); - }); -} /** * Install an add-on and call a callback when complete. * @@ -684,7 +623,7 @@ function addCertOverride(host, bits) { } } -/** *** Mock Provider *****/ +/***** Mock Provider *****/ function MockProvider(aUseAsyncCallbacks, aTypes) { this.addons = []; @@ -719,7 +658,7 @@ MockProvider.prototype = { useAsyncCallbacks: null, types: null, - /** *** Utility functions *****/ + /***** Utility functions *****/ /** * Register this provider with the AddonManager @@ -745,10 +684,10 @@ MockProvider.prototype = { * The add-on to add */ addAddon: function MP_addAddon(aAddon) { - var oldAddons = this.addons.filter(aOldAddon => aOldAddon.id == aAddon.id); + var oldAddons = this.addons.filter(function(aOldAddon) aOldAddon.id == aAddon.id); var oldAddon = oldAddons.length > 0 ? oldAddons[0] : null; - this.addons = this.addons.filter(aOldAddon => aOldAddon.id != aAddon.id); + this.addons = this.addons.filter(function(aOldAddon) aOldAddon.id != aAddon.id); this.addons.push(aAddon); aAddon._provider = this; @@ -882,7 +821,7 @@ MockProvider.prototype = { return newInstalls; }, - /** *** AddonProvider implementation *****/ + /***** AddonProvider implementation *****/ /** * Called to initialize the provider. @@ -906,7 +845,7 @@ MockProvider.prototype = { info("Notifying timer set at " + (setAt || "unknown location")); timer.callback.notify(timer); timer.cancel(); - } catch (e) { + } catch(e) { info("Timer notify failed: " + e); } } @@ -1082,7 +1021,7 @@ MockProvider.prototype = { }, - /** *** Internal functions *****/ + /***** Internal functions *****/ /** * Delay calling a callback to fake a time-consuming async operation. @@ -1118,7 +1057,7 @@ MockProvider.prototype = { } }; -/** *** Mock Addon object for the Mock Provider *****/ +/***** Mock Addon object for the Mock Provider *****/ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) { // Only set required attributes. @@ -1127,6 +1066,7 @@ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) { this.type = aType || "extension"; this.version = ""; this.isCompatible = true; + this.isDebuggable = false; this.providesUpdatesSecurely = true; this.blocklistState = 0; this._appDisabled = false; @@ -1140,8 +1080,7 @@ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) { AddonManager.PERM_CAN_ENABLE | AddonManager.PERM_CAN_DISABLE | AddonManager.PERM_CAN_UPGRADE; - this.operationsRequiringRestart = (aOperationsRequiringRestart != undefined) ? - aOperationsRequiringRestart : + this.operationsRequiringRestart = aOperationsRequiringRestart || (AddonManager.OP_NEEDS_RESTART_INSTALL | AddonManager.OP_NEEDS_RESTART_UNINSTALL | AddonManager.OP_NEEDS_RESTART_ENABLE | @@ -1149,12 +1088,6 @@ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) { } MockAddon.prototype = { - get isCorrectlySigned() { - if (this.signedState === AddonManager.SIGNEDSTATE_NOT_REQUIRED) - return true; - return this.signedState > AddonManager.SIGNEDSTATE_MISSING; - }, - get shouldBeActive() { return !this.appDisabled && !this._userDisabled && !(this.pendingOperations & AddonManager.PENDING_UNINSTALL); @@ -1254,10 +1187,6 @@ MockAddon.prototype = { AddonManagerPrivate.callAddonListeners("onOperationCancelled", this); }, - markAsSeen: function() { - this.seen = true; - }, - _updateActiveState: function(currentActive, newActive) { if (currentActive == newActive) return; @@ -1267,7 +1196,7 @@ MockAddon.prototype = { AddonManagerPrivate.callAddonListeners("onOperationCancelled", this); } else if (newActive) { - let needsRestart = !!(this.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_ENABLE); + var needsRestart = !!(this.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_ENABLE); this.pendingOperations |= AddonManager.PENDING_ENABLE; AddonManagerPrivate.callAddonListeners("onEnabling", this, needsRestart); if (!needsRestart) { @@ -1277,7 +1206,7 @@ MockAddon.prototype = { } } else { - let needsRestart = !!(this.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_DISABLE); + var needsRestart = !!(this.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_DISABLE); this.pendingOperations |= AddonManager.PENDING_DISABLE; AddonManagerPrivate.callAddonListeners("onDisabling", this, needsRestart); if (!needsRestart) { @@ -1289,7 +1218,7 @@ MockAddon.prototype = { } }; -/** *** Mock AddonInstall object for the Mock Provider *****/ +/***** Mock AddonInstall object for the Mock Provider *****/ function MockInstall(aName, aType, aAddonToInstall) { this.name = aName || ""; @@ -1357,18 +1286,14 @@ MockInstall.prototype = { return; } - let needsRestart = (this.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_INSTALL); - AddonManagerPrivate.callAddonListeners("onInstalling", this.addon, needsRestart); - if (!needsRestart) { - AddonManagerPrivate.callAddonListeners("onInstalled", this.addon); - } + AddonManagerPrivate.callAddonListeners("onInstalling", this.addon); this.state = AddonManager.STATE_INSTALLED; this.callListeners("onInstallEnded"); break; case AddonManager.STATE_DOWNLOADING: case AddonManager.STATE_CHECKING: - case AddonManager.STATE_INSTALLING: + case AddonManger.STATE_INSTALLING: // Installation is already running return; default: @@ -1394,21 +1319,21 @@ MockInstall.prototype = { addListener: function(aListener) { - if (!this.listeners.some(i => i == aListener)) + if (!this.listeners.some(function(i) i == aListener)) this.listeners.push(aListener); }, removeListener: function(aListener) { - this.listeners = this.listeners.filter(i => i != aListener); + this.listeners = this.listeners.filter(function(i) i != aListener); }, addTestListener: function(aListener) { - if (!this.testListeners.some(i => i == aListener)) + if (!this.testListeners.some(function(i) i == aListener)) this.testListeners.push(aListener); }, removeTestListener: function(aListener) { - this.testListeners = this.testListeners.filter(i => i != aListener); + this.testListeners = this.testListeners.filter(function(i) i != aListener); }, callListeners: function(aMethod) { |