Bug 670002 - Tests for source maps in the web console w/ performance issues. r=jsantell
☠☠ backed out by 0b9ec2488c89 ☠ ☠
authorJaideep Bhoosreddy <jaideepb@buffalo.edu>
Tue, 19 Jul 2016 14:42:00 -0400
changeset 330924 c6a1177a17e4cb0a3b0fc81a7d1e82de6d04e42a
parent 330923 aab8baf2c5f54cf16b69b197094719fc0f0eae23
child 330925 a6c528c3fe72fcd5d2959c08d5163a1e48276433
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs670002
milestone50.0a1
Bug 670002 - Tests for source maps in the web console w/ performance issues. r=jsantell
devtools/client/framework/test/browser.ini
devtools/client/framework/test/browser_source-location-01.js
devtools/client/framework/test/browser_source-location-02.js
devtools/client/framework/test/browser_source_map-01.js
devtools/client/framework/test/browser_source_map-02.js
devtools/client/framework/test/code_binary_search.coffee
devtools/client/framework/test/code_binary_search.js
devtools/client/framework/test/code_binary_search.map
devtools/client/framework/test/doc_empty-tab-01.html
--- a/devtools/client/framework/test/browser.ini
+++ b/devtools/client/framework/test/browser.ini
@@ -3,18 +3,22 @@ tags = devtools
 subsuite = devtools
 support-files =
   browser_toolbox_options_disable_js.html
   browser_toolbox_options_disable_js_iframe.html
   browser_toolbox_options_disable_cache.sjs
   browser_toolbox_sidebar_tool.xul
   browser_toolbox_window_title_changes_page.html
   browser_toolbox_window_title_frame_select_page.html
+  code_binary_search.coffee
+  code_binary_search.js
+  code_binary_search.map
   code_math.js
   code_ugly.js
+  doc_empty-tab-01.html
   head.js
   shared-head.js
   shared-redux-head.js
   helper_disable_cache.js
   doc_theme.css
   doc_viewsource.html
   browser_toolbox_options_enable_serviceworkers_testing_frame_script.js
   browser_toolbox_options_enable_serviceworkers_testing.html
@@ -26,18 +30,18 @@ support-files =
 [browser_devtools_api_destroy.js]
 [browser_dynamic_tool_enabling.js]
 [browser_ignore_toolbox_network_requests.js]
 [browser_keybindings_01.js]
 [browser_keybindings_02.js]
 [browser_keybindings_03.js]
 [browser_menu_api.js]
 [browser_new_activation_workflow.js]
-[browser_source-location-01.js]
-[browser_source-location-02.js]
+[browser_source_map-01.js]
+[browser_source_map-02.js]
 [browser_target_from_url.js]
 [browser_target_events.js]
 [browser_target_remote.js]
 [browser_target_support.js]
 [browser_toolbox_custom_host.js]
 [browser_toolbox_dynamic_registration.js]
 [browser_toolbox_getpanelwhenready.js]
 [browser_toolbox_highlight.js]
rename from devtools/client/framework/test/browser_source-location-01.js
rename to devtools/client/framework/test/browser_source_map-01.js
--- a/devtools/client/framework/test/browser_source-location-01.js
+++ b/devtools/client/framework/test/browser_source_map-01.js
@@ -1,66 +1,65 @@
 /* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
+ 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");
 
 /**
- * Tests the SourceMapController updates generated sources when source maps
+ * 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.
  */
 
 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 JS_URL = `${DEBUGGER_ROOT}code_binary_search.js`;
-const COFFEE_URL = `${DEBUGGER_ROOT}code_binary_search.coffee`;
-const { SourceLocationController } = require("devtools/client/framework/source-location");
+const JS_URL = `${URL_ROOT}code_binary_search.js`;
+const COFFEE_URL = `${URL_ROOT}code_binary_search.coffee`;
+const { SourceMapService } = require("devtools/client/framework/source-map-service");
 
 add_task(function* () {
-  let toolbox = yield openNewTabAndToolbox(PAGE_URL, "jsdebugger");
+  const toolbox = yield openNewTabAndToolbox(PAGE_URL, "jsdebugger");
 
-  let controller = new SourceLocationController(toolbox.target);
+  const service = new SourceMapService(toolbox.target);
 
-  let aggregator = [];
+  const aggregator = [];
 
-  function onUpdate(oldLoc, newLoc) {
+  function onUpdate(e, oldLoc, newLoc) {
     if (oldLoc.line === 6) {
       checkLoc1(oldLoc, newLoc);
     } else if (oldLoc.line === 8) {
       checkLoc2(oldLoc, newLoc);
     } else if (oldLoc.line === 2) {
       checkLoc3(oldLoc, newLoc);
     } else {
       throw new Error(`Unexpected location update: ${JSON.stringify(oldLoc)}`);
     }
     aggregator.push(newLoc);
   }
 
   let loc1 = { url: JS_URL, line: 6 };
   let loc2 = { url: JS_URL, line: 8, column: 3 };
-  let loc3 = { url: COFFEE_URL, line: 2, column: 0 };
 
-  controller.bindLocation(loc1, onUpdate);
-  controller.bindLocation(loc2, onUpdate);
-  controller.bindLocation(loc3, onUpdate);
+  service.subscribe(loc1, onUpdate);
+  service.subscribe(loc2, onUpdate);
 
   // Inject JS script
+  let sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_binary_search");
   yield createScript(JS_URL);
+  yield sourceShown;
 
-  yield waitUntil(() => aggregator.length === 3);
+  yield waitUntil(() => aggregator.length === 2);
 
   ok(aggregator.find(i => i.url === COFFEE_URL && i.line === 4), "found first updated location");
   ok(aggregator.find(i => i.url === COFFEE_URL && i.line === 6), "found second updated location");
-  ok(aggregator.find(i => i.url === COFFEE_URL && i.line === 2), "found third updated location");
 
   yield toolbox.destroy();
   gBrowser.removeCurrentTab();
   finish();
 });
 
 function checkLoc1(oldLoc, newLoc) {
   is(oldLoc.line, 6, "Correct line for JS:6");
@@ -75,28 +74,37 @@ 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.url, COFFEE_URL, "Correct url for JS:8:3 -> COFFEE");
 }
 
