Bug 1365371 - change source map test not to require old debugger; r=jryans
authorTom Tromey <tom@tromey.com>
Tue, 16 May 2017 13:27:04 -0600
changeset 409115 7c0bd165daf4943618ee6eac5b6344c1fc22af5c
parent 409114 82edbfe72c47d736a604612fab8d7ebc417e6105
child 409116 15a0bebc29aa183902a5135560e6653a38aaafaf
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1365371
milestone55.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 1365371 - change source map test not to require old debugger; r=jryans MozReview-Commit-ID: 8SckurtKlHZ
devtools/client/framework/test/browser_source_map-01.js
devtools/client/framework/test/head.js
--- a/devtools/client/framework/test/browser_source_map-01.js
+++ b/devtools/client/framework/test/browser_source_map-01.js
@@ -1,43 +1,32 @@
 /* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */
 
-// Whitelisting this test.
-// As part of bug 1077403, the leaking uncaught rejections should be fixed.
-thisTestLeaksUncaughtRejectionsAndShouldBeFixed("[object Object]");
-thisTestLeaksUncaughtRejectionsAndShouldBeFixed(
-  "TypeError: this.transport is null");
+"use strict";
 
 /**
  * Tests the SourceMapService updates generated sources when source maps
  * are subsequently found. Also checks when no column is provided, and
  * when tagging an already source mapped location initially.
  */
 
-// Force the old debugger UI since it's directly used (see Bug 1301705)
-Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false);
-registerCleanupFunction(function* () {
-  Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend");
-});
-
-const DEBUGGER_ROOT = "http://example.com/browser/devtools/client/debugger/test/mochitest/";
 // Empty page
-const PAGE_URL = `${DEBUGGER_ROOT}doc_empty-tab-01.html`;
+const PAGE_URL = `${URL_ROOT}doc_empty-tab-01.html`;
 const JS_URL = `${URL_ROOT}code_binary_search.js`;
 const COFFEE_URL = `${URL_ROOT}code_binary_search.coffee`;
 
 add_task(function* () {
   const toolbox = yield openNewTabAndToolbox(PAGE_URL, "jsdebugger");
   const service = toolbox.sourceMapURLService;
 
   // Inject JS script
-  let sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_binary_search");
+  let sourceSeen = waitForSourceLoad(toolbox, JS_URL);
   yield createScript(JS_URL);
-  yield sourceShown;
+  yield sourceSeen;
 
   let loc1 = { url: JS_URL, line: 6 };
   let newLoc1 = yield service.originalPositionFor(loc1.url, loc1.line);
   checkLoc1(loc1, newLoc1);
 
   let loc2 = { url: JS_URL, line: 8, column: 3 };
   let newLoc2 = yield service.originalPositionFor(loc2.url, loc2.line, loc2.column);
   checkLoc2(loc2, newLoc2);
@@ -59,38 +48,8 @@ function checkLoc1(oldLoc, newLoc) {
 function checkLoc2(oldLoc, newLoc) {
   is(oldLoc.line, 8, "Correct line for JS:8:3");
   is(oldLoc.column, 3, "Correct column for JS:8:3");
   is(oldLoc.url, JS_URL, "Correct url for JS:8:3");
   is(newLoc.line, 6, "Correct line for JS:8:3 -> COFFEE");
   is(newLoc.column, 10, "Correct column for JS:8:3 -> COFFEE");
   is(newLoc.sourceUrl, COFFEE_URL, "Correct url for JS:8:3 -> COFFEE");
 }
-
-function createScript(url) {
-  info(`Creating script: ${url}`);
-  let mm = getFrameScript();
-  let command = `
-    let script = document.createElement("script");
-    script.setAttribute("src", "${url}");
-    document.body.appendChild(script);
-    null;
-  `;
-  return evalInDebuggee(mm, command);
-}
-
-function waitForSourceShown(debuggerPanel, url) {
-  let { panelWin } = debuggerPanel;
-  let deferred = defer();
-
-  info(`Waiting for source ${url} to be shown in the debugger...`);
-  panelWin.on(panelWin.EVENTS.SOURCE_SHOWN, function onSourceShown(_, source) {
-
-    let sourceUrl = source.url || source.generatedUrl;
-    if (sourceUrl.includes(url)) {
-      panelWin.off(panelWin.EVENTS.SOURCE_SHOWN, onSourceShown);
-      info(`Source shown for ${url}`);
-      deferred.resolve(source);
-    }
-  });
-
-  return deferred.promise;
-}
--- a/devtools/client/framework/test/head.js
+++ b/devtools/client/framework/test/head.js
@@ -141,8 +141,50 @@ function checkHostType(toolbox, hostType
   let pref = Services.prefs.getCharPref("devtools.toolbox.host");
   is(pref, hostType, "host pref is " + hostType);
 
   if (previousHostType) {
     is(Services.prefs.getCharPref("devtools.toolbox.previousHost"),
       previousHostType, "The previous host is correct");
   }
 }
+
+/**
+ * Create a new <script> referencing URL.  Return a promise that
+ * resolves when this has happened
+ * @param {String} url
+ *        the url
+ * @return {Promise} a promise that resolves when the element has been created
+ */
+function createScript(url) {
+  info(`Creating script: ${url}`);
+  let mm = getFrameScript();
+  let command = `
+    let script = document.createElement("script");
+    script.setAttribute("src", "${url}");
+    document.body.appendChild(script);
+    null;
+  `;
+  return evalInDebuggee(mm, command);
+}
+
+/**
+ * Wait for the toolbox to notice that a given source is loaded
+ * @param {Toolbox} toolbox
+ * @param {String} url
+ *        the url to wait for
+ * @return {Promise} a promise that is resolved when the source is loaded
+ */
+function waitForSourceLoad(toolbox, url) {
+  info(`Waiting for source ${url} to be available...`);
+  return new Promise(resolve => {
+    let target = toolbox.target;
+
+    function sourceHandler(_, sourceEvent) {
+      if (sourceEvent && sourceEvent.source && sourceEvent.source.url === url) {
+        resolve();
+        target.off("source-updated", sourceHandler);
+      }
+    }
+
+    target.on("source-updated", sourceHandler);
+  });
+}