|
1 function test() |
|
2 { |
|
3 const kPrefName_AutoScroll = "general.autoScroll"; |
|
4 Services.prefs.setBoolPref(kPrefName_AutoScroll, false); |
|
5 |
|
6 gBrowser.selectedTab = gBrowser.addTab(); |
|
7 |
|
8 var doc; |
|
9 |
|
10 function startLoad(dataUri) { |
|
11 gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false); |
|
12 gBrowser.loadURI(dataUri); |
|
13 } |
|
14 |
|
15 function onLoad() { |
|
16 gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false); |
|
17 waitForFocus(onFocus, content); |
|
18 } |
|
19 |
|
20 function onFocus() { |
|
21 doc = gBrowser.contentDocument; |
|
22 runChecks(); |
|
23 } |
|
24 |
|
25 function endTest() { |
|
26 // restore the changed prefs |
|
27 if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll)) |
|
28 Services.prefs.clearUserPref(kPrefName_AutoScroll); |
|
29 |
|
30 // cleaning-up |
|
31 gBrowser.removeCurrentTab(); |
|
32 |
|
33 // waitForFocus() fixes a failure in the next test if the latter runs too soon. |
|
34 waitForFocus(finish); |
|
35 } |
|
36 |
|
37 waitForExplicitFinish(); |
|
38 |
|
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); |
|
43 |
|
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"); |
|
56 |
|
57 endTest(); |
|
58 }; |
|
59 EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 }, |
|
60 gBrowser.contentWindow); |
|
61 |
|
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); |
|
67 |
|
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 } |