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