Commit d18ce947 authored by Alexandre Poirot's avatar Alexandre Poirot
Browse files

Bug 1757937b - [devtools] Assert limited debugging of asm.js code before reloading the page. r=bomsy

parent 9fd67f43
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -21,9 +21,15 @@ prefs =
  # rejection).
  dom.ipc.processPrelaunch.enabled=false

# Integration tests:
[browser_dbg-integration-reloading-compressed-sourcemaps.js]
[browser_dbg-integration-reloading-uncompressed-sourcemaps.js]
[browser_dbg-asm.js]

# Feature tests:
[browser_dbg-features-asm.js]
[browser_dbg-features-source-text-content.js]

# Other tests:
[browser_dbg-asyncstacks.js]
[browser_dbg-audiocontext.js]
[browser_dbg-async-stepping.js]
@@ -99,7 +105,6 @@ skip-if = debug # Window leaks: bug 1575332
[browser_dbg-expressions-thread.js]
skip-if = !fission # threads panel only shows remote frame when fission is enabled.
[browser_dbg-expressions-watch.js]
[browser_dbg-features-source-text-content.js]
[browser_dbg-fission-frame-breakpoint.js]
[browser_dbg-fission-frame-pause-exceptions.js]
[browser_dbg-fission-frame-sources.js]
+0 −28
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

"use strict";

add_task(async function() {
  const dbg = await initDebugger("doc-asm.html");
  await reload(dbg);

  // After reload() we are getting getSources notifiction for old sources,
  // using the debugger statement to really stop are reloaded page.
  await waitForPaused(dbg);
  await resume(dbg);

  await waitForSources(dbg, "doc-asm.html", "asm.js");

  // Make sure sources appear.
  is(findAllElements(dbg, "sourceNodes").length, 3);

  await selectSource(dbg, "asm.js");

  await addBreakpoint(dbg, "asm.js", 7);
  invokeInTab("runAsm");

  await waitForPaused(dbg);
  assertPausedAtSourceAndLine(dbg, findSource(dbg, "asm.js").id, 7);
});
+92 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/**
 * This test covers all specifics of debugging ASM.js files.
 *
 * ASM.js is a subset of the Javascript syntax.
 * Thanks to these limitations, the JS engine is able to compile this code
 * into machine instructions and execute it faster.
 *
 * When the DevTools are opened, ThreadConfiguration's `observeAsmJS` is set to true,
 * which sets DebuggerAPI's `allowUnobservedAsmJS` to false,
 * which disables the compilation of ASM.js files and make them run as regular JS code.
 * Thus, allowing to debug them as regular JS code.
 *
 * This behavior introduces some limitations when opening the debugger against
 * and already loaded page. The ASM.js file won't be debuggable.
 */

"use strict";

add_task(async function() {
  // Load the test page before opening the debugger
  // and also force a GC before opening the debugger
  // so that ASM.js is fully garbaged collected.
  // Otherwise on debug builds, the thread actor is able to intermittently
  // retrieve the ASM.js sources and retrieve the breakable lines.
  const tab = await addTab(EXAMPLE_URL + "doc-asm.html");
  await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
    Cu.forceGC();
  });
  const toolbox = await openToolboxForTab(tab, "jsdebugger");
  const dbg = createDebuggerContext(toolbox);

  // There is the legit and the spurious wasm source (see following comment)
  await waitForSourcesInSourceTree(dbg, ["doc-asm.html", "asm.js", "asm.js"]);
  is(dbg.selectors.getSourceCount(), 3, "There are only three sources");

  const legitSource = findSource(dbg, EXAMPLE_URL + "asm.js");
  ok(
    legitSource.url.startsWith("https://"),
    "We got the legit source that works, not the spurious WASM one"
  );
  is(legitSource.isWasm, false, "ASM.js sources are *not* flagged as WASM");

  // XXX Bug 1759573 - There is a spurious wasm source reported which is broken
  // and ideally shouldn't exists at all in UI.
  // The Thread Actor is notified by the Debugger API about a WASM
  // source when calling Debugger.findSources in ThreadActor.addAllSources.
  const wasmUrl = "wasm:" + legitSource.url;
  ok(
    sourceExists(dbg, wasmUrl),
    `There is a spurious wasm:// source displayed: ${wasmUrl}`
  );

  await selectSource(dbg, legitSource);

  assertTextContentOnLine(dbg, 7, "return 1 | 0;");

  info(
    "Before reloading, ThreadConfiguration's 'observedAsmJS' was false while the page was loading"
  );
  info(
    "So that we miss info about the ASM sources and lines are not breakables"
  );
  assertLineIsBreakable(dbg, legitSource.url, 7, false);

  info("Reload and assert that ASM.js file are then debuggable");
  await reload(dbg, "doc-asm.html", "asm.js");

  info("After reloading, ASM lines are breakable");
  // Ensure selecting the source before asserting breakable lines
  // otherwise the gutter may not be yet updated
  await selectSource(dbg, "asm.js");
  assertLineIsBreakable(dbg, legitSource.url, 7, true);

  await waitForSourcesInSourceTree(dbg, ["doc-asm.html", "asm.js"]);
  is(dbg.selectors.getSourceCount(), 2, "There is only the two sources");

  assertTextContentOnLine(dbg, 7, "return 1 | 0;");

  await addBreakpoint(dbg, "asm.js", 7);
  invokeInTab("runAsm");

  await waitForPaused(dbg);
  assertPausedAtSourceAndLine(dbg, findSource(dbg, "asm.js").id, 7);
  await assertBreakpoint(dbg, 7);

  await removeBreakpoint(dbg, findSource(dbg, "asm.js").id, 7);
  await resume(dbg);
});
+12 −1
Original line number Diff line number Diff line
@@ -2,7 +2,18 @@
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Test Source Text content fetching
/**
 * This test focus on asserting the source content displayed in CodeMirror
 * when we open a source from the SourceTree (or by any other means).
 *
 * The source content is being fetched from the server only on-demand.
 * The main shortcoming is about sources being GC-ed. This only happens
 * when we open the debugger on an already loaded page.
 * When we (re)load a page while the debugger is opened, sources are never GC-ed.
 * There are also specifics related to HTML page having inline scripts.
 * Also, as this data is fetched on-demand, there is a loading prompt
 * being displayed while the source is being fetched from the server.
 */

"use strict";

+0 −1
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
    function runAsm() {
      console.log(asmjs.f());
    }
    debugger; // see browser_dbg-asm.js reload() comment
    </script>
  </head>