Bug 1494549 - Add a mochitest test for status message;r=ladybenko

Depends on D8334.
In this changeset we also change the way we are reading the preferences
in adb-addon.js to avoid caching the value of the preference the first
time the module is loaded.

This allows the module to follow updates of said preferences without
having to restart Firefox.

Differential Revision: https://phabricator.services.mozilla.com/D8335

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2018-10-12 07:20:22 +00:00
Родитель 26732aa0db
Коммит 367cd9399a
8 изменённых файлов: 56 добавлений и 7 удалений

Просмотреть файл

@ -41,7 +41,7 @@ class Sidebar extends PureComponent {
id: localizationId id: localizationId
}, dom.aside( }, dom.aside(
{ {
className: "sidebar__devices__message" className: "sidebar__devices__message js-sidebar-usb-status"
}, },
localizationId localizationId
) )

Просмотреть файл

@ -5,6 +5,7 @@ support-files =
debug-target-pane_collapsibilities_head.js debug-target-pane_collapsibilities_head.js
head-addons-script.js head-addons-script.js
head.js head.js
resources/test-adb-extension/*
resources/test-temporary-extension/* resources/test-temporary-extension/*
!/devtools/client/shared/test/shared-head.js !/devtools/client/shared/test/shared-head.js
!/devtools/client/shared/test/telemetry-test-helpers.js !/devtools/client/shared/test/telemetry-test-helpers.js
@ -15,4 +16,5 @@ support-files =
[browser_aboutdebugging_debug-target-pane_empty.js] [browser_aboutdebugging_debug-target-pane_empty.js]
[browser_aboutdebugging_navigate.js] [browser_aboutdebugging_navigate.js]
[browser_aboutdebugging_sidebar_network_runtimes.js] [browser_aboutdebugging_sidebar_network_runtimes.js]
[browser_aboutdebugging_sidebar_usb_status.js]
[browser_aboutdebugging_thisfirefox.js] [browser_aboutdebugging_thisfirefox.js]

Просмотреть файл

@ -0,0 +1,41 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { adbAddon } = require("devtools/shared/adb/adb-addon");
/**
* This test asserts that the sidebar shows a message describing the status of the USB
* devices scanning.
*/
add_task(async function() {
// Make sure the ADB addon is removed when the test ends.
registerCleanupFunction(async function() {
try {
await adbAddon.uninstall();
} catch (e) {
// Will throw if the addon is already uninstalled, ignore exceptions here.
}
});
await pushPref("devtools.remote.adb.extensionURL",
CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi");
const { document, tab } = await openAboutDebugging();
const usbStatusElement = document.querySelector(".js-sidebar-usb-status");
ok(usbStatusElement, "Sidebar shows the USB status element");
ok(usbStatusElement.textContent.includes("USB devices disabled"),
"USB status element has the expected content");
info("Install the adb extension and wait for the message to udpate");
adbAddon.install();
await waitUntil(() => usbStatusElement.textContent.includes("USB devices enabled"));
info("Uninstall the adb extension and wait for the message to udpate");
adbAddon.uninstall();
await waitUntil(() => usbStatusElement.textContent.includes("USB devices disabled"));
await removeTab(tab);
});

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -8,8 +8,8 @@ const {AddonManager} = require("resource://gre/modules/AddonManager.jsm");
const Services = require("Services"); const Services = require("Services");
const EventEmitter = require("devtools/shared/event-emitter"); const EventEmitter = require("devtools/shared/event-emitter");
const ADB_LINK = Services.prefs.getCharPref("devtools.remote.adb.extensionURL"); const PREF_ADB_EXTENSION_URL = "devtools.remote.adb.extensionURL";
const ADB_ADDON_ID = Services.prefs.getCharPref("devtools.remote.adb.extensionID"); const PREF_ADB_EXTENSION_ID = "devtools.remote.adb.extensionID";
// Extension ID for adb helper extension that might be installed on Firefox 63 or older. // Extension ID for adb helper extension that might be installed on Firefox 63 or older.
const OLD_ADB_ADDON_ID = "adbhelper@mozilla.org"; const OLD_ADB_ADDON_ID = "adbhelper@mozilla.org";
@ -65,8 +65,13 @@ class ADBAddon extends EventEmitter {
return this._status; return this._status;
} }
async _getAddon() {
const addonId = Services.prefs.getCharPref(PREF_ADB_EXTENSION_ID);
return AddonManager.getAddonByID(addonId);
}
async updateInstallStatus() { async updateInstallStatus() {
const addon = await AddonManager.getAddonByID(ADB_ADDON_ID); const addon = await this._getAddon();
if (addon && !addon.userDisabled) { if (addon && !addon.userDisabled) {
this.status = ADB_ADDON_STATES.INSTALLED; this.status = ADB_ADDON_STATES.INSTALLED;
} else { } else {
@ -92,7 +97,8 @@ class ADBAddon extends EventEmitter {
} }
} }
return ADB_LINK.replace(/#OS#/g, OS); const xpiLink = Services.prefs.getCharPref(PREF_ADB_EXTENSION_URL);
return xpiLink.replace(/#OS#/g, OS);
} }
/** /**
@ -103,7 +109,7 @@ class ADBAddon extends EventEmitter {
* String passed to the AddonManager for telemetry. * String passed to the AddonManager for telemetry.
*/ */
async install(source) { async install(source) {
const addon = await AddonManager.getAddonByID(ADB_ADDON_ID); const addon = await this._getAddon();
if (addon && !addon.userDisabled) { if (addon && !addon.userDisabled) {
this.status = ADB_ADDON_STATES.INSTALLED; this.status = ADB_ADDON_STATES.INSTALLED;
return; return;
@ -124,7 +130,7 @@ class ADBAddon extends EventEmitter {
} }
async uninstall() { async uninstall() {
const addon = await AddonManager.getAddonByID(ADB_ADDON_ID); const addon = await this._getAddon();
addon.uninstall(); addon.uninstall();
} }