Skip to content

Commit

Permalink
Bug 1830816 - Convert JSMs in browser/tools/mozscreenshots/mozscreens…
Browse files Browse the repository at this point in the history
…hots/extension to ESMs. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D177101
  • Loading branch information
kpatenio committed May 8, 2023
1 parent f4f0c35 commit d9858a3
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ module.exports = {
"browser/base/content/test/sanitize/browser_sanitize-history.js",
"devtools/client/shared/test/shared-head.js",
"devtools/client/shared/test/head.js",
"browser/tools/mozscreenshots/mozscreenshots/extension/configurations/ControlCenter.jsm",
"browser/tools/mozscreenshots/mozscreenshots/extension/configurations/ControlCenter.sys.mjs",
// uses new HttpServer which doesn't support https
"browser/base/content/test/favicons/browser_favicon_nostore.js",
// That are all files that produes warnings in the existing test infrastructure.
Expand Down
5 changes: 3 additions & 2 deletions browser/tools/mozscreenshots/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ async function setup() {

let aAddon = await AddonManager.getAddonByID("[email protected]");
isnot(aAddon, null, "The mozscreenshots extension should be installed");
TestRunner = ChromeUtils.import("resource://mozscreenshots/TestRunner.jsm")
.TestRunner;
TestRunner = ChromeUtils.importESModule(
"resource://mozscreenshots/TestRunner.sys.mjs"
).TestRunner;
TestRunner.initTest(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["Screenshot"];

const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
// See LOG_LEVELS in Console.sys.mjs. Common examples: "All", "Info", "Warn", &
Expand All @@ -30,7 +22,7 @@ XPCOMUtils.defineLazyGetter(lazy, "log", () => {
return new ConsoleAPI(consoleOptions);
});

var Screenshot = {
export var Screenshot = {
_extensionPath: null,
_path: null,
_imagePrefix: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,22 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["TestRunner"];

const APPLY_CONFIG_TIMEOUT_MS = 60 * 1000;
const HOME_PAGE = "resource://mozscreenshots/lib/mozscreenshots.html";

const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { Rect } = ChromeUtils.importESModule(
"resource://gre/modules/Geometry.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { Rect } from "resource://gre/modules/Geometry.sys.mjs";

const lazy = {};

ChromeUtils.defineESModuleGetters(lazy, {
BrowserTestUtils: "resource://testing-common/BrowserTestUtils.sys.mjs",
// Screenshot.sys.mjs must be imported this way for xpcshell tests to work
Screenshot: "resource://mozscreenshots/Screenshot.jsm",
});
// Screenshot.jsm must be imported this way for xpcshell tests to work
ChromeUtils.defineModuleGetter(
lazy,
"Screenshot",
"resource://mozscreenshots/Screenshot.jsm"
);

var TestRunner = {

export var TestRunner = {
combos: null,
completedCombos: 0,
currentComboIndex: 0,
Expand Down
4 changes: 2 additions & 2 deletions browser/tools/mozscreenshots/mozscreenshots/extension/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ this.mozscreenshots = class extends ExtensionAPI {
let uri = Services.io.newURI("resources/", null, this.extension.rootURI);
resProto.setSubstitution("mozscreenshots", uri);

const { TestRunner } = ChromeUtils.import(
"resource://mozscreenshots/TestRunner.jsm"
const { TestRunner } = ChromeUtils.importESModule(
"resource://mozscreenshots/TestRunner.sys.mjs"
);
TestRunner.init(this.extension.rootURI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
* 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/. */

"use strict";
import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys.mjs";

var EXPORTED_SYMBOLS = ["AppMenu"];

const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);

var AppMenu = {
export var AppMenu = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["Buttons"];

const { CustomizableUI } = ChromeUtils.import(
"resource:///modules/CustomizableUI.jsm"
);

var Buttons = {
export var Buttons = {
init(libDir) {
createWidget();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@
* 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/. */

"use strict";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys.mjs";

var EXPORTED_SYMBOLS = ["ControlCenter"];

const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);
const { SitePermissions } = ChromeUtils.import(
"resource:///modules/SitePermissions.jsm"
);
const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";

let { UrlClassifierTestUtils } = ChromeUtils.import(
"resource://testing-common/UrlClassifierTestUtils.jsm"
Expand All @@ -38,7 +29,7 @@ const MIXED_ACTIVE_CONTENT_URL = `https://example.com/${RESOURCE_PATH}/mixed_act
const MIXED_PASSIVE_CONTENT_URL = `https://example.com/${RESOURCE_PATH}/mixed_passive.html`;
const TRACKING_PAGE = `http://tracking.example.org/${RESOURCE_PATH}/tracking.html`;

var ControlCenter = {
export var ControlCenter = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
* 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/. */

"use strict";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";

var EXPORTED_SYMBOLS = ["CustomizeMode"];

const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);

var CustomizeMode = {
export var CustomizeMode = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
* 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/. */

"use strict";
import { require } from "resource://devtools/shared/loader/Loader.sys.mjs";

var EXPORTED_SYMBOLS = ["DevTools"];

const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const { gDevTools } = require("devtools/client/framework/devtools");
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);

import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";

async function showToolboxForSelectedTab(toolId, hostType) {
const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
Expand All @@ -24,7 +18,7 @@ function selectToolbox(toolbox) {
return toolbox.win.document.querySelector("#toolbox-container");
}

var DevTools = {
export var DevTools = {
init(libDir) {
let panels = [
"options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["LightweightThemes"];

const { AddonManager } = ChromeUtils.import(
"resource://gre/modules/AddonManager.jsm"
);

var LightweightThemes = {
export var LightweightThemes = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@
* 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/. */

"use strict";

// Various parts here are run in the content process.
/* global content */

var EXPORTED_SYMBOLS = ["PermissionPrompts"];

const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);
import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys.mjs";

const URL =
"https://test1.example.com/browser/browser/tools/mozscreenshots/mozscreenshots/extension/mozscreenshots/browser/resources/lib/permissionPrompts.html";
let lastTab = null;

var PermissionPrompts = {
export var PermissionPrompts = {
init(libDir) {
Services.prefs.setBoolPref("media.navigator.permission.fake", true);
Services.prefs.setBoolPref("extensions.install.requireBuiltInCerts", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
* 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/. */

"use strict";

// Various parts here are run in the content process.
/* global content */

var EXPORTED_SYMBOLS = ["Preferences"];
import { TestUtils } from "resource://testing-common/TestUtils.sys.mjs";

const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
var Preferences = {
export var Preferences = {
init(libDir) {
let panes = [
["paneGeneral"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["Tabs"];

const CUST_TAB = "chrome://browser/skin/customize.svg";
const PREFS_TAB = "chrome://global/skin/icons/settings.svg";
const DEFAULT_FAVICON_TAB = `data:text/html,<meta%20charset="utf-8"><title>No%20favicon</title>`;

const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { TestUtils } from "resource://testing-common/TestUtils.sys.mjs";

var Tabs = {
export var Tabs = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["TabsInTitlebar"];

const PREF_TABS_IN_TITLEBAR = "browser.tabs.inTitlebar";

var TabsInTitlebar = {
export var TabsInTitlebar = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["Toolbars"];

var Toolbars = {
export var Toolbars = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* 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/. */

"use strict";

var EXPORTED_SYMBOLS = ["UIDensities"];

var UIDensities = {
export var UIDensities = {
init(libDir) {},

configurations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
* 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/. */

"use strict";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys.mjs";

var EXPORTED_SYMBOLS = ["WindowSize"];

const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);

var WindowSize = {
export var WindowSize = {
init(libDir) {
Services.prefs.setBoolPref("browser.fullscreen.autohide", false);
},
Expand Down
Loading

0 comments on commit d9858a3

Please sign in to comment.