gecko/toolkit/components/passwordmgr/test/test_bug_221634.html

95 lines
3.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Login Manager</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="endTest();">
Login Manager test: 221634
<p id="display"></p>
<div id="content" style="display: none">
<form id="form1" action="formtest.js">
<input type="text" name="uname">
<input type="password" name="pword">
<button type="submit">Submit</button>
<button type="reset"> Reset</button>
</form>
<img onload="performTest();" src="mlogosm.gif">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: 221634 (password manager needs to fill in forms before the page finishes loading) **/
var dclHappened = false;
var testHappened = false;
var pageloadHappened = false;
// We're still loading the page, so make sure nothing has filled in yet.
is($_(1, "uname").value, "", "Checking unfilled username 1");
is($_(1, "pword").value, "", "Checking unfilled password 1");
document.addEventListener("DOMContentLoaded", contentLoaded, false);
SimpleTest.waitForExplicitFinish();
// Step 1 - Fires at DOMContentLoaded
function contentLoaded() {
ok(!testHappened, "Sanity check to ensure test hasn't happened yet.")
ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.")
// We're in DOMContentLoaded, so the pwmgr may or may not have filled in yet.
// Set a 0-second timeout, which should execute before the pageload event.
// setTimeout(reallyDoTest, 0);
// ha-ha... That doesn't work. The pageload event comes first, although
// it can be hacked into working by adding <img src="404_non_existant_file.gif">
dclHappened = true;
}
// Step 2 - Fires when the image loads, which should be immediately after DOMContentLoaded (but before pageload)
function performTest() {
ok(dclHappened, "Sanity check to make sure DOMContentLoaded already happened");
ok(!pageloadHappened, "Sanity check to ensure pageload hasn't happened yet.")
// Check form1
is($_(1, "uname").value, "testuser", "Checking filled username");
is($_(1, "pword").value, "testpass", "Checking filled password");
testHappened = true;
}
// Step 3 - Fired by |body| onload.
function endTest() {
ok(dclHappened, "Sanity check to make sure DOMContentLoaded already happened");
ok(testHappened, "Sanity check to make sure our test ran before pageload");
// Check form1
is($_(1, "uname").value, "testuser", "Rechecking filled username");
is($_(1, "pword").value, "testpass", "Rechecking filled password");
pageloadHappened = true;
// Make sure the expected number of tests (for this page) have run.
// If the event execution gets out of order, only a subset get counted.
// (Although there should still be other failures... Belt-n-suspenders!)
is(SimpleTest._tests.length, 12, "expected number of executed tests");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>