toolkit/components/passwordmgr/test/test_bug_221634.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/passwordmgr/test/test_bug_221634.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for Login Manager</title>
     1.8 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>  
    1.10 +  <script type="text/javascript" src="pwmgr_common.js"></script>  
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body onload="endTest();">
    1.14 +Login Manager test: 221634
    1.15 +<p id="display"></p>
    1.16 +<div id="content" style="display: none">
    1.17 +
    1.18 +  <form id="form1" action="formtest.js">
    1.19 +    <input  type="text"       name="uname">
    1.20 +    <input  type="password"   name="pword">
    1.21 +
    1.22 +    <button type="submit">Submit</button>
    1.23 +    <button type="reset"> Reset</button>
    1.24 +  </form>
    1.25 +  
    1.26 +  <img onload="performTest();" src="mlogosm.gif">
    1.27 +</div>
    1.28 +<pre id="test">
    1.29 +<script class="testbody" type="text/javascript">
    1.30 +
    1.31 +/** Test for Login Manager: 221634 (password manager needs to fill in forms before the page finishes loading) **/
    1.32 +commonInit();
    1.33 +
    1.34 +var dclHappened      = false;
    1.35 +var testHappened     = false;
    1.36 +var pageloadHappened = false;
    1.37 +
    1.38 +// We're still loading the page, so make sure nothing has filled in yet.
    1.39 +is($_(1, "uname").value, "", "Checking unfilled username 1");
    1.40 +is($_(1, "pword").value, "", "Checking unfilled password 1");
    1.41 +
    1.42 +document.addEventListener("DOMContentLoaded", contentLoaded, false);
    1.43 +
    1.44 +SimpleTest.waitForExplicitFinish();
    1.45 +
    1.46 +
    1.47 +// Step 1 - Fires at DOMContentLoaded
    1.48 +function contentLoaded() {
    1.49 +  ok(!testHappened,     "Sanity check to ensure test hasn't happened yet.")
    1.50 +  ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.")
    1.51 +
    1.52 +  // We're in DOMContentLoaded, so the pwmgr may or may not have filled in yet.
    1.53 +
    1.54 +  // Set a 0-second timeout, which should execute before the pageload event.
    1.55 +  // setTimeout(reallyDoTest, 0);
    1.56 +  // ha-ha... That doesn't work. The pageload event comes first, although
    1.57 +  // it can be hacked into working by adding <img src="404_non_existent_file.gif">
    1.58 +
    1.59 +  dclHappened = true;
    1.60 +}
    1.61 +
    1.62 +// Step 2 - Fires when the image loads, which should be immediately after DOMContentLoaded (but before pageload)
    1.63 +function performTest() {
    1.64 +  ok(dclHappened,       "Sanity check to make sure DOMContentLoaded already happened");
    1.65 +  ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.")
    1.66 +
    1.67 +  // Check form1
    1.68 +  is($_(1, "uname").value, "testuser", "Checking filled username");
    1.69 +  is($_(1, "pword").value, "testpass", "Checking filled password");
    1.70 +
    1.71 +  testHappened = true;
    1.72 +}
    1.73 +
    1.74 +// Step 3 - Fired by |body| onload.
    1.75 +function endTest() {
    1.76 +  ok(dclHappened, "Sanity check to make sure DOMContentLoaded already happened");
    1.77 +  ok(testHappened, "Sanity check to make sure our test ran before pageload");
    1.78 +  
    1.79 +  // Check form1
    1.80 +  is($_(1, "uname").value, "testuser", "Rechecking filled username");
    1.81 +  is($_(1, "pword").value, "testpass", "Rechecking filled password");
    1.82 +
    1.83 +  pageloadHappened = true;
    1.84 +
    1.85 +  // Make sure the expected number of tests (for this page) have run.
    1.86 +  // If the event execution gets out of order, only a subset get counted.
    1.87 +  // (Although there should still be other failures... Belt-n-suspenders!)
    1.88 +  is(SimpleTest._tests.length, 12, "expected number of executed tests");
    1.89 +
    1.90 +  SimpleTest.finish();
    1.91 +}
    1.92 +
    1.93 +</script>
    1.94 +
    1.95 +</pre>
    1.96 +</body>
    1.97 +</html>
    1.98 +

mercurial