Bug 1241958 - Add test for windowless workers, r=jlast.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 24 Dec 2018 08:40:04 -1000
changeset 451907 0621040311260830908b35fbeebd42041911c531
parent 451906 5327afef99b0ab315a0ba93c0ceb0caab565d857
child 451908 47d3977ee67ef6e2dbdcc5ce83a159c1c8e886f5
push id35270
push useraiakab@mozilla.com
push dateTue, 25 Dec 2018 09:51:24 +0000
treeherdermozilla-central@47d3977ee67e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1241958
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1241958 - Add test for windowless workers, r=jlast.
devtools/client/debugger/new/test/mochitest/browser.ini
devtools/client/debugger/new/test/mochitest/browser_dbg-windowless-workers.js
devtools/client/debugger/new/test/mochitest/examples/doc-windowless-workers.html
devtools/client/debugger/new/test/mochitest/examples/simple-worker.js
devtools/client/debugger/new/test/mochitest/helpers.js
--- a/devtools/client/debugger/new/test/mochitest/browser.ini
+++ b/devtools/client/debugger/new/test/mochitest/browser.ini
@@ -646,16 +646,18 @@ support-files =
   examples/simple2.js
   examples/simple3.js
   examples/frames.js
   examples/pause-points.js
   examples/script-mutate.js
   examples/script-switching-02.js
   examples/script-switching-01.js
   examples/times2.js
+  examples/doc-windowless-workers.html
+  examples/simple-worker.js
   examples/doc_rr_basic.html
   examples/doc_rr_continuous.html
   examples/doc_rr_logs.html
   examples/doc_rr_recovery.html
   examples/doc_rr_error.html
 
 [browser_dbg-asm.js]
 [browser_dbg-async-stepping.js]
@@ -759,16 +761,17 @@ skip-if = debug || (verify && (os == 'wi
 skip-if = os == "win"
 [browser_dbg-tabs-pretty-print.js]
 [browser_dbg-tabs-without-urls.js]
 [browser_dbg-toggling-tools.js]
 [browser_dbg-react-app.js]
 skip-if = os == "win"
 [browser_dbg-wasm-sourcemaps.js]
 skip-if = true
+[browser_dbg-windowless-workers.js]
 [browser_dbg_rr_breakpoints-01.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-02.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-03.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-04.js]
 skip-if = os != "mac" || debug || !nightly_build
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-windowless-workers.js
@@ -0,0 +1,45 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test basic windowless worker functionality: the main thread and worker can be
+// separately controlled from the same debugger.
+add_task(async function() {
+  await pushPref("devtools.debugger.features.windowless-workers", true);
+
+  const dbg = await initDebugger("doc-windowless-workers.html");
+  const mainThread = dbg.toolbox.threadClient.actor;
+
+  const workers = await getWorkers(dbg);
+  ok(workers.length == 1, "Got one worker");
+  const workerThread = workers[0].actor;
+
+  const mainThreadSource = findSource(dbg, "doc-windowless-workers.html");
+  const workerSource = findSource(dbg, "simple-worker.js");
+
+  assertNotPaused(dbg);
+
+  await dbg.actions.breakOnNext();
+  await waitForPaused(dbg, "doc-windowless-workers.html");
+
+  // We should be paused at the timer in doc-windowless-workers.html
+  assertPausedAtSourceAndLine(dbg, mainThreadSource.id, 9);
+
+  await dbg.actions.selectThread(workerThread);
+  assertNotPaused(dbg);
+
+  await dbg.actions.breakOnNext();
+  await waitForPaused(dbg, "simple-worker.js");
+
+  // We should be paused at the timer in simple-worker.js
+  assertPausedAtSourceAndLine(dbg, workerSource.id, 3);
+
+  await stepOver(dbg);
+  assertPausedAtSourceAndLine(dbg, workerSource.id, 4);
+
+  await dbg.actions.selectThread(mainThread);
+
+  await stepOver(dbg);
+  assertPausedAtSourceAndLine(dbg, mainThreadSource.id, 10);
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/examples/doc-windowless-workers.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+
+<script>
+var worker = new Worker("simple-worker.js");
+
+var count = 0;
+function timer() {
+  var n = ++count;
+  console.log("MAIN THREAD SAYS HELLO! " + n);
+}
+
+setInterval(timer, 1000);
+</script>
+
+<body>
+Hello World!
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/examples/simple-worker.js
@@ -0,0 +1,7 @@
+var count = 0;
+function timer() {
+  var n = ++count;
+  console.log("WORKER SAYS HELLO! " + n);
+}
+
+setInterval(timer, 1000);
--- a/devtools/client/debugger/new/test/mochitest/helpers.js
+++ b/devtools/client/debugger/new/test/mochitest/helpers.js
@@ -400,16 +400,44 @@ function assertHighlightLocation(dbg, so
 function isPaused(dbg) {
   const {
     selectors: { isPaused },
     getState
   } = dbg;
   return !!isPaused(getState());
 }
 
+// Make sure the debugger is paused at a certain source ID and line.
+function assertPausedAtSourceAndLine(dbg, expectedSourceId, expectedLine) {
+  assertPaused(dbg);
+
+  const {
+    selectors: { getWorkers, getFrames },
+    getState
+  } = dbg;
+
+  const frames = getFrames(getState());
+  ok(frames.length >= 1, "Got at least one frame");
+  const { sourceId, line } = frames[0].location;
+  ok(sourceId == expectedSourceId, "Frame has correct source");
+  ok(line == expectedLine, "Frame has correct line");
+}
+
+// Get any workers associated with the debugger.
+async function getWorkers(dbg) {
+  await dbg.actions.updateWorkers();
+
+  const {
+    selectors: { getWorkers },
+    getState
+  } = dbg;
+
+  return getWorkers(getState()).toJS();
+}
+
 async function waitForLoadedScopes(dbg) {
   const scopes = await waitForElement(dbg, "scopes");
   // Since scopes auto-expand, we can assume they are loaded when there is a tree node
   // with the aria-level attribute equal to "2".
   await waitUntil(() => scopes.querySelector(`.tree-node[aria-level="2"]`));
 }
 
 /**