|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=629172 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 629172</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629172">Mozilla Bug 629172</a> |
|
15 <p id="display"></p> |
|
16 <div id="content"> |
|
17 <textarea id="ltr-ref" style="display: none">test.</textarea> |
|
18 <textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea> |
|
19 </div> |
|
20 <pre id="test"> |
|
21 <script type="application/javascript"> |
|
22 |
|
23 /** Test for Bug 629172 **/ |
|
24 SimpleTest.waitForExplicitFinish(); |
|
25 SimpleTest.waitForFocus(function() { |
|
26 var LTRRef = document.getElementById("ltr-ref"); |
|
27 var RTLRef = document.getElementById("rtl-ref"); |
|
28 var Screenshots = {}; |
|
29 |
|
30 // generate the reference screenshots |
|
31 LTRRef.style.display = ""; |
|
32 document.body.clientWidth; |
|
33 Screenshots.ltr = snapshotWindow(window); |
|
34 LTRRef.parentNode.removeChild(LTRRef); |
|
35 RTLRef.style.display = ""; |
|
36 document.body.clientWidth; |
|
37 Screenshots.rtl = snapshotWindow(window); |
|
38 RTLRef.parentNode.removeChild(RTLRef); |
|
39 Screenshots.get = function(dir, flip) { |
|
40 if (flip) { |
|
41 return this[dir == "rtl" ? "ltr" : "rtl"]; |
|
42 } else { |
|
43 return this[dir]; |
|
44 } |
|
45 }; |
|
46 |
|
47 function testDirection(initialDir) { |
|
48 var t = document.createElement("textarea"); |
|
49 t.setAttribute("dir", initialDir); |
|
50 t.value = "test."; |
|
51 var inputEventCount = 0; |
|
52 t.oninput = function() { inputEventCount++; }; |
|
53 document.getElementById("content").appendChild(t); |
|
54 document.body.clientWidth; |
|
55 var s1 = snapshotWindow(window); |
|
56 ok(compareSnapshots(s1, Screenshots.get(initialDir, false), true)[0], |
|
57 "Textarea should appear correctly before switching the direction (" + initialDir + ")"); |
|
58 t.focus(); |
|
59 is(inputEventCount, 0, "input event count must be 0 before"); |
|
60 synthesizeKey("x", {accelKey: true, shiftKey: true}); |
|
61 is(t.getAttribute("dir"), initialDir == "ltr" ? "rtl" : "ltr", "The dir attribute must be correctly updated"); |
|
62 is(inputEventCount, 1, "input event count must be 1 after"); |
|
63 t.blur(); |
|
64 var s2 = snapshotWindow(window); |
|
65 ok(compareSnapshots(s2, Screenshots.get(initialDir, true), true)[0], |
|
66 "Textarea should appear correctly after switching the direction (" + initialDir + ")"); |
|
67 t.focus(); |
|
68 is(inputEventCount, 1, "input event count must be 1 before"); |
|
69 synthesizeKey("x", {accelKey: true, shiftKey: true}); |
|
70 is(inputEventCount, 2, "input event count must be 2 after"); |
|
71 is(t.getAttribute("dir"), initialDir == "ltr" ? "ltr" : "rtl", "The dir attribute must be correctly updated"); |
|
72 t.blur(); |
|
73 var s3 = snapshotWindow(window); |
|
74 ok(compareSnapshots(s3, Screenshots.get(initialDir, false), true)[0], |
|
75 "Textarea should appear correctly after switching back the direction (" + initialDir + ")"); |
|
76 t.parentNode.removeChild(t); |
|
77 } |
|
78 |
|
79 testDirection("ltr"); |
|
80 testDirection("rtl"); |
|
81 |
|
82 SimpleTest.finish(); |
|
83 }); |
|
84 |
|
85 </script> |
|
86 </pre> |
|
87 </body> |
|
88 </html> |