fune/devtools/client/webide/test/test_runtime.html
Mark Banner d226fcc86a Bug 1453383 - Enable ESLint for devtools/client/{webaudioeditor,webide}/. r=jdescottes
MozReview-Commit-ID: Gm77Z0T3oJq

--HG--
extra : rebase_source : 9a23baa102558d30302baf5044da207b7d79f3b6
2018-04-11 16:10:35 +01:00

200 lines
6.4 KiB
HTML

<!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();
let win;
SimpleTest.registerCleanupFunction(() => {
(async function() {
if (win) {
await closeWebIDE(win);
}
DebuggerServer.destroy();
await removeAllProjects();
})();
});
(async function() {
function isPlayActive() {
return !win.document.querySelector("#cmd_play").hasAttribute("disabled");
}
function isStopActive() {
return !win.document.querySelector("#cmd_stop").hasAttribute("disabled");
}
DebuggerServer.init();
DebuggerServer.registerAllActors();
win = await openWebIDE();
let docRuntime = getRuntimeDocument(win);
let docProject = getProjectDocument(win);
let winProject = getProjectWindow(win);
let packagedAppLocation = getTestFilePath("app");
let onValidated = waitForUpdate(win, "project-validated");
let onDetails = waitForUpdate(win, "details");
await winProject.projectList.importPackagedApp(packagedAppLocation);
await onValidated;
await onDetails;
win.AppManager.runtimeList.usb.push({
connect: function(connection) {
is(connection, win.AppManager.connection, "connection is valid");
connection.host = null; // force connectPipe
connection.connect();
return Promise.resolve();
},
get name() {
return "fakeRuntime";
}
});
win.AppManager.runtimeList.usb.push({
connect: function(connection) {
return new Promise(() => {});
},
get name() {
return "infiniteRuntime";
}
});
win.AppManager.runtimeList.usb.push({
connect: function(connection) {
return new Promise(() => {});
},
prolongedConnection: true,
get name() {
return "prolongedRuntime";
}
});
win.AppManager.update("runtime-list");
let panelNode = docRuntime.querySelector("#runtime-panel");
let items = panelNode.querySelectorAll(".runtime-panel-item-usb");
is(items.length, 3, "Found 3 runtime buttons");
let connectionsChanged = waitForConnectionChange("opened", 2);
items[0].click();
ok(win.document.querySelector("window").className, "busy", "UI is busy");
await win.UI._busyPromise;
await connectionsChanged;
is(Object.keys(DebuggerServer._connections).length, 2, "Connected");
await waitForUpdate(win, "runtime-global-actors");
// Play button always disabled now, webapps actor removed
ok(!isPlayActive(), "play button is disabled");
ok(!isStopActive(), "stop button is disabled");
let oldProject = win.AppManager.selectedProject;
win.AppManager.selectedProject = null;
await nextTick();
ok(!isPlayActive(), "play button is disabled");
ok(!isStopActive(), "stop button is disabled");
win.AppManager._selectedProject = oldProject;
win.UI.updateCommands();
await nextTick();
ok(!isPlayActive(), "play button is enabled");
ok(!isStopActive(), "stop button is disabled");
connectionsChanged = waitForConnectionChange("closed", 2);
await win.Cmds.disconnectRuntime();
await connectionsChanged;
is(Object.keys(DebuggerServer._connections).length, 0, "Disconnected");
ok(win.AppManager.selectedProject, "A project is still selected");
ok(!isPlayActive(), "play button is disabled");
ok(!isStopActive(), "stop button is disabled");
connectionsChanged = waitForConnectionChange("opened", 2);
docRuntime.querySelectorAll(".runtime-panel-item-other")[1].click();
await waitForUpdate(win, "runtime-targets");
await connectionsChanged;
is(Object.keys(DebuggerServer._connections).length, 2, "Locally connected");
ok(win.AppManager.isMainProcessDebuggable(), "Main process available");
// Select main process
SimpleTest.executeSoon(() => {
docProject.querySelectorAll("#project-panel-runtimeapps .panel-item")[0].click();
});
await waitForUpdate(win, "project");
// Toolbox opens automatically for main process / runtime apps
ok(win.UI.toolboxPromise, "Toolbox promise exists");
await win.UI.toolboxPromise;
await win.Cmds.disconnectRuntime();
Services.prefs.setIntPref("devtools.webide.busyTimeout", 100);
// Click the infinite runtime
items[1].click();
ok(win.document.querySelector("window").className, "busy", "UI is busy");
// Wait for error message since connection never completes
await new Promise(resolve => {
win.UI.reportError = errorName => {
if (errorName === "error_operationTimeout") {
resolve();
}
};
});
// Click the prolonged runtime
items[2].click();
ok(win.document.querySelector("window").className, "busy", "UI is busy");
// Check for unexpected error message since this is prolonged
let noErrorDeferred = new Promise((resolve, reject) => {
win.UI.reportError = errorName => {
if (errorName === "error_operationTimeout") {
reject();
}
};
setTimeout(() => {
resolve();
}, 1000);
});
await noErrorDeferred;
SimpleTest.finish();
})();
};
</script>
</body>
</html>