Bug 1484989 - Prevent JsTerm to steal focus when reloading a page; r=bgrins.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 15 Oct 2018 14:25:10 +0000
changeset 499744 57c85fc5a5bc6a1c25fc0050aa4350bbe82f6ecf
parent 499743 fc9eacb1243742cb91903442938e0664d5a8817e
child 499745 71a04ddae0fad8b796e63f482269e825b98fd686
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1484989
milestone64.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 1484989 - Prevent JsTerm to steal focus when reloading a page; r=bgrins. JsTerm's focus function was called in clearOutput, which we call when navigating to a new page (if Persist Logs is not checked). This means that we were forcing the JsTerm to be focused each time the user navigated while having the console open. This behavior, can be annoying, or at worst, if you're debugging a focus issue in your content page, completely maddening. The fix is striaghtforward: do not call focus in clearOutput. A test is added to make sure we don't regress this. Differential Revision: https://phabricator.services.mozilla.com/D8701
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_jsterm_focus_reload.js
devtools/client/webconsole/webconsole-frame.js
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -215,16 +215,17 @@ skip-if = verify
 [browser_jsterm_content_defined_helpers.js]
 [browser_jsterm_copy_command.js]
 [browser_jsterm_ctrl_a_select_all.js]
 [browser_jsterm_ctrl_key_nav.js]
 skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only
 [browser_jsterm_document_no_xray.js]
 [browser_jsterm_error_docs.js]
 [browser_jsterm_error_outside_valid_range.js]
+[browser_jsterm_focus_reload.js]
 [browser_jsterm_helper_clear.js]
 [browser_jsterm_helper_dollar_dollar.js]
 [browser_jsterm_helper_dollar_x.js]
 [browser_jsterm_helper_dollar.js]
 [browser_jsterm_helper_help.js]
 [browser_jsterm_helper_keys_values.js]
 [browser_jsterm_helper_pprint.js]
 [browser_jsterm_hide_when_devtools_chrome_enabled_false.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_focus_reload.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Check that the console does not steal the focus when reloading a page, if the focus
+// is on the content page.
+
+"use strict";
+
+const TEST_URI = `data:text/html,<meta charset=utf8>Focus test`;
+
+add_task(async function() {
+  // Run test with legacy JsTerm
+  await pushPref("devtools.webconsole.jsterm.codeMirror", false);
+  await performTests();
+  // And then run it with the CodeMirror-powered one.
+  await pushPref("devtools.webconsole.jsterm.codeMirror", true);
+  await performTests();
+});
+
+async function performTests() {
+  info("Testing that messages disappear on a refresh if logs aren't persisted");
+  const {jsterm} = await openNewTabAndConsole(TEST_URI);
+  is(isJstermFocused(jsterm), true, "JsTerm is focused when opening the console");
+
+  info("Put the focus on the content page");
+  ContentTask.spawn(gBrowser.selectedBrowser, null, () => content.focus());
+  await waitFor(() => isJstermFocused(jsterm) === false);
+
+  info("Reload the page to check that JsTerm does not steal the content page focus");
+  await refreshTab();
+  is(isJstermFocused(jsterm), false,
+    "JsTerm is still unfocused after reloading the page");
+}
--- a/devtools/client/webconsole/webconsole-frame.js
+++ b/devtools/client/webconsole/webconsole-frame.js
@@ -135,17 +135,16 @@ WebConsoleFrame.prototype = {
   clearOutput(clearStorage) {
     if (this.consoleOutput) {
       this.consoleOutput.dispatchMessagesClear();
     }
     this.webConsoleClient.clearNetworkRequests();
     if (clearStorage) {
       this.webConsoleClient.clearMessagesCache();
     }
-    this.jsterm.focus();
     this.emit("messages-cleared");
   },
 
   /**
    * Remove all of the private messages from the Web Console output.
    *
    * This method emits the "private-messages-cleared" notification.
    */