Bug 1445551: Part 1c - Fix browser tests that attempt to use importGlobalProperties. r=mconley
When compartment-per-addon is disabled, browser mochitests will no longer
automatically run in an implicit Sandbox scope, which means that things like
Cu.importGlobalProperties will stop working.
MozReview-Commit-ID: AWloQ7gasEf
--- a/browser/modules/test/browser/browser_BrowserErrorReporter.js
+++ b/browser/modules/test/browser/browser_BrowserErrorReporter.js
@@ -1,16 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.import("resource:///modules/BrowserErrorReporter.jsm", this);
-Cu.importGlobalProperties(["fetch"]);
-
/* global sinon */
Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
registerCleanupFunction(function() {
delete window.sinon;
});
const PREF_ENABLED = "browser.chrome.errorReporter.enabled";
const PREF_PROJECT_ID = "browser.chrome.errorReporter.projectId";
--- a/browser/modules/test/browser/browser_ContentSearch.js
+++ b/browser/modules/test/browser/browser_ContentSearch.js
@@ -1,18 +1,16 @@
/* 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/. */
const TEST_MSG = "ContentSearchTest";
const CONTENT_SEARCH_MSG = "ContentSearch";
const TEST_CONTENT_SCRIPT_BASENAME = "contentSearch.js";
-Cu.importGlobalProperties(["XMLHttpRequest"]);
-
var gMsgMan;
/* import-globals-from ../../../components/search/test/head.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/browser/components/search/test/head.js",
this);
let originalEngine = Services.search.currentEngine;
--- a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js
+++ b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbarbutton_colors.js
@@ -1,11 +1,11 @@
"use strict";
-Cu.importGlobalProperties(["InspectorUtils"]);
+/* globals InspectorUtils */
// This test checks whether applied WebExtension themes that attempt to change
// the button background color properties are applied correctly.
add_task(async function test_button_background_properties() {
const BUTTON_BACKGROUND_ACTIVE = "#FFFFFF";
const BUTTON_BACKGROUND_HOVER = "#59CBE8";
--- a/toolkit/components/thumbnails/test/browser_thumbnails_expiration.js
+++ b/toolkit/components/thumbnails/test/browser_thumbnails_expiration.js
@@ -1,17 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const URL = "http://mochi.test:8888/?t=" + Date.now();
const URL1 = URL + "#1";
const URL2 = URL + "#2";
const URL3 = URL + "#3";
-var tmp = {};
+var tmp = Cu.Sandbox(window, {wantGlobalProperties: ["ChromeUtils"]});
Services.scriptloader.loadSubScript("resource://gre/modules/PageThumbs.jsm", tmp);
const EXPIRATION_MIN_CHUNK_SIZE = 50;
const {PageThumbsExpiration} = tmp;
function* runTests() {
// Create dummy URLs.
let dummyURLs = [];
--- a/toolkit/components/thumbnails/test/browser_thumbnails_storage_migrate3.js
+++ b/toolkit/components/thumbnails/test/browser_thumbnails_storage_migrate3.js
@@ -2,17 +2,17 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
const URL = "http://mochi.test:8888/migration3";
const URL2 = URL + "#2";
const URL3 = URL + "#3";
const THUMBNAIL_DIRECTORY = "thumbnails";
const PREF_STORAGE_VERSION = "browser.pagethumbnails.storage_version";
-var tmp = {};
+var tmp = Cu.Sandbox(window, {wantGlobalProperties: ["ChromeUtils"]});
Services.scriptloader.loadSubScript("resource://gre/modules/PageThumbs.jsm", tmp);
var {PageThumbsStorageMigrator} = tmp;
XPCOMUtils.defineLazyServiceGetter(this, "gDirSvc",
"@mozilla.org/file/directory_service;1", "nsIProperties");
/**
* This test makes sure we correctly migrate to thumbnail storage version 3.
--- a/toolkit/modules/tests/browser/browser_WebRequest_ancestors.js
+++ b/toolkit/modules/tests/browser/browser_WebRequest_ancestors.js
@@ -1,11 +1,13 @@
"use strict";
-Cu.importGlobalProperties(["XMLHttpRequest"]);
+// This test requires an XMLHttpRequest constructor which isn't
+// associated with a window.
+const {XMLHttpRequest} = Cu.Sandbox(window, {wantGlobalProperties: ["XMLHttpRequest"]});
var {WebRequest} = ChromeUtils.import("resource://gre/modules/WebRequest.jsm", {});
var {PromiseUtils} = ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm", {});
add_task(async function test_ancestors_exist() {
let deferred = PromiseUtils.defer();
function onBeforeRequest(details) {
info(`onBeforeRequest ${details.url}`);