Bug 1261687 - Don't update devtools title if tabNavigated.isFrameSwitching;r=jryans
Check the "isFrameSwitching" property of the tabNavigated event before
updating the devtools title. If frameSwitching is true, the event is a
fake event generated by the webbrowser actor when switching the frame
context in the devtools.
Added another mochitest to verify this.
MozReview-Commit-ID: LDycPcf0tLv
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -473,26 +473,28 @@ TabTarget.prototype = {
// We have to filter message to ensure that this detach is for this tab
if (aPacket.from == this._form.actor) {
this.destroy();
}
};
this.client.addListener("tabDetached", this._onTabDetached);
this._onTabNavigated = (aType, aPacket) => {
- // Update the title and url on tabNavigated event.
- this._url = aPacket.url;
- this._title = aPacket.title;
-
let event = Object.create(null);
event.url = aPacket.url;
event.title = aPacket.title;
event.nativeConsoleAPI = aPacket.nativeConsoleAPI;
event.isFrameSwitching = aPacket.isFrameSwitching;
+ if (!aPacket.isFrameSwitching) {
+ // Update the title and url unless this is a frame switch.
+ this._url = aPacket.url;
+ this._title = aPacket.title;
+ }
+
// Send any stored event payload (DOMWindow or nsIRequest) for backwards
// compatibility with non-remotable tools.
if (aPacket.state == "start") {
event._navPayload = this._navRequest;
this.emit("will-navigate", event);
this._navRequest = null;
} else {
event._navPayload = this._navWindow;
--- a/devtools/client/framework/test/browser.ini
+++ b/devtools/client/framework/test/browser.ini
@@ -2,16 +2,17 @@
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_math.js
code_ugly.js
head.js
shared-head.js
shared-redux-head.js
helper_disable_cache.js
doc_theme.css
doc_viewsource.html
@@ -69,13 +70,14 @@ skip-if = e10s # Bug 1069044 - destroyIn
[browser_toolbox_view_source_01.js]
[browser_toolbox_view_source_02.js]
[browser_toolbox_view_source_03.js]
[browser_toolbox_view_source_04.js]
[browser_toolbox_window_reload_target.js]
[browser_toolbox_window_shortcuts.js]
skip-if = os == "mac" && os_version == "10.8" || os == "win" && os_version == "5.1" # Bug 851129 - Re-enable browser_toolbox_window_shortcuts.js test after leaks are fixed
[browser_toolbox_window_title_changes.js]
+[browser_toolbox_window_title_frame_select.js]
[browser_toolbox_zoom.js]
[browser_two_tabs.js]
skip-if = e10s && debug && os == 'win' # Bug 1231869
# We want this test to run for mochitest-dt as well, so we include it here:
[../../../../browser/base/content/test/general/browser_parsable_css.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/browser_toolbox_window_title_frame_select.js
@@ -0,0 +1,72 @@
+/* -*- 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/ */
+
+/* import-globals-from shared-head.js */
+
+"use strict";
+
+/**
+ * Check that the detached devtools window title is not updated when switching
+ * the selected frame.
+ */
+
+var {Toolbox} = require("devtools/client/framework/toolbox");
+const URL = URL_ROOT + "browser_toolbox_window_title_frame_select_page.html";
+const IFRAME_URL = URL_ROOT + "browser_toolbox_window_title_changes_page.html";
+
+add_task(function* () {
+ Services.prefs.setBoolPref("devtools.command-button-frames.enabled", true);
+
+ yield addTab(URL);
+ let target = TargetFactory.forTab(gBrowser.selectedTab);
+ let toolbox = yield gDevTools.showToolbox(target, null,
+ Toolbox.HostType.BOTTOM);
+
+ yield toolbox.selectTool("inspector");
+ yield toolbox.switchHost(Toolbox.HostType.WINDOW);
+
+ is(getTitle(), "Inspector - Page title",
+ "Devtools title correct after switching to detached window host");
+
+ // Verify that the frame list button is visible and populated
+ let btn = toolbox.doc.getElementById("command-button-frames");
+ let frames = Array.slice(btn.firstChild.querySelectorAll("[data-window-id]"));
+ is(frames.length, 2, "We have both frames in the list");
+
+ let topFrameBtn = frames.filter(b => b.getAttribute("label") == URL)[0];
+ let iframeBtn = frames.filter(b => b.getAttribute("label") == IFRAME_URL)[0];
+ ok(topFrameBtn, "Got top level document in the list");
+ ok(iframeBtn, "Got iframe document in the list");
+
+ // Listen to will-navigate to check if the view is empty
+ let willNavigate = toolbox.target.once("will-navigate");
+
+ // Only select the iframe after we are able to select an element from the top
+ // level document.
+ let newRoot = toolbox.getPanel("inspector").once("new-root");
+ info("Select the iframe");
+ iframeBtn.click();
+
+ yield willNavigate;
+ yield newRoot;
+
+ info("Navigation to the iframe is done, the inspector should be back up");
+ is(getTitle(), "Inspector - Page title",
+ "Devtools title was not updated after changing inspected frame");
+
+ info("Cleanup toolbox and test preferences.");
+ yield toolbox.destroy();
+ toolbox = null;
+ gBrowser.removeCurrentTab();
+ Services.prefs.clearUserPref("devtools.toolbox.host");
+ Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
+ Services.prefs.clearUserPref("devtools.toolbox.sideEnabled");
+ Services.prefs.clearUserPref("devtools.command-button-frames.enabled");
+ finish();
+});
+
+function getTitle() {
+ return Services.wm.getMostRecentWindow("devtools:toolbox").document.title;
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/browser_toolbox_window_title_frame_select_page.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Page title</title>
+ <!-- Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ -->
+ <iframe src="browser_toolbox_window_title_changes_page.html"></iframe>
+ </head>
+ <body></body>
+</html>