|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=549262 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 549262</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549262">Mozilla Bug 549262</a> |
|
14 <p id="display"></p> |
|
15 <div id="content"> |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript"> |
|
19 |
|
20 /** Test for Bug 549262 **/ |
|
21 |
|
22 var smoothScrollPref = "general.smoothScroll"; |
|
23 SpecialPowers.setBoolPref(smoothScrollPref, false); |
|
24 SimpleTest.waitForExplicitFinish(); |
|
25 var win = window.open("file_bug549262.html", "_blank", |
|
26 "width=600,height=600,scrollbars=yes"); |
|
27 |
|
28 // grab the timer right at the start |
|
29 var cwu = SpecialPowers.getDOMWindowUtils(win); |
|
30 function step() { |
|
31 cwu.advanceTimeAndRefresh(100); |
|
32 } |
|
33 |
|
34 SimpleTest.waitForFocus(function() { |
|
35 // Make sure that pressing Space when a contenteditable element is not focused |
|
36 // will scroll the page. |
|
37 var ed = win.document.getElementById("editor"); |
|
38 var sc = win.document.querySelector("a"); |
|
39 sc.focus(); |
|
40 is(win.scrollY, 0, "Sanity check"); |
|
41 synthesizeKey(" ", {}, win); |
|
42 |
|
43 step(); |
|
44 |
|
45 isnot(win.scrollY, 0, "Page is scrolled down"); |
|
46 is(ed.textContent, "abc", "The content of the editable element has not changed"); |
|
47 var oldY = win.scrollY; |
|
48 synthesizeKey(" ", {shiftKey: true}, win); |
|
49 |
|
50 step(); |
|
51 |
|
52 ok(win.scrollY < oldY, "Page is scrolled up"); |
|
53 is(ed.textContent, "abc", "The content of the editable element has not changed"); |
|
54 |
|
55 // Make sure that pressing Space when a contenteditable element is focused |
|
56 // will not scroll the page, and will edit the element. |
|
57 ed.focus(); |
|
58 win.getSelection().collapse(ed.firstChild, 1); |
|
59 oldY = win.scrollY; |
|
60 synthesizeKey(" ", {}, win); |
|
61 |
|
62 step(); |
|
63 |
|
64 ok(win.scrollY <= oldY, "Page is not scrolled down"); |
|
65 is(ed.textContent, "a bc", "The content of the editable element has changed"); |
|
66 sc.focus(); |
|
67 synthesizeKey(" ", {}, win); |
|
68 |
|
69 step(); |
|
70 |
|
71 isnot(win.scrollY, 0, "Page is scrolled down"); |
|
72 is(ed.textContent, "a bc", "The content of the editable element has not changed"); |
|
73 ed.focus(); |
|
74 win.getSelection().collapse(ed.firstChild, 3); |
|
75 synthesizeKey(" ", {shiftKey: true}, win); |
|
76 |
|
77 step(); |
|
78 |
|
79 isnot(win.scrollY, 0, "Page is not scrolled up"); |
|
80 is(ed.textContent, "a b c", "The content of the editable element has changed"); |
|
81 |
|
82 // Now let's test the down/up keys |
|
83 sc = document.body; |
|
84 |
|
85 step(); |
|
86 |
|
87 ed.blur(); |
|
88 sc.focus(); |
|
89 oldY = win.scrollY; |
|
90 synthesizeKey("VK_UP", {}, win); |
|
91 |
|
92 step(); |
|
93 |
|
94 ok(win.scrollY < oldY, "Page is scrolled up"); |
|
95 oldY = win.scrollY; |
|
96 ed.focus(); |
|
97 win.getSelection().collapse(ed.firstChild, 3); |
|
98 synthesizeKey("VK_UP", {}, win); |
|
99 |
|
100 step(); |
|
101 |
|
102 is(win.scrollY, oldY, "Page is not scrolled up"); |
|
103 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); |
|
104 is(win.getSelection().focusOffset, 0, "Selection should be moved to the beginning"); |
|
105 win.getSelection().removeAllRanges(); |
|
106 synthesizeMouse(sc, 300, 300, {}, win); |
|
107 synthesizeKey("VK_DOWN", {}, win); |
|
108 |
|
109 step(); |
|
110 |
|
111 ok(win.scrollY > oldY, "Page is scrolled down"); |
|
112 ed.focus(); |
|
113 win.getSelection().collapse(ed.firstChild, 3); |
|
114 oldY = win.scrollY; |
|
115 synthesizeKey("VK_DOWN", {}, win); |
|
116 |
|
117 step(); |
|
118 |
|
119 is(win.scrollY, oldY, "Page is not scrolled down"); |
|
120 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); |
|
121 is(win.getSelection().focusOffset, ed.textContent.length, "Selection should be moved to the end"); |
|
122 |
|
123 win.close(); |
|
124 SpecialPowers.clearUserPref(smoothScrollPref); |
|
125 cwu.restoreNormalRefresh(); |
|
126 |
|
127 SimpleTest.finish(); |
|
128 }, win); |
|
129 |
|
130 </script> |
|
131 </pre> |
|
132 </body> |
|
133 </html> |