Bug 1404392 - Enable and refactor browser_webconsole_filter_scroll.js to check that filtering does not affect scroll position; r=bgrins. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 08 Jan 2018 18:02:51 +0100
changeset 717557 259f1098f24f6418d5194c0840802ce52c77259f
parent 717556 6aec7a783637a3a66e354ad0afb741cff329af0f
child 717558 a59401ac327772b2c1a0a8b1c1b52bf4490a29a8
push id94728
push userbmo:nchevobbe@mozilla.com
push dateTue, 09 Jan 2018 08:40:09 +0000
reviewersbgrins
bugs1404392
milestone59.0a1
Bug 1404392 - Enable and refactor browser_webconsole_filter_scroll.js to check that filtering does not affect scroll position; r=bgrins. MozReview-Commit-ID: DEZDnblICnh
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filter_scroll.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -271,17 +271,16 @@ skip-if = (e10s && debug) || (e10s && os
 [browser_webconsole_errors_after_page_reload.js]
 [browser_webconsole_eval_in_debugger_stackframe.js]
 [browser_webconsole_eval_in_debugger_stackframe2.js]
 [browser_webconsole_execution_scope.js]
 [browser_webconsole_external_script_errors.js]
 [browser_webconsole_file_uri.js]
 skip-if = true #	Bug 1404382
 [browser_webconsole_filter_scroll.js]
-skip-if = true #	Bug 1404392
 [browser_webconsole_filters.js]
 [browser_webconsole_filters_persist.js]
 [browser_webconsole_highlighter_console_helper.js]
 [browser_webconsole_history_arrow_keys.js]
 [browser_webconsole_hpkp_invalid-headers.js]
 skip-if = true #	Bug 1405340
 # old console skip-if = (os == 'win' && bits == 64) # Bug 1390001
 [browser_webconsole_hsts_invalid-headers.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filter_scroll.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filter_scroll.js
@@ -1,82 +1,78 @@
 /* -*- 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/ */
 
 "use strict";
 
-// See Bug 597460.
+const TEST_URI =
+`data:text/html;charset=utf-8,
+  <p>Web Console test for scroll when filtering.</p>
+  <script>
+  for (let i = 0; i < 100; i++) {
+    console.log("init-" + i);
+  }
+  </script>
+`;
+add_task(async function () {
+  const hud = await openNewTabAndConsole(TEST_URI);
+  let {ui} = hud;
+  const outputContainer = ui.outputNode.querySelector(".webconsole-output");
 
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "test/test-network.html";
-const PREF = "devtools.webconsole.persistlog";
+  info("Console should be scrolled to bottom on initial load from page logs");
+  await waitFor(() => findMessage(hud, "init-99"));
+  ok(hasVerticalOverflow(outputContainer), "There is a vertical overflow");
+  ok(isScrolledToBottom(outputContainer), "The console is scrolled to the bottom");
 
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF, true);
+  info("Filter out some messages and check that the scroll position is not impacted");
+  const filterInput = hud.ui.outputNode.querySelector(".text-filter");
 
-  yield loadTab(TEST_URI);
-  let hud = yield openConsole();
+  filterInput.value = "init-";
+  filterInput.focus();
+  let onMessagesFiltered = waitFor(() => !findMessage(hud, "init-1"), null, 200);
+  EventUtils.synthesizeKey("9", {});
+  await onMessagesFiltered;
+  ok(isScrolledToBottom(outputContainer),
+    "The console is still scrolled to the bottom after filtering");
+
+  info("Clear the text filter and check that the scroll position is not impacted");
+  let onMessagesUnFiltered = waitFor(() => findMessage(hud, "init-1"), null, 200);
+  filterInput.select();
+  EventUtils.synthesizeKey("VK_DELETE", {});
+  await onMessagesUnFiltered;
+  ok(isScrolledToBottom(outputContainer),
+    "The console is still scrolled to the bottom after clearing the filter");
 
-  let results = yield consoleOpened(hud);
+  info("Scroll up");
+  outputContainer.scrollTop = 0;
 
-  testScroll(results, hud);
+  filterInput.value = "init-";
+  filterInput.focus();
+  onMessagesFiltered = waitFor(() => !findMessage(hud, "init-1"), null, 200);
+  EventUtils.synthesizeKey("9", {});
+  await onMessagesFiltered;
+  is(outputContainer.scrollTop, 0,
+    "The console is still scrolled to the top after filtering");
 
-  Services.prefs.clearUserPref(PREF);
+  info("Clear the text filter and check that the scroll position is not impacted");
+  onMessagesUnFiltered = waitFor(() => findMessage(hud, "init-1"), null, 200);
+  filterInput.select();
+  EventUtils.synthesizeKey("VK_DELETE", {});
+  await onMessagesUnFiltered;
+  is(outputContainer.scrollTop, 0,
+    "The console is still scrolled to the top after clearing the filter");
+
 });
 
-function consoleOpened(hud) {
-  let deferred = defer();
-
-  for (let i = 0; i < 200; i++) {
-    content.console.log("test message " + i);
-  }
-
-  hud.setFilterState("network", false);
-  hud.setFilterState("networkinfo", false);
-
-  hud.ui.filterBox.value = "test message";
-  hud.ui.adjustVisibilityOnSearchStringChange();
-
-  waitForMessages({
-    webconsole: hud,
-    messages: [{
-      name: "console messages displayed",
-      text: "test message 199",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_LOG,
-    }],
-  }).then(() => {
-    waitForMessages({
-      webconsole: hud,
-      messages: [{
-        text: "test-network.html",
-        category: CATEGORY_NETWORK,
-        severity: SEVERITY_LOG,
-      }],
-    }).then(deferred.resolve);
-
-    content.location.reload();
-  });
-
-  return deferred.promise;
+function hasVerticalOverflow(container) {
+  return container.scrollHeight > container.clientHeight;
 }
 
-function testScroll([result], hud) {
-  let scrollNode = hud.ui.outputWrapper;
-  let msgNode = [...result.matched][0];
-  ok(msgNode.classList.contains("filtered-by-type"),
-    "network message is filtered by type");
-  ok(msgNode.classList.contains("filtered-by-string"),
-    "network message is filtered by string");
-
-  ok(scrollNode.scrollTop > 0, "scroll location is not at the top");
-
-  // Make sure the Web Console output is scrolled as near as possible to the
-  // bottom.
-  let nodeHeight = msgNode.clientHeight;
-  ok(scrollNode.scrollTop >= scrollNode.scrollHeight - scrollNode.clientHeight -
-     nodeHeight * 2, "scroll location is correct");
-
-  hud.setFilterState("network", true);
-  hud.setFilterState("networkinfo", true);
+function isScrolledToBottom(container) {
+  if (!container.lastChild) {
+    return true;
+  }
+  let lastNodeHeight = container.lastChild.clientHeight;
+  return container.scrollTop + container.clientHeight >=
+         container.scrollHeight - lastNodeHeight / 2;
 }