|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for secure input mode</title> |
|
5 <script type="text/javascript" |
|
6 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="text/javascript" |
|
8 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
9 <script type="text/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script> |
|
11 <script type="text/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> |
|
13 <link rel="stylesheet" type="text/css" |
|
14 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
15 </head> |
|
16 <body> |
|
17 <div id="content" style="display: none"> |
|
18 |
|
19 </div> |
|
20 <pre id="test"> |
|
21 </pre> |
|
22 |
|
23 <p> |
|
24 <input id="input_text" type="text"><br> |
|
25 <input id="input_password" type="password"><br> |
|
26 <input id="input_text_readonly" type="text" readonly><br> |
|
27 <input id="input_text_ime_mode_disabled" type="text" style="ime-mode: disabled;"><br> |
|
28 <input id="input_change" type="text"><br> |
|
29 <textarea id="textarea"></textarea><br> |
|
30 </p> |
|
31 <div id="contenteditable" contenteditable style="min-height: 3em;"></div> |
|
32 |
|
33 <script class="testbody" type="application/javascript"> |
|
34 |
|
35 SimpleTest.waitForExplicitFinish(); |
|
36 |
|
37 function sendAKeyEvent() |
|
38 { |
|
39 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {}, "a", "a"); |
|
40 } |
|
41 |
|
42 function isFocused(aElement) |
|
43 { |
|
44 return (SpecialPowers.focusManager.focusedElement == aElement); |
|
45 } |
|
46 |
|
47 function runTest() |
|
48 { |
|
49 sendAKeyEvent(); |
|
50 ok(true, "Not crashed: input on the document"); |
|
51 $("input_text").focus(); |
|
52 sendAKeyEvent(); |
|
53 ok(true, "Not crashed: input on <input type=\"text\">"); |
|
54 $("input_password").focus(); |
|
55 sendAKeyEvent(); |
|
56 ok(true, "Not crashed: input on <input type=\"password\">"); |
|
57 $("input_password").blur(); |
|
58 sendAKeyEvent(); |
|
59 ok(true, "Not crashed: input on the document after blur() of <input type=\"password\">"); |
|
60 $("input_password").focus(); |
|
61 $("input_text_readonly").focus(); |
|
62 sendAKeyEvent(); |
|
63 ok(true, "Not crashed: input on <input type=\"text\" readonly>"); |
|
64 $("input_password").focus(); |
|
65 $("input_text_ime_mode_disabled").focus(); |
|
66 sendAKeyEvent(); |
|
67 ok(true, "Not crashed: input on <input type=\"text\" style=\"ime-mode: disabled;\">"); |
|
68 $("input_password").focus(); |
|
69 $("textarea").focus(); |
|
70 sendAKeyEvent(); |
|
71 ok(true, "Not crashed: input on <textarea>"); |
|
72 $("input_password").focus(); |
|
73 $("contenteditable").focus(); |
|
74 sendAKeyEvent(); |
|
75 ok(true, "Not crashed: input on <div contenteditable>"); |
|
76 |
|
77 $("input_change").focus(); |
|
78 $("input_change").type = "password"; |
|
79 sendAKeyEvent(); |
|
80 ok(true, "Not crashed: input on <input type=\"password\"> changed from type=\"text\""); |
|
81 $("input_change").type = "text"; |
|
82 sendAKeyEvent(); |
|
83 ok(true, "Not crashed: input on <input type=\"text\"> changed from type=\"password\""); |
|
84 |
|
85 otherWindow = |
|
86 window.open("data:text/html,<input id=\"text\" type\"text\"><input id=\"password\" type\"password\">", |
|
87 "_blank", "chrome,width=100,height=100"); |
|
88 ok(otherWindow, "failed to open other window"); |
|
89 if (!otherWindow) { |
|
90 SimpleTest.finish(); |
|
91 return; |
|
92 } |
|
93 |
|
94 $("input_text").focus(); |
|
95 otherWindow.focus(); |
|
96 |
|
97 SimpleTest.waitForFocus(function () { |
|
98 window.focus(); |
|
99 sendAKeyEvent(); |
|
100 ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">"); |
|
101 ok(true, "Not crashed: input on <input type=\"text\"> after the other document has focus"); |
|
102 |
|
103 $("input_password").focus(); |
|
104 otherWindow.focus(); |
|
105 window.focus(); |
|
106 sendAKeyEvent(); |
|
107 ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">"); |
|
108 ok(true, "Not crashed: input on <input type=\"password\"> after the other document has focus"); |
|
109 |
|
110 $("input_text").focus(); |
|
111 otherWindow.focus(); |
|
112 otherWindow.document.getElementById("text").focus(); |
|
113 window.focus(); |
|
114 sendAKeyEvent(); |
|
115 ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">"); |
|
116 ok(true, "Not crashed: input on <input type=\"text\"> after the other document's <input type=\"text\"> has focus"); |
|
117 |
|
118 $("input_password").focus(); |
|
119 otherWindow.focus(); |
|
120 otherWindow.document.getElementById("text").focus(); |
|
121 window.focus(); |
|
122 sendAKeyEvent(); |
|
123 ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">"); |
|
124 ok(true, "Not crashed: input on <input type=\"password\"> after the other document's <input type=\"text\"> has focus"); |
|
125 |
|
126 $("input_text").focus(); |
|
127 otherWindow.focus(); |
|
128 otherWindow.document.getElementById("password").focus(); |
|
129 window.focus(); |
|
130 sendAKeyEvent(); |
|
131 ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">"); |
|
132 ok(true, "Not crashed: input on <input type=\"text\"> after the other document's <input type=\"password\"> has focus"); |
|
133 |
|
134 $("input_password").focus(); |
|
135 otherWindow.focus(); |
|
136 otherWindow.document.getElementById("password").focus(); |
|
137 window.focus(); |
|
138 sendAKeyEvent(); |
|
139 ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">"); |
|
140 ok(true, "Not crashed: input on <input type=\"password\"> after the other document's <input type=\"password\"> has focus"); |
|
141 |
|
142 SimpleTest.finish(); |
|
143 |
|
144 }, otherWindow); |
|
145 } |
|
146 |
|
147 SimpleTest.waitForFocus(runTest); |
|
148 </script> |
|
149 </body> |
|
150 </html> |