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