-function checkLoc3(oldLoc, newLoc) {
-  is(oldLoc.line, 2, "Correct line for COFFEE:2:0");
-  is(oldLoc.column, 0, "Correct column for COFFEE:2:0");
-  is(oldLoc.url, COFFEE_URL, "Correct url for COFFEE:2:0");
-  is(newLoc.line, 2, "Correct line for COFFEE:2:0 -> COFFEE");
-  is(newLoc.column, 0, "Correct column for COFFEE:2:0 -> COFFEE");
-  is(newLoc.url, COFFEE_URL, "Correct url for COFFEE:2:0 -> 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;
+}
rename from devtools/client/framework/test/browser_source-location-02.js
rename to devtools/client/framework/test/browser_source_map-02.js
--- a/devtools/client/framework/test/browser_source-location-02.js
+++ b/devtools/client/framework/test/browser_source_map-02.js
@@ -1,63 +1,63 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
+ http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
- * Tests the SourceLocationController updates generated sources when pretty printing
+ * Tests the SourceMapService updates generated sources when pretty printing
  * and un pretty printing.
  */
 
 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 JS_URL = `${URL_ROOT}code_ugly.js`;
-const { SourceLocationController } = require("devtools/client/framework/source-location");
+const { SourceMapService } = require("devtools/client/framework/source-map-service");
 
 add_task(function* () {
   let toolbox = yield openNewTabAndToolbox(PAGE_URL, "jsdebugger");
 
-  let controller = new SourceLocationController(toolbox.target);
+  let service = new SourceMapService(toolbox.target);
 
   let checkedPretty = false;
   let checkedUnpretty = false;
 
-  function onUpdate(oldLoc, newLoc) {
+  function onUpdate(e, oldLoc, newLoc) {
     if (oldLoc.line === 3) {
       checkPrettified(oldLoc, newLoc);
       checkedPretty = true;
     } else if (oldLoc.line === 9) {
       checkUnprettified(oldLoc, newLoc);
       checkedUnpretty = true;
     } else {
       throw new Error(`Unexpected location update: ${JSON.stringify(oldLoc)}`);
     }
   }
-
-  controller.bindLocation({ url: JS_URL, line: 3 }, onUpdate);
+  const loc1 = { url: JS_URL, line: 3 };
+  service.subscribe(loc1, onUpdate);
 
   // Inject JS script
   let sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_ugly.js");
   yield createScript(JS_URL);
   yield sourceShown;
 
   let ppButton = toolbox.getCurrentPanel().panelWin.document.getElementById("pretty-print");
   sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_ugly.js");
   ppButton.click();
   yield sourceShown;
   yield waitUntil(() => checkedPretty);
 
   // TODO check unprettified change once bug 1177446 fixed
-  /*
-  sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_ugly.js");
-  ppButton.click();
-  yield sourceShown;
-  yield waitUntil(() => checkedUnpretty);
-  */
+  // info("Testing un-pretty printing.");
+  // sourceShown = waitForSourceShown(toolbox.getCurrentPanel(), "code_ugly.js");
+  // ppButton.click();
+  // yield sourceShown;
+  // yield waitUntil(() => checkedUnpretty);
+
 
   yield toolbox.destroy();
   gBrowser.removeCurrentTab();
   finish();
 });
 
 function checkPrettified(oldLoc, newLoc) {
   is(oldLoc.line, 3, "Correct line for JS:3");
copy from devtools/client/debugger/test/mochitest/code_binary_search.coffee
copy to devtools/client/framework/test/code_binary_search.coffee
copy from devtools/client/debugger/test/mochitest/code_binary_search.js
copy to devtools/client/framework/test/code_binary_search.js
copy from devtools/client/debugger/test/mochitest/code_binary_search.map
copy to devtools/client/framework/test/code_binary_search.map
copy from devtools/client/debugger/test/mochitest/doc_empty-tab-01.html
copy to devtools/client/framework/test/doc_empty-tab-01.html