toolkit/content/tests/browser/browser_autoscroll_disabled.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 function test()
     2 {
     3   const kPrefName_AutoScroll = "general.autoScroll";
     4   Services.prefs.setBoolPref(kPrefName_AutoScroll, false);
     6   gBrowser.selectedTab = gBrowser.addTab();
     8   var doc;
    10   function startLoad(dataUri) {
    11     gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false);
    12     gBrowser.loadURI(dataUri);
    13   }
    15   function onLoad() {
    16     gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false);
    17     waitForFocus(onFocus, content);
    18   }
    20   function onFocus() {
    21     doc = gBrowser.contentDocument;
    22     runChecks();
    23   }
    25   function endTest() {
    26     // restore the changed prefs
    27     if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll))
    28       Services.prefs.clearUserPref(kPrefName_AutoScroll);
    30     // cleaning-up
    31     gBrowser.removeCurrentTab();
    33     // waitForFocus() fixes a failure in the next test if the latter runs too soon.
    34     waitForFocus(finish);
    35   }
    37   waitForExplicitFinish();
    39   let dataUri = 'data:text/html,<html><body id="i" style="overflow-y: scroll"><div style="height: 2000px"></div>\
    40       <iframe id="iframe" style="display: none;"></iframe>\
    41 </body></html>';
    42   startLoad(dataUri);
    44   function runChecks() {
    45     var elem = doc.getElementById('i');
    46     // Skip the first callback as it's the same callback that the browser
    47     // uses to kick off the scrolling.
    48     var skipFrames = 1;
    49     var checkScroll = function () {
    50       if (skipFrames--) {
    51         window.mozRequestAnimationFrame(checkScroll);
    52         return;
    53       }
    54       ok(elem.scrollTop == 0, "element should not have scrolled vertically");
    55       ok(elem.scrollLeft == 0, "element should not have scrolled horizontally");
    57       endTest();
    58     };
    59     EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 },
    60                                gBrowser.contentWindow);
    62     var iframe = gBrowser.contentDocument.getElementById("iframe");
    63     var e = iframe.contentDocument.createEvent("pagetransition");
    64     e.initPageTransitionEvent("pagehide", true, true, false);
    65     iframe.contentDocument.dispatchEvent(e);
    66     iframe.contentDocument.documentElement.dispatchEvent(e);
    68     EventUtils.synthesizeMouse(elem, 100, 100,
    69                                { type: "mousemove", clickCount: "0" },
    70                                gBrowser.contentWindow);
    71     /*
    72      * if scrolling didn’t work, we wouldn’t do any redraws and thus time out.
    73      * so request and force redraws to get the chance to check for scrolling at
    74      * all.
    75      */
    76     window.mozRequestAnimationFrame(checkScroll);
    77   }
    78 }

mercurial