Skip to content

Commit

Permalink
Bug 1538632 - Add a test for the deprecation message in WebIDE;r=daisuke
Browse files Browse the repository at this point in the history
Depends on D26085

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
juliandescottes committed Apr 10, 2019
1 parent 7abb2d6 commit 43bf250
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
1 change: 1 addition & 0 deletions devtools/client/webide/test/chrome.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ skip-if = (os == "linux") # Bug 1024734
[test_runtime.html]
[test_manifestUpdate.html]
[test_addons.html]
[test_deprecation_message.html]
[test_device_runtime.html]
[test_autoconnect_runtime.html]
[test_autoselect_project.html]
Expand Down
18 changes: 17 additions & 1 deletion devtools/client/webide/test/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.webide.busyTimeout");
Services.prefs.clearUserPref("devtools.webide.lastSelectedProject");
Services.prefs.clearUserPref("devtools.webide.lastConnectedRuntime");
Services.prefs.clearUserPref("devtools.webide.showDeprecationMessage");
});

var openWebIDE = async function(autoInstallAddons) {
var openWebIDE = async function({ autoInstallAddons, showDeprecationMessage } = {}) {
info("opening WebIDE");

Services.prefs.setBoolPref("devtools.webide.autoinstallADBExtension", !!autoInstallAddons);
Services.prefs.setBoolPref("devtools.webide.showDeprecationMessage", !!showDeprecationMessage);

const win = Services.ww.openWindow(null, "chrome://webide/content/", "webide",
"chrome,centerscreen,resizable", null);
Expand Down Expand Up @@ -220,3 +222,17 @@ function waitForConnectionChange(expectedState, count = 1) {
DebuggerServer.on("connectionchange", onConnectionChange);
});
}

/**
* Copied from shared-head.js.
*/
function waitUntil(predicate, interval = 100) {
if (predicate()) {
return Promise.resolve(true);
}
return new Promise(resolve => {
setTimeout(function() {
waitUntil(predicate, interval).then(() => resolve(true));
}, interval);
});
}
4 changes: 3 additions & 1 deletion devtools/client/webide/test/test_addons.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
(async function() {
ok(!isAdbAddonInstalled(), "ADB extension not installed");

const win = await openWebIDE(true);
const win = await openWebIDE({
autoInstallAddons: true,
});

// ADB is installed asynchronously after starting WebIDE.
while (!isAdbAddonInstalled()) {
Expand Down
83 changes: 83 additions & 0 deletions devtools/client/webide/test/test_deprecation_message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>

<html>

<head>
<meta charset="utf8">
<title></title>

<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript" src="head.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>

<body>

<script type="application/javascript">
window.onload = function() {
SimpleTest.waitForExplicitFinish();

async function testWithMessageDisabled() {
info("Open WebIDE with the showDeprecationMessage preference set to FALSE");
const win = await openWebIDE({
showDeprecationMessage: false,
});

const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
await gDevToolsBrowser.isWebIDEInitialized.promise;
ok(true, "WebIDE was initialized");

info("Check if the deprecation message is hidden");
const nbox = win.UI.deprecationBox;
const deprecationMessage = nbox.getNotificationWithValue("webide:deprecationnotification");
ok(!deprecationMessage, "The deprecation message is hidden");

await closeWebIDE(win);
}

async function testWithMessageEnabled() {
info("Open WebIDE with the showDeprecationMessage preference set to TRUE");
const win = await openWebIDE({
showDeprecationMessage: true,
});

const {gDevToolsBrowser} = require("devtools/client/framework/devtools-browser");
await gDevToolsBrowser.isWebIDEInitialized.promise;
ok(true, "WebIDE was initialized");

info("Check if the deprecation message is displayed");
const nbox = win.UI.deprecationBox;
const deprecationMessage = nbox.getNotificationWithValue("webide:deprecationnotification");
ok(!!deprecationMessage, "The deprecation message is displayed");

info("Check if a button is displayed in the notification box");
// Note: `notification-button` is a hardcoded className added by the XUL
// notificationbox widget and we cannot set custom classnames.
const button = nbox.stack.querySelector(".notification-button");
ok(!!button, "The button to open about:debugging is displayed");
button.click();

info("Wait until the about:debugging tab is selected in the main window");
const mainWindow = Services.wm.getMostRecentWindow("navigator:browser");
await waitUntil(() => {
const contentWindow = mainWindow.gBrowser.selectedBrowser.contentWindow;
return contentWindow.location.href.startsWith("about:debugging");
});

info("Remove the about:debugging tab");
await removeTab(mainWindow.gBrowser.selectedTab, mainWindow);

await closeWebIDE(win);
}

(async function() {
await testWithMessageDisabled();
await testWithMessageEnabled();

SimpleTest.finish();
})();
};
</script>
</body>
</html>

0 comments on commit 43bf250

Please sign in to comment.