Bug 1353042 - Get rid of all sdk/tabs and sdk/tabs/utils usage; r=zer0
☠☠ backed out by 1f499580389b ☠ ☠
authorPatrick Brosset <pbrosset@mozilla.com>
Tue, 02 May 2017 16:46:54 +0200
changeset 360063 4c2036f901c1dab4774958fbe51a62737b324923
parent 360062 8818d31a2a397ff86a4b843e11ed0ba31c4c8f3e
child 360064 8649b10a34c18f0e6c57106748750e0a67009d42
push id43203
push userpbrosset@mozilla.com
push dateTue, 23 May 2017 07:33:39 +0000
treeherderautoland@4c2036f901c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszer0
bugs1353042
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 1353042 - Get rid of all sdk/tabs and sdk/tabs/utils usage; r=zer0 Removed obsolete browser_dbg_event-listeners-03/4.js tests (they are for the old debugger, and the new debugger doesn't even support event listeners yet, so no use keeping this test around). Removed getBrowserForTab SDK dependency from command-state.js. Changed the implementation of addTab/removeTab in perf test's tab-utils helper. MozReview-Commit-ID: 7EXJ5K3kaJm
devtools/client/debugger/test/mochitest/browser.ini
devtools/client/debugger/test/mochitest/browser_dbg_break-on-dom-event-03.js
devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-04.js
devtools/client/debugger/test/mochitest/doc_event-listeners-04.html
devtools/client/performance/test/helpers/tab-utils.js
devtools/shared/gcli/command-state.js
--- a/devtools/client/debugger/test/mochitest/browser.ini
+++ b/devtools/client/debugger/test/mochitest/browser.ini
@@ -73,17 +73,16 @@ support-files =
   doc_conditional-breakpoints.html
   doc_domnode-variables.html
   doc_editor-mode.html
   doc_empty-tab-01.html
   doc_empty-tab-02.html
   doc_event-listeners-01.html
   doc_event-listeners-02.html
   doc_event-listeners-03.html
-  doc_event-listeners-04.html
   doc_frame-parameters.html
   doc_function-display-name.html
   doc_function-jump.html
   doc_function-search.html
   doc_global-method-override.html
   doc_iframes.html
   doc_included-script.html
   doc_inline-debugger-statement.html
@@ -177,18 +176,16 @@ skip-if = e10s || true # bug 1113935
 [browser_dbg_break-on-dom-05.js]
 [browser_dbg_break-on-dom-06.js]
 [browser_dbg_break-on-dom-07.js]
 [browser_dbg_break-on-dom-08.js]
 [browser_dbg_break-on-dom-event-01.js]
 skip-if = e10s || os == "mac" || e10s # Bug 895426
 [browser_dbg_break-on-dom-event-02.js]
 skip-if = e10s # TODO
-[browser_dbg_break-on-dom-event-03.js]
-skip-if = e10s # TODO
 [browser_dbg_break-unselected.js]
 [browser_dbg_breakpoints-actual-location.js]
 [browser_dbg_breakpoints-actual-location2.js]
 [browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js]
 skip-if = e10s # Bug 1093535
 [browser_dbg_breakpoints-button-01.js]
 [browser_dbg_breakpoints-button-02.js]
 [browser_dbg_breakpoints-condition-thrown-message.js]
@@ -264,18 +261,16 @@ skip-if = e10s && debug
 [browser_dbg_editor-mode.js]
 skip-if = e10s && debug
 [browser_dbg_event-listeners-01.js]
 skip-if = e10s && debug
 [browser_dbg_event-listeners-02.js]
 skip-if = e10s && debug
 [browser_dbg_event-listeners-03.js]
 skip-if = e10s && debug
-[browser_dbg_event-listeners-04.js]
-skip-if = debug || e10s # debug bug 1142597, e10s bug 1146603.
 [browser_dbg_file-reload.js]
 skip-if = e10s && debug
 [browser_dbg_function-display-name.js]
 skip-if = e10s && debug
 [browser_dbg_global-method-override.js]
 skip-if = e10s && debug
 [browser_dbg_globalactor.js]
 skip-if = e10s # TODO
deleted file mode 100644
--- a/devtools/client/debugger/test/mochitest/browser_dbg_break-on-dom-event-03.js
+++ /dev/null
@@ -1,97 +0,0 @@
-/* -*- 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/ */
-
-/**
- * Tests that the break-on-dom-events request works for load event listeners.
- */
-
-const TAB_URL = EXAMPLE_URL + "doc_event-listeners-04.html";
-
-var gClient, gThreadClient;
-
-function test() {
-  if (!DebuggerServer.initialized) {
-    DebuggerServer.init();
-    DebuggerServer.addBrowserActors();
-  }
-
-  let transport = DebuggerServer.connectPipe();
-  gClient = new DebuggerClient(transport);
-  gClient.connect().then(([aType, aTraits]) => {
-    is(aType, "browser",
-      "Root actor should identify itself as a browser.");
-
-    addTab(TAB_URL)
-      .then(() => attachThreadActorForUrl(gClient, TAB_URL))
-      .then(aThreadClient => gThreadClient = aThreadClient)
-      .then(pauseDebuggee)
-      .then(testBreakOnLoad)
-      .then(() => gClient.close())
-      .then(finish)
-      .then(null, aError => {
-        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
-      });
-  });
-}
-
-function pauseDebuggee() {
-  let deferred = promise.defer();
-
-  gClient.addOneTimeListener("paused", (aEvent, aPacket) => {
-    is(aPacket.type, "paused",
-      "We should now be paused.");
-    is(aPacket.why.type, "debuggerStatement",
-      "The debugger statement was hit.");
-
-    gThreadClient.resume(deferred.resolve);
-  });
-
-  // Spin the event loop before causing the debuggee to pause, to allow
-  // this function to return first.
-  executeSoon(() => triggerButtonClick());
-
-  return deferred.promise;
-}
-
-// Test pause on a load event.
-function testBreakOnLoad() {
-  let deferred = promise.defer();
-
-  // Test calling pauseOnDOMEvents from a running state.
-  gThreadClient.pauseOnDOMEvents(["load"], (aPacket) => {
-    is(aPacket.error, undefined,
-      "The pause-on-load request completed successfully.");
-    let handlers = ["loadHandler"];
-
-    gClient.addListener("paused", function tester(aEvent, aPacket) {
-      is(aPacket.why.type, "pauseOnDOMEvents",
-        "A hidden breakpoint was hit.");
-
-      is(aPacket.frame.where.line, 15, "Found the load event listener.");
-      gClient.removeListener("paused", tester);
-      deferred.resolve();
-
-      gThreadClient.resume(() => triggerButtonClick(handlers.slice(-1)));
-    });
-
-    getTabActorForUrl(gClient, TAB_URL).then(aGrip => {
-      gClient.attachTab(aGrip.actor, (aResponse, aTabClient) => {
-        aTabClient.reload();
-      });
-    });
-  });
-
-  return deferred.promise;
-}
-
-function triggerButtonClick() {
-  let button = content.document.querySelector("button");
-  EventUtils.sendMouseEvent({ type: "click" }, button);
-}
-
-registerCleanupFunction(function () {
-  gClient = null;
-  gThreadClient = null;
-});
deleted file mode 100644
--- a/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-04.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- 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/ */
-
-/**
- * Test that event listeners are properly fetched even if one of the listeners
- * don't have a Debugger.Source object (bug 942899).
- *
- * This test is skipped on debug and e10s builds for following reasons:
- *  - debug: requiring sdk/tabs causes memory leaks when new windows are opened
- *    in tests executed after this one. Bug 1142597.
- *  - e10s: tab.attach is not e10s safe and only works when add-on compatibility
- *    shims are in place. Bug 1146603.
- */
-
-const TAB_URL = EXAMPLE_URL + "doc_event-listeners-01.html";
-
-function test() {
-  Task.spawn(function* () {
-    let tab = yield addTab(TAB_URL);
-
-    // Create a sandboxed content script the Add-on SDK way. Inspired by bug
-    // 1145996.
-    let tabs = require("sdk/tabs");
-    let sdkTab = [...tabs].find(tab => tab.url === TAB_URL);
-    ok(sdkTab, "Add-on SDK found the loaded tab.");
-
-    info("Attaching an event handler via add-on sdk content scripts.");
-    let worker = sdkTab.attach({
-      contentScript: "document.body.addEventListener('click', e => alert(e))",
-      onError: ok.bind(this, false)
-    });
-
-    let options = {
-      source: TAB_URL,
-      line: 1
-    };
-    let [,, panel, win] = yield initDebugger(tab, options);
-    let dbg = panel.panelWin;
-    let controller = dbg.DebuggerController;
-    let constants = dbg.require("./content/constants");
-    let actions = dbg.require("./content/actions/event-listeners");
-    let fetched = waitForDispatch(panel, constants.FETCH_EVENT_LISTENERS);
-
-    info("Scheduling event listener fetch.");
-    controller.dispatch(actions.fetchEventListeners());
-
-    info("Waiting for updated event listeners to arrive.");
-    yield fetched;
-
-    ok(true, "The listener update did not hang.");
-    closeDebuggerAndFinish(panel);
-  });
-}
deleted file mode 100644
--- a/devtools/client/debugger/test/mochitest/doc_event-listeners-04.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!-- Any copyright is dedicated to the Public Domain.
-     http://creativecommons.org/publicdomain/zero/1.0/ -->
-<!doctype html>
-<html>
-  <head>
-    <meta charset="utf-8"/>
-    <title>Debugger test page</title>
-  </head>
-
-  <body>
-    <button>Click me!</button>
-
-    <script type="text/javascript">
-      window.addEventListener("load", function onload() {
-        var button = document.querySelector("button");
-        button.onclick = function () {
-          debugger;
-        };
-      });
-    </script>
-  </body>
-
-</html>
--- a/devtools/client/performance/test/helpers/tab-utils.js
+++ b/devtools/client/performance/test/helpers/tab-utils.js
@@ -1,18 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
 /* globals dump */
 
+const { Cu } = require("chrome");
+const { BrowserTestUtils } = Cu.import("resource://testing-common/BrowserTestUtils.jsm", {});
 const Services = require("Services");
-const tabs = require("sdk/tabs");
-const tabUtils = require("sdk/tabs/utils");
-const { viewFor } = require("sdk/view/core");
 const { waitForDelayedStartupFinished } = require("devtools/client/performance/test/helpers/wait-utils");
 const { gDevTools } = require("devtools/client/framework/devtools");
 
 /**
  * Gets a random integer in between an interval. Used to uniquely identify
  * added tabs by augmenting the URL.
  */
 function getRandomInt(min, max) {
@@ -24,54 +23,29 @@ function getRandomInt(min, max) {
  * for it to load.
  */
 exports.addTab = function ({ url, win }, options = {}) {
   let id = getRandomInt(0, Number.MAX_SAFE_INTEGER - 1);
   url += `#${id}`;
 
   dump(`Adding tab with url: ${url}.\n`);
 
-  return new Promise(resolve => {
-    let tab;
-
-    tabs.on("ready", function onOpen(model) {
-      if (tab != viewFor(model)) {
-        return;
-      }
-      dump(`Tab added and finished loading: ${model.url}.\n`);
-      tabs.off("ready", onOpen);
-      resolve(tab);
-    });
-
-    win.focus();
-    tab = tabUtils.openTab(win, url);
-
-    if (options.dontWaitForTabReady) {
-      resolve(tab);
-    }
-  });
+  let { gBrowser } = win || window;
+  return BrowserTestUtils.openNewForegroundTab(gBrowser, url,
+                                               !options.dontWaitForTabReady);
 };
 
 /**
  * Removes a browser tab from the specified window and waits for it to close.
  */
 exports.removeTab = function (tab, options = {}) {
-  dump(`Removing tab: ${tabUtils.getURI(tab)}.\n`);
+  dump(`Removing tab: ${tab.linkedBrowser.currentURI.spec}.\n`);
 
   return new Promise(resolve => {
-    tabs.on("close", function onClose(model) {
-      if (tab != viewFor(model)) {
-        return;
-      }
-      dump(`Tab removed and finished closing: ${model.url}.\n`);
-      tabs.off("close", onClose);
-      resolve(tab);
-    });
-
-    tabUtils.closeTab(tab);
+    BrowserTestUtils.removeTab(tab).then(() => resolve(tab));
 
     if (options.dontWaitForTabClose) {
       resolve(tab);
     }
   });
 };
 
 /**
--- a/devtools/shared/gcli/command-state.js
+++ b/devtools/shared/gcli/command-state.js
@@ -1,19 +1,17 @@
 /* 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";
 
 const EventEmitter = require("devtools/shared/event-emitter");
 
-loader.lazyRequireGetter(this, "getBrowserForTab", "sdk/tabs/utils", true);
-
-const getTargetId = ({tab}) => getBrowserForTab(tab).outerWindowID;
+const getTargetId = ({tab}) => tab.linkedBrowser.outerWindowID;
 const enabledCommands = new Map();
 
 /**
  * The `CommandState` is a singleton that provides utility methods to keep the commands'
  * state in sync between the toolbox, the toolbar and the content.
  */
 const CommandState = EventEmitter.decorate({
   /**