browser_aboutdebugging_message_close.js (2845B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-addons.js */ 7 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this); 8 9 const EXTENSION_NAME = "Temporary web extension"; 10 const EXTENSION_ID = "test-devtools@mozilla.org"; 11 12 // Test that Message component can be closed with the X button 13 add_task(async function () { 14 const { document, tab, window } = await openAboutDebugging(); 15 await selectThisFirefoxPage(document, window.AboutDebugging.store); 16 17 info("Check that the message can be closed with icon"); 18 let warningMessage = await installExtensionWithWarning(document); 19 await testCloseMessageWithIcon(warningMessage, document); 20 await removeTemporaryExtension(EXTENSION_NAME, document); 21 22 info("Check that the message can be closed with the button around the icon"); 23 warningMessage = await installExtensionWithWarning(document); 24 await testCloseMessageWithButton(warningMessage, document); 25 await removeTemporaryExtension(EXTENSION_NAME, document); 26 27 await removeTab(tab); 28 }); 29 30 async function testCloseMessageWithIcon(warningMessage, doc) { 31 const closeIcon = warningMessage.querySelector( 32 ".qa-message-button-close-icon" 33 ); 34 ok(!!closeIcon, "The warning message has a close icon"); 35 36 info("Closing the message and waiting for it to disappear"); 37 closeIcon.click(); 38 39 const target = findDebugTargetByText(EXTENSION_NAME, doc); 40 await waitUntil(() => target.querySelector(".qa-message") === null); 41 } 42 43 async function testCloseMessageWithButton(warningMessage, doc) { 44 const closeButton = warningMessage.querySelector( 45 ".qa-message-button-close-button" 46 ); 47 ok(!!closeButton, "The warning message has a close button"); 48 49 info("Click on the button and wait for the message to disappear"); 50 EventUtils.synthesizeMouse(closeButton, 1, 1, {}, doc.defaultView); 51 52 const target = findDebugTargetByText(EXTENSION_NAME, doc); 53 await waitUntil(() => target.querySelector(".qa-message") === null); 54 } 55 56 async function installExtensionWithWarning(doc) { 57 await pushPref("extensions.webextensions.warnings-as-errors", false); 58 await installTemporaryExtensionFromXPI( 59 { 60 id: EXTENSION_ID, 61 name: EXTENSION_NAME, 62 extraProperties: { 63 // This property is not expected in the manifest and should trigger a warning! 64 wrongProperty: {}, 65 }, 66 }, 67 doc 68 ); 69 await SpecialPowers.popPrefEnv(); 70 71 info("Wait until a debug target item appears"); 72 await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, doc)); 73 74 const target = findDebugTargetByText(EXTENSION_NAME, doc); 75 const warningMessage = target.querySelector(".qa-message"); 76 ok( 77 !!warningMessage, 78 "A warning message is displayed for the installed addon" 79 ); 80 81 return warningMessage; 82 }