Bug 1447244 Part 9 - Add test for console links based on source IDs, r=lsmyth.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 16 Jan 2019 12:02:44 -1000
changeset 518733 8891e6a6c18b94f801a5c98b254cf60b9a3915aa
parent 518732 72038435352d512bb17cc12c24c7912667dfac09
child 518734 aa7d1cc3ef70d2da282442deefc0372abc805a80
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)
reviewerslsmyth
bugs1447244
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 1447244 Part 9 - Add test for console links based on source IDs, r=lsmyth.
devtools/client/webconsole/test/mochitest/browser.ini
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/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -72,16 +72,17 @@ support-files =
   test-data.json
   test-data.json^headers^
   test-duplicate-error.html
   test-dynamic-import.html
   test-dynamic-import.js
   test-encoding-ISO-8859-1.html
   test-error.html
   test-eval-in-stackframe.html
+  test-eval-sources.html
   test-exception-stackframe.html
   test-external-script-errors.html
   test-external-script-errors.js
   test-file-location.js
   test-filter.html
   test-for-of.html
   test-iframe-insecure-form-action.html
   test-iframe1.html
@@ -315,16 +316,17 @@ subsuite = clipboard
 [browser_webconsole_document_focus.js]
 [browser_webconsole_duplicate_errors.js]
 [browser_webconsole_error_with_grouped_stack.js]
 [browser_webconsole_error_with_longstring_stack.js]
 [browser_webconsole_error_with_unicode.js]
 [browser_webconsole_errors_after_page_reload.js]
 [browser_webconsole_eval_in_debugger_stackframe.js]
 [browser_webconsole_eval_in_debugger_stackframe2.js]
+[browser_webconsole_eval_sources.js]
 [browser_webconsole_execution_scope.js]
 [browser_webconsole_external_script_errors.js]
 [browser_webconsole_file_uri.js]
 skip-if = true #	Bug 1404382
 [browser_webconsole_filter_by_input.js]
 [browser_webconsole_filter_scroll.js]
 [browser_webconsole_filters.js]
 [browser_webconsole_filters_persist.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_eval_sources.js
@@ -0,0 +1,47 @@
+/* -*- 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 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();
+
+  // I don't know how to make sure the pane has been updated with its stack frames.
+  await waitForTime(100);
+
+  const frame = message.querySelector(".frame");
+  EventUtils.sendMouseEvent({ type: "mousedown" }, frame);
+
+  await once(hud.ui, "source-in-debugger-opened");
+}
+
+// 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);
+
+  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);
+});
--- a/devtools/client/webconsole/test/mochitest/head.js
+++ b/devtools/client/webconsole/test/mochitest/head.js
@@ -334,29 +334,32 @@ function waitForNodeMutation(node, obser
  *
  * @param {Object} hud
  *        The webconsole
  * @param {Object} toolbox
  *        The toolbox
  * @param {String} text
  *        The text to search for.  This should be contained in the
  *        message.  The searching is done with @see findMessage.
+ * @param {boolean} expectUrl
+ *        Whether the URL in the opened source should match the link, or whether
+ *        it is expected to be null.
  */
-async function testOpenInDebugger(hud, toolbox, text) {
+async function testOpenInDebugger(hud, toolbox, text, expectUrl = true) {
   info(`Finding message for open-in-debugger test; text is "${text}"`);
   const messageNode = await waitFor(() => findMessage(hud, text));
   const frameLinkNode = messageNode.querySelector(".message-location .frame-link");
   ok(frameLinkNode, "The message does have a location link");
-  await checkClickOnNode(hud, toolbox, frameLinkNode);
+  await checkClickOnNode(hud, toolbox, frameLinkNode, expectUrl);
 }
 
 /**
  * Helper function for testOpenInDebugger.
  */
-async function checkClickOnNode(hud, toolbox, frameLinkNode) {
+async function checkClickOnNode(hud, toolbox, frameLinkNode, expectUrl) {
   info("checking click on node location");
 
   const url = frameLinkNode.getAttribute("data-url");
   ok(url, `source url found ("${url}")`);
 
   const line = frameLinkNode.getAttribute("data-line");
   ok(line, `source line found ("${line}")`);
 
@@ -371,17 +374,17 @@ async function checkClickOnNode(hud, too
 
   // 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,
-    url,
+    expectUrl ? url : null,
     "expected source url"
   );
 }
 
 /**
  * Returns true if the give node is currently focused.
  */
 function hasFocus(node) {
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/test-eval-sources.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<meta charset=UTF-8>
+<script>
+/* eslint-disable */
+eval("window.foo = function() { console.log('FOO'); }");
+eval("window.bar = function() { throw new Error('BAR') };");
+foo();
+bar();
+</script>