Bug 1531826 Part 4 - Add tests for console/inspector links to eval sources.
authorBrian Hackett <bhackett1024@gmail.com>
Tue, 05 Mar 2019 07:46:37 -1000
changeset 520790 eeeed2bd887078a1b26a3f349d9cd0558b19074e
parent 520789 5def261a4246475d3a7ba1911847fbd78ae790d1
child 520791 a52dffe6d7beee0a0ad9dca59ab504593018d00d
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1531826
milestone67.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 1531826 Part 4 - Add tests for console/inspector links to eval sources.
devtools/client/inspector/markup/test/browser.ini
devtools/client/inspector/markup/test/browser_markup_view-source.js
devtools/client/webconsole/test/mochitest/browser_webconsole_eval_sources.js
devtools/client/webconsole/test/mochitest/head.js
devtools/client/webconsole/test/mochitest/test-eval-sources.html
--- a/devtools/client/inspector/markup/test/browser.ini
+++ b/devtools/client/inspector/markup/test/browser.ini
@@ -231,11 +231,12 @@ subsuite = clipboard
 [browser_markup_textcontent_edit_01.js]
 [browser_markup_textcontent_edit_02.js]
 [browser_markup_toggle_01.js]
 [browser_markup_toggle_02.js]
 [browser_markup_toggle_03.js]
 [browser_markup_toggle_04.js]
 [browser_markup_toggle_closing_tag_line.js]
 [browser_markup_update-on-navigtion.js]
+[browser_markup_view-source.js]
 [browser_markup_void_elements_html.js]
 [browser_markup_void_elements_xhtml.js]
 [browser_markup_whitespace.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/markup/test/browser_markup_view-source.js
@@ -0,0 +1,63 @@
+/* -*- 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/ */
+
+"use strict";
+
+const DOCUMENT_SRC = `
+<body>
+<button id="foo">Button</button>
+<script>
+var script = \`
+  function foo() {
+    console.log('handler');
+  }
+\`;
+eval(script);
+
+var button = document.getElementById("foo");
+button.addEventListener("click", foo, false);
+</script>
+</body>`;
+
+const TEST_URI = "data:text/html;charset=utf-8," + DOCUMENT_SRC;
+
+add_task(async function() {
+  // Test that event handler links go to the right debugger source when it
+  // came from an eval().
+  const { inspector, toolbox } = await openInspectorForURL(TEST_URI);
+
+  const target = await TargetFactory.forTab(gBrowser.selectedTab);
+
+  const nodeFront = await getNodeFront("#foo", inspector);
+  const container = getContainerForNodeFront(nodeFront, inspector);
+
+  const evHolder = container.elt.querySelector(
+    ".inspector-badge.interactive[data-event]");
+
+  evHolder.scrollIntoView();
+  EventUtils.synthesizeMouseAtCenter(evHolder, {},
+    inspector.markup.doc.defaultView);
+
+  const tooltip = inspector.markup.eventDetailsTooltip;
+  await tooltip.once("shown");
+
+  const debuggerIcon = tooltip.panel.querySelector(".event-tooltip-debugger-icon");
+  EventUtils.synthesizeMouse(debuggerIcon, 2, 2, {}, debuggerIcon.ownerGlobal);
+
+  await gDevTools.showToolbox(target, "jsdebugger");
+  const dbg = toolbox.getPanel("jsdebugger");
+
+  let source;
+  await BrowserTestUtils.waitForCondition(() => {
+    source = dbg._selectors.getSelectedSource(dbg._getState());
+    return !!source;
+  }, "loaded source", 100, 20);
+
+  is(
+    source.url,
+    null,
+    "expected no url for eval source"
+  );
+});
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_eval_sources.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_eval_sources.js
@@ -3,21 +3,22 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
                  "test/mochitest/test-eval-sources.html";
 
-async function clickFirstStackElement(hud, message) {
-  const button = message.querySelector(".collapse-button");
-  ok(button, "has button");
-
-  button.click();
+async function clickFirstStackElement(hud, message, needsExpansion) {
+  if (needsExpansion) {
+    const button = message.querySelector(".collapse-button");
+    ok(button, "has button");
+    button.click();
+  }
 
   let frame;
   await waitUntil(() => {
     frame = message.querySelector(".frame");
     return !!frame;
   });
 
   EventUtils.sendMouseEvent({ type: "mousedown" }, frame);
@@ -28,22 +29,36 @@ async function clickFirstStackElement(hu
 // Test that stack/message links in console API and error messages originating
 // from eval code go to a source in the debugger. This should work even when the
 // console is opened first.
 add_task(async function() {
   const hud = await openNewTabAndConsole(TEST_URI);
   const target = await TargetFactory.forTab(gBrowser.selectedTab);
   const toolbox = gDevTools.getToolbox(target);
 
-  const messageNode = await waitFor(() => findMessage(hud, "BAR"));
-  await clickFirstStackElement(hud, messageNode);
+  let messageNode = await waitFor(() => findMessage(hud, "BAR"));
+  await clickFirstStackElement(hud, messageNode, true);
 
   const dbg = toolbox.getPanel("jsdebugger");
 
   is(
     dbg._selectors.getSelectedSource(dbg._getState()).url,
     null,
     "expected source url"
   );
 
   await testOpenInDebugger(hud, toolbox, "FOO", false);
   await testOpenInDebugger(hud, toolbox, "BAR", false);
+
+  // Test that links in the API work when the eval source has a sourceURL property
+  // which is not considered to be a valid URL.
+  await testOpenInDebugger(hud, toolbox, "BAZ", false);
+
+  // Test that stacks in console.trace() calls work.
+  messageNode = await waitFor(() => findMessage(hud, "TRACE"));
+  await clickFirstStackElement(hud, messageNode, false);
+
+  is(
+    /my-foo.js/.test(dbg._selectors.getSelectedSource(dbg._getState()).url),
+    true,
+    "expected source url"
+  );
 });
--- a/devtools/client/webconsole/test/mochitest/head.js
+++ b/devtools/client/webconsole/test/mochitest/head.js
@@ -372,21 +372,22 @@ async function checkClickOnNode(hud, too
 
   const dbg = toolbox.getPanel("jsdebugger");
 
   // Wait for the source to finish loading, if it is pending.
   await waitFor(() => {
     return !!dbg._selectors.getSelectedSource(dbg._getState());
   });
 
-  is(
-    dbg._selectors.getSelectedSource(dbg._getState()).url,
-    expectUrl ? url : null,
-    "expected source url"
-  );
+  if (expectUrl) {
+    is(
+      dbg._selectors.getSelectedSource(dbg._getState()).url, url,
+      "expected source url"
+    );
+  }
 }
 
 /**
  * Returns true if the give node is currently focused.
  */
 function hasFocus(node) {
   return node.ownerDocument.activeElement == node
     && node.ownerDocument.hasFocus();
--- a/devtools/client/webconsole/test/mochitest/test-eval-sources.html
+++ b/devtools/client/webconsole/test/mochitest/test-eval-sources.html
@@ -1,9 +1,17 @@
 <!DOCTYPE html>
 <meta charset=UTF-8>
 <script>
 /* eslint-disable */
 eval("window.foo = function() { console.log('FOO'); }");
 eval("window.bar = function() { throw new Error('BAR') };");
+eval(`window.baz = function() {
+        console.log('BAZ');
+        console.trace('TRACE');
+     }
+     //# sourceURL=my-foo.js`);
+
 foo();
+baz();
 bar();
+
 </script>