toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function test()
michael@0 2 {
michael@0 3 const kPrefName_AutoScroll = "general.autoScroll";
michael@0 4 Services.prefs.setBoolPref(kPrefName_AutoScroll, true);
michael@0 5
michael@0 6 gBrowser.selectedTab = gBrowser.addTab();
michael@0 7
michael@0 8 const expectScrollNone = 0;
michael@0 9 const expectScrollVert = 1;
michael@0 10 const expectScrollHori = 2;
michael@0 11 const expectScrollBoth = 3;
michael@0 12
michael@0 13 var allTests = [
michael@0 14 {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><body><style type="text/css">div { display: inline-block; }</style>\
michael@0 15 <div id="a" style="width: 100px; height: 100px; overflow: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
michael@0 16 <div id="b" style="width: 100px; height: 100px; overflow: auto;"><div style="width: 200px; height: 200px;"></div></div>\
michael@0 17 <div id="c" style="width: 100px; height: 100px; overflow-x: auto; overflow-y: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
michael@0 18 <div id="d" style="width: 100px; height: 100px; overflow-y: auto; overflow-x: hidden;"><div style="width: 200px; height: 200px;"></div></div>\
michael@0 19 <select id="e" style="width: 100px; height: 100px;" multiple="multiple"><option>aaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option><option>a</option>\
michael@0 20 <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\
michael@0 21 <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\
michael@0 22 <select id="f" style="width: 100px; height: 100px;"><option>a</option><option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option>\
michael@0 23 <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\
michael@0 24 <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\
michael@0 25 <div id="g" style="width: 99px; height: 99px; border: 10px solid black; margin: 10px; overflow: auto;"><div style="width: 100px; height: 100px;"></div></div>\
michael@0 26 <div id="h" style="width: 100px; height: 100px; overflow: -moz-hidden-unscrollable;"><div style="width: 200px; height: 200px;"></div></div>\
michael@0 27 <iframe id="iframe" style="display: none;"></iframe>\
michael@0 28 </body></html>'},
michael@0 29 {elem: 'a', expected: expectScrollNone},
michael@0 30 {elem: 'b', expected: expectScrollBoth},
michael@0 31 {elem: 'c', expected: expectScrollHori},
michael@0 32 {elem: 'd', expected: expectScrollVert},
michael@0 33 {elem: 'e', expected: expectScrollVert},
michael@0 34 {elem: 'f', expected: expectScrollNone},
michael@0 35 {elem: 'g', expected: expectScrollBoth},
michael@0 36 {elem: 'h', expected: expectScrollNone},
michael@0 37 {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><body id="i" style="overflow-y: scroll"><div style="height: 2000px"></div>\
michael@0 38 <iframe id="iframe" style="display: none;"></iframe>\
michael@0 39 </body></html>'},
michael@0 40 {elem: 'i', expected: expectScrollVert}, // bug 695121
michael@0 41 {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><style>html, body { width: 100%; height: 100%; overflow-x: hidden; overflow-y: scroll; }</style>\
michael@0 42 <body id="j"><div style="height: 2000px"></div>\
michael@0 43 <iframe id="iframe" style="display: none;"></iframe>\
michael@0 44 </body></html>'},
michael@0 45 {elem: 'j', expected: expectScrollVert} // bug 914251
michael@0 46 ];
michael@0 47
michael@0 48 var doc;
michael@0 49
michael@0 50 function nextTest() {
michael@0 51 var test = allTests.shift();
michael@0 52 if (!test) {
michael@0 53 endTest();
michael@0 54 return;
michael@0 55 }
michael@0 56
michael@0 57 if (test.dataUri) {
michael@0 58 startLoad(test.dataUri);
michael@0 59 return;
michael@0 60 }
michael@0 61
michael@0 62 var elem = doc.getElementById(test.elem);
michael@0 63
michael@0 64 let firstTimestamp = undefined;
michael@0 65 function checkScroll(timestamp) {
michael@0 66 if (firstTimestamp === undefined) {
michael@0 67 firstTimestamp = timestamp;
michael@0 68 }
michael@0 69
michael@0 70 // This value is calculated similarly to the value of the same name in
michael@0 71 // ClickEventHandler.autoscrollLoop, except here it's cumulative across
michael@0 72 // all frames after the first one instead of being based only on the
michael@0 73 // current frame.
michael@0 74 let timeCompensation = (timestamp - firstTimestamp) / 20;
michael@0 75 info("timestamp=" + timestamp + " firstTimestamp=" + firstTimestamp +
michael@0 76 " timeCompensation=" + timeCompensation);
michael@0 77
michael@0 78 // Try to wait until enough time has passed to allow the scroll to happen.
michael@0 79 // autoscrollLoop incrementally scrolls during each animation frame, but
michael@0 80 // due to how its calculations work, when a frame is very close to the
michael@0 81 // previous frame, no scrolling may actually occur during that frame.
michael@0 82 // After 20ms's worth of frames, timeCompensation will be 1, making it
michael@0 83 // more likely that the accumulated scroll in autoscrollLoop will be >= 1,
michael@0 84 // although it also depends on acceleration, which here in this test
michael@0 85 // should be > 1 due to how it synthesizes mouse events below.
michael@0 86 if (timeCompensation < 1) {
michael@0 87 window.mozRequestAnimationFrame(checkScroll);
michael@0 88 return;
michael@0 89 }
michael@0 90
michael@0 91 // Close the autoscroll popup by synthesizing Esc.
michael@0 92 EventUtils.synthesizeKey("VK_ESCAPE", {}, gBrowser.contentWindow);
michael@0 93 var scrollVert = test.expected & expectScrollVert;
michael@0 94 ok((scrollVert && elem.scrollTop > 0) ||
michael@0 95 (!scrollVert && elem.scrollTop == 0),
michael@0 96 test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically');
michael@0 97 var scrollHori = test.expected & expectScrollHori;
michael@0 98 ok((scrollHori && elem.scrollLeft > 0) ||
michael@0 99 (!scrollHori && elem.scrollLeft == 0),
michael@0 100 test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally');
michael@0 101
michael@0 102 // Before continuing the test, we need to ensure that the IPC
michael@0 103 // message that stops autoscrolling has had time to arrive.
michael@0 104 executeSoon(nextTest);
michael@0 105 };
michael@0 106 EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 },
michael@0 107 gBrowser.contentWindow);
michael@0 108
michael@0 109 // This ensures bug 605127 is fixed: pagehide in an unrelated document
michael@0 110 // should not cancel the autoscroll.
michael@0 111 var iframe = gBrowser.contentDocument.getElementById("iframe");
michael@0 112 var e = iframe.contentDocument.createEvent("pagetransition");
michael@0 113 e.initPageTransitionEvent("pagehide", true, true, false);
michael@0 114 iframe.contentDocument.dispatchEvent(e);
michael@0 115 iframe.contentDocument.documentElement.dispatchEvent(e);
michael@0 116
michael@0 117 EventUtils.synthesizeMouse(elem, 100, 100,
michael@0 118 { type: "mousemove", clickCount: "0" },
michael@0 119 gBrowser.contentWindow);
michael@0 120
michael@0 121 // Start checking for the scroll.
michael@0 122 window.mozRequestAnimationFrame(checkScroll);
michael@0 123 }
michael@0 124
michael@0 125 waitForExplicitFinish();
michael@0 126
michael@0 127 nextTest();
michael@0 128
michael@0 129 function startLoad(dataUri) {
michael@0 130 gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false);
michael@0 131 gBrowser.loadURI(dataUri);
michael@0 132 }
michael@0 133
michael@0 134 function onLoad() {
michael@0 135 gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false);
michael@0 136 waitForFocus(onFocus, content);
michael@0 137 }
michael@0 138
michael@0 139 function onFocus() {
michael@0 140 doc = gBrowser.contentDocument;
michael@0 141 nextTest();
michael@0 142 }
michael@0 143
michael@0 144 function endTest() {
michael@0 145 // restore the changed prefs
michael@0 146 if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll))
michael@0 147 Services.prefs.clearUserPref(kPrefName_AutoScroll);
michael@0 148
michael@0 149 // cleaning-up
michael@0 150 gBrowser.removeCurrentTab();
michael@0 151
michael@0 152 // waitForFocus() fixes a failure in the next test if the latter runs too soon.
michael@0 153 waitForFocus(finish);
michael@0 154 }
michael@0 155 }

mercurial