widget/tests/test_secure_input.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/test_secure_input.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for secure input mode</title>
     1.8 +  <script type="text/javascript"
     1.9 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <script type="text/javascript"
    1.11 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    1.12 +  <script type="text/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
    1.14 +  <script type="text/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
    1.16 +  <link rel="stylesheet" type="text/css"
    1.17 +          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.18 +</head>
    1.19 +<body>
    1.20 +<div id="content" style="display: none">
    1.21 +  
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +</pre>
    1.25 +
    1.26 +<p>
    1.27 +  <input id="input_text" type="text"><br>
    1.28 +  <input id="input_password" type="password"><br>
    1.29 +  <input id="input_text_readonly" type="text" readonly><br>
    1.30 +  <input id="input_text_ime_mode_disabled" type="text" style="ime-mode: disabled;"><br>
    1.31 +  <input id="input_change" type="text"><br>
    1.32 +  <textarea id="textarea"></textarea><br>
    1.33 +</p>
    1.34 +<div id="contenteditable" contenteditable style="min-height: 3em;"></div>
    1.35 +
    1.36 +<script class="testbody" type="application/javascript">
    1.37 +
    1.38 +  SimpleTest.waitForExplicitFinish();
    1.39 +
    1.40 +  function sendAKeyEvent()
    1.41 +  {
    1.42 +    synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, MAC_VK_ANSI_A, {}, "a", "a");
    1.43 +  }
    1.44 +
    1.45 +  function isFocused(aElement)
    1.46 +  {
    1.47 +    return (SpecialPowers.focusManager.focusedElement == aElement);
    1.48 +  }
    1.49 +
    1.50 +  function runTest()
    1.51 +  {
    1.52 +    sendAKeyEvent();
    1.53 +    ok(true, "Not crashed: input on the document");
    1.54 +    $("input_text").focus();
    1.55 +    sendAKeyEvent();
    1.56 +    ok(true, "Not crashed: input on <input type=\"text\">");
    1.57 +    $("input_password").focus();
    1.58 +    sendAKeyEvent();
    1.59 +    ok(true, "Not crashed: input on <input type=\"password\">");
    1.60 +    $("input_password").blur();
    1.61 +    sendAKeyEvent();
    1.62 +    ok(true, "Not crashed: input on the document after blur() of <input type=\"password\">");
    1.63 +    $("input_password").focus();
    1.64 +    $("input_text_readonly").focus();
    1.65 +    sendAKeyEvent();
    1.66 +    ok(true, "Not crashed: input on <input type=\"text\" readonly>");
    1.67 +    $("input_password").focus();
    1.68 +    $("input_text_ime_mode_disabled").focus();
    1.69 +    sendAKeyEvent();
    1.70 +    ok(true, "Not crashed: input on <input type=\"text\" style=\"ime-mode: disabled;\">");
    1.71 +    $("input_password").focus();
    1.72 +    $("textarea").focus();
    1.73 +    sendAKeyEvent();
    1.74 +    ok(true, "Not crashed: input on <textarea>");
    1.75 +    $("input_password").focus();
    1.76 +    $("contenteditable").focus();
    1.77 +    sendAKeyEvent();
    1.78 +    ok(true, "Not crashed: input on <div contenteditable>");
    1.79 +
    1.80 +    $("input_change").focus();
    1.81 +    $("input_change").type = "password";
    1.82 +    sendAKeyEvent();
    1.83 +    ok(true, "Not crashed: input on <input type=\"password\"> changed from type=\"text\"");
    1.84 +    $("input_change").type = "text";
    1.85 +    sendAKeyEvent();
    1.86 +    ok(true, "Not crashed: input on <input type=\"text\"> changed from type=\"password\"");
    1.87 +
    1.88 +    otherWindow =
    1.89 +      window.open("data:text/html,<input id=\"text\" type\"text\"><input id=\"password\" type\"password\">",
    1.90 +                  "_blank", "chrome,width=100,height=100");
    1.91 +    ok(otherWindow, "failed to open other window");
    1.92 +    if (!otherWindow) {
    1.93 +      SimpleTest.finish();
    1.94 +      return;
    1.95 +    }
    1.96 +
    1.97 +    $("input_text").focus();
    1.98 +    otherWindow.focus();
    1.99 +
   1.100 +    SimpleTest.waitForFocus(function () {
   1.101 +      window.focus();
   1.102 +      sendAKeyEvent();
   1.103 +      ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">");
   1.104 +      ok(true, "Not crashed: input on <input type=\"text\"> after the other document has focus");
   1.105 +
   1.106 +      $("input_password").focus();
   1.107 +      otherWindow.focus();
   1.108 +      window.focus();
   1.109 +      sendAKeyEvent();
   1.110 +      ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">");
   1.111 +      ok(true, "Not crashed: input on <input type=\"password\"> after the other document has focus");
   1.112 +
   1.113 +      $("input_text").focus();
   1.114 +      otherWindow.focus();
   1.115 +      otherWindow.document.getElementById("text").focus();
   1.116 +      window.focus();
   1.117 +      sendAKeyEvent();
   1.118 +      ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">");
   1.119 +      ok(true, "Not crashed: input on <input type=\"text\"> after the other document's <input type=\"text\"> has focus");
   1.120 +
   1.121 +      $("input_password").focus();
   1.122 +      otherWindow.focus();
   1.123 +      otherWindow.document.getElementById("text").focus();
   1.124 +      window.focus();
   1.125 +      sendAKeyEvent();
   1.126 +      ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">");
   1.127 +      ok(true, "Not crashed: input on <input type=\"password\"> after the other document's <input type=\"text\"> has focus");
   1.128 +
   1.129 +      $("input_text").focus();
   1.130 +      otherWindow.focus();
   1.131 +      otherWindow.document.getElementById("password").focus();
   1.132 +      window.focus();
   1.133 +      sendAKeyEvent();
   1.134 +      ok(isFocused($("input_text")), "focused element isn't <input type=\"text\">");
   1.135 +      ok(true, "Not crashed: input on <input type=\"text\"> after the other document's <input type=\"password\"> has focus");
   1.136 +
   1.137 +      $("input_password").focus();
   1.138 +      otherWindow.focus();
   1.139 +      otherWindow.document.getElementById("password").focus();
   1.140 +      window.focus();
   1.141 +      sendAKeyEvent();
   1.142 +      ok(isFocused($("input_password")), "focused element isn't <input type=\"password\">");
   1.143 +      ok(true, "Not crashed: input on <input type=\"password\"> after the other document's <input type=\"password\"> has focus");
   1.144 +
   1.145 +      SimpleTest.finish();
   1.146 +
   1.147 +    }, otherWindow);
   1.148 +  }
   1.149 +
   1.150 +  SimpleTest.waitForFocus(runTest);
   1.151 +</script>
   1.152 +</body>
   1.153 +</html>

mercurial