fune/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_message_close.js
Rob Wu 64ad4811f6 Bug 1570715 - Treat (deprecation) warnings as errors r=rpl
Add new preference `extensions.webextensions.warnings-as-errors` that
defaults to `true` in tests. Tests that expect warnings are modified
to briefly flip the pref for the specific part of the test that needs
an exception.

As part of the refactor, log entries for schema entries that contain
`"onError": "warn"` will now be prefixed by "Warning" instead of
"Error", to be consistent with the change from bug 1495908.

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

--HG--
extra : moz-landing-system : lando
2019-09-16 16:35:59 +00:00

82 lines
2.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* import-globals-from helper-addons.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
const EXTENSION_NAME = "Temporary web extension";
const EXTENSION_ID = "test-devtools@mozilla.org";
// Test that Message component can be closed with the X button
add_task(async function() {
const { document, tab, window } = await openAboutDebugging();
await selectThisFirefoxPage(document, window.AboutDebugging.store);
info("Check that the message can be closed with icon");
let warningMessage = await installExtensionWithWarning(document);
await testCloseMessageWithIcon(warningMessage, document);
await removeTemporaryExtension(EXTENSION_NAME, document);
info("Check that the message can be closed with the button around the icon");
warningMessage = await installExtensionWithWarning(document);
await testCloseMessageWithButton(warningMessage, document);
await removeTemporaryExtension(EXTENSION_NAME, document);
await removeTab(tab);
});
async function testCloseMessageWithIcon(warningMessage, doc) {
const closeIcon = warningMessage.querySelector(
".qa-message-button-close-icon"
);
ok(!!closeIcon, "The warning message has a close icon");
info("Closing the message and waiting for it to disappear");
closeIcon.click();
const target = findDebugTargetByText(EXTENSION_NAME, doc);
await waitUntil(() => target.querySelector(".qa-message") === null);
}
async function testCloseMessageWithButton(warningMessage, doc) {
const closeButton = warningMessage.querySelector(
".qa-message-button-close-button"
);
ok(!!closeButton, "The warning message has a close button");
info("Click on the button and wait for the message to disappear");
EventUtils.synthesizeMouse(closeButton, 1, 1, {}, doc.defaultView);
const target = findDebugTargetByText(EXTENSION_NAME, doc);
await waitUntil(() => target.querySelector(".qa-message") === null);
}
async function installExtensionWithWarning(doc) {
await pushPref("extensions.webextensions.warnings-as-errors", false);
await installTemporaryExtensionFromXPI(
{
id: EXTENSION_ID,
name: EXTENSION_NAME,
extraProperties: {
// This property is not expected in the manifest and should trigger a warning!
wrongProperty: {},
},
},
doc
);
await SpecialPowers.popPrefEnv();
info("Wait until a debug target item appears");
await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, doc));
const target = findDebugTargetByText(EXTENSION_NAME, doc);
const warningMessage = target.querySelector(".qa-message");
ok(
!!warningMessage,
"A warning message is displayed for the installed addon"
);
return warningMessage;
}