browser/devtools/webconsole/test/browser_webconsole_bug_613642_maintain_scroll.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_613642_maintain_scroll.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,128 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/*
     1.6 + * Any copyright is dedicated to the Public Domain.
     1.7 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.8 + *
     1.9 + * Contributor(s):
    1.10 + *   Mihai Șucan <mihai.sucan@gmail.com>
    1.11 + */
    1.12 +
    1.13 +let hud, testDriver;
    1.14 +
    1.15 +function testNext() {
    1.16 +  testDriver.next();
    1.17 +}
    1.18 +
    1.19 +function testGen() {
    1.20 +  hud.jsterm.clearOutput();
    1.21 +  let outputNode = hud.outputNode;
    1.22 +  let scrollBox = outputNode.parentNode;
    1.23 +
    1.24 +  for (let i = 0; i < 150; i++) {
    1.25 +    content.console.log("test message " + i);
    1.26 +  }
    1.27 +
    1.28 +  waitForMessages({
    1.29 +    webconsole: hud,
    1.30 +    messages: [{
    1.31 +      text: "test message 149",
    1.32 +      category: CATEGORY_WEBDEV,
    1.33 +      severity: SEVERITY_LOG,
    1.34 +    }],
    1.35 +  }).then(testNext);
    1.36 +
    1.37 +  yield undefined;
    1.38 +
    1.39 +  ok(scrollBox.scrollTop > 0, "scroll location is not at the top");
    1.40 +
    1.41 +  // scroll to the first node
    1.42 +  outputNode.focus();
    1.43 +
    1.44 +  scrollBox.onscroll = () => {
    1.45 +    info("onscroll top " + scrollBox.scrollTop);
    1.46 +    if (scrollBox.scrollTop != 0) {
    1.47 +      // Wait for scroll to 0.
    1.48 +      return;
    1.49 +    }
    1.50 +    scrollBox.onscroll = null;
    1.51 +    is(scrollBox.scrollTop, 0, "scroll location updated (moved to top)");
    1.52 +    testNext();
    1.53 +  };
    1.54 +  EventUtils.synthesizeKey("VK_HOME", {}, hud.iframeWindow);
    1.55 +
    1.56 +  yield undefined;
    1.57 +
    1.58 +  // add a message and make sure scroll doesn't change
    1.59 +  content.console.log("test message 150");
    1.60 +
    1.61 +  waitForMessages({
    1.62 +    webconsole: hud,
    1.63 +    messages: [{
    1.64 +      text: "test message 150",
    1.65 +      category: CATEGORY_WEBDEV,
    1.66 +      severity: SEVERITY_LOG,
    1.67 +    }],
    1.68 +  }).then(testNext);
    1.69 +
    1.70 +  yield undefined;
    1.71 +
    1.72 +  scrollBox.onscroll = () => {
    1.73 +    if (scrollBox.scrollTop != 0) {
    1.74 +      // Wait for scroll to stabilize at the top.
    1.75 +      return;
    1.76 +    }
    1.77 +    scrollBox.onscroll = null;
    1.78 +    is(scrollBox.scrollTop, 0, "scroll location is still at the top");
    1.79 +    testNext();
    1.80 +  };
    1.81 +
    1.82 +  // Make sure that scroll stabilizes at the top. executeSoon() is needed for
    1.83 +  // the yield to work.
    1.84 +  executeSoon(scrollBox.onscroll);
    1.85 +
    1.86 +  yield undefined;
    1.87 +
    1.88 +  // scroll back to the bottom
    1.89 +  outputNode.lastChild.focus();
    1.90 +
    1.91 +  scrollBox.onscroll = () => {
    1.92 +    if (scrollBox.scrollTop == 0) {
    1.93 +      // Wait for scroll to bottom.
    1.94 +      return;
    1.95 +    }
    1.96 +    scrollBox.onscroll = null;
    1.97 +    isnot(scrollBox.scrollTop, 0, "scroll location updated (moved to bottom)");
    1.98 +    testNext();
    1.99 +  };
   1.100 +  EventUtils.synthesizeKey("VK_END", {});
   1.101 +  yield undefined;
   1.102 +
   1.103 +  let oldScrollTop = scrollBox.scrollTop;
   1.104 +
   1.105 +  content.console.log("test message 151");
   1.106 +
   1.107 +  scrollBox.onscroll = () => {
   1.108 +    if (scrollBox.scrollTop == oldScrollTop) {
   1.109 +      // Wait for scroll to change.
   1.110 +      return;
   1.111 +    }
   1.112 +    scrollBox.onscroll = null;
   1.113 +    isnot(scrollBox.scrollTop, oldScrollTop, "scroll location updated (moved to bottom again)");
   1.114 +    hud = testDriver = null;
   1.115 +    finishTest();
   1.116 +  };
   1.117 +
   1.118 +  yield undefined;
   1.119 +}
   1.120 +
   1.121 +function test() {
   1.122 +  addTab("data:text/html;charset=utf-8,Web Console test for bug 613642: remember scroll location");
   1.123 +  browser.addEventListener("load", function tabLoad(aEvent) {
   1.124 +    browser.removeEventListener(aEvent.type, tabLoad, true);
   1.125 +    openConsole(null, function(aHud) {
   1.126 +      hud = aHud;
   1.127 +      testDriver = testGen();
   1.128 +      testDriver.next();
   1.129 +    });
   1.130 +  }, true);
   1.131 +}

mercurial