|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for Login Manager</title> |
|
5 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="text/javascript" src="pwmgr_common.js"></script> |
|
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
9 </head> |
|
10 <body onload="endTest();"> |
|
11 Login Manager test: 221634 |
|
12 <p id="display"></p> |
|
13 <div id="content" style="display: none"> |
|
14 |
|
15 <form id="form1" action="formtest.js"> |
|
16 <input type="text" name="uname"> |
|
17 <input type="password" name="pword"> |
|
18 |
|
19 <button type="submit">Submit</button> |
|
20 <button type="reset"> Reset</button> |
|
21 </form> |
|
22 |
|
23 <img onload="performTest();" src="mlogosm.gif"> |
|
24 </div> |
|
25 <pre id="test"> |
|
26 <script class="testbody" type="text/javascript"> |
|
27 |
|
28 /** Test for Login Manager: 221634 (password manager needs to fill in forms before the page finishes loading) **/ |
|
29 commonInit(); |
|
30 |
|
31 var dclHappened = false; |
|
32 var testHappened = false; |
|
33 var pageloadHappened = false; |
|
34 |
|
35 // We're still loading the page, so make sure nothing has filled in yet. |
|
36 is($_(1, "uname").value, "", "Checking unfilled username 1"); |
|
37 is($_(1, "pword").value, "", "Checking unfilled password 1"); |
|
38 |
|
39 document.addEventListener("DOMContentLoaded", contentLoaded, false); |
|
40 |
|
41 SimpleTest.waitForExplicitFinish(); |
|
42 |
|
43 |
|
44 // Step 1 - Fires at DOMContentLoaded |
|
45 function contentLoaded() { |
|
46 ok(!testHappened, "Sanity check to ensure test hasn't happened yet.") |
|
47 ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.") |
|
48 |
|
49 // We're in DOMContentLoaded, so the pwmgr may or may not have filled in yet. |
|
50 |
|
51 // Set a 0-second timeout, which should execute before the pageload event. |
|
52 // setTimeout(reallyDoTest, 0); |
|
53 // ha-ha... That doesn't work. The pageload event comes first, although |
|
54 // it can be hacked into working by adding <img src="404_non_existent_file.gif"> |
|
55 |
|
56 dclHappened = true; |
|
57 } |
|
58 |
|
59 // Step 2 - Fires when the image loads, which should be immediately after DOMContentLoaded (but before pageload) |
|
60 function performTest() { |
|
61 ok(dclHappened, "Sanity check to make sure DOMContentLoaded already happened"); |
|
62 ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.") |
|
63 |
|
64 // Check form1 |
|
65 is($_(1, "uname").value, "testuser", "Checking filled username"); |
|
66 is($_(1, "pword").value, "testpass", "Checking filled password"); |
|
67 |
|
68 testHappened = true; |
|
69 } |
|
70 |
|
71 // Step 3 - Fired by |body| onload. |
|
72 function endTest() { |
|
73 ok(dclHappened, "Sanity check to make sure DOMContentLoaded already happened"); |
|
74 ok(testHappened, "Sanity check to make sure our test ran before pageload"); |
|
75 |
|
76 // Check form1 |
|
77 is($_(1, "uname").value, "testuser", "Rechecking filled username"); |
|
78 is($_(1, "pword").value, "testpass", "Rechecking filled password"); |
|
79 |
|
80 pageloadHappened = true; |
|
81 |
|
82 // Make sure the expected number of tests (for this page) have run. |
|
83 // If the event execution gets out of order, only a subset get counted. |
|
84 // (Although there should still be other failures... Belt-n-suspenders!) |
|
85 is(SimpleTest._tests.length, 12, "expected number of executed tests"); |
|
86 |
|
87 SimpleTest.finish(); |
|
88 } |
|
89 |
|
90 </script> |
|
91 |
|
92 </pre> |
|
93 </body> |
|
94 </html> |
|
95 |