widget/tests/test_secure_input.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial