summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_hasBeenTypePassword_navigation.html
blob: 70a0f8427e31b8d0fb9bd3555c8535468bef99cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1330228
-->
<head>
  <title>Test hasBeenTypePassword is used with bfcache</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1330228">Mozilla Bug 1330228</a>
<p id="display">
  <iframe id="testframe" src="file_login_fields.html"></iframe>
</p>
<pre id="test">
<script type="application/javascript">

/** Test hasBeenTypePassword is used with bfcache **/
SimpleTest.waitForExplicitFinish();

function afterLoad() {
  var iframeDoc = $("testframe").contentDocument;

  /* change all the form controls */
  iframeDoc.getElementById("un").value = "username";
  iframeDoc.getElementById("pw1").value = "password1";

  // Convert pw2 to a password field temporarily to test hasBeenTypePassword.
  // We don't want the initial or final value to be type=password or we may
  // not test the right scenario.
  iframeDoc.getElementById("pw2").type = "password";
  iframeDoc.getElementById("pw2").value = "password2";
  iframeDoc.getElementById("pw2").type = "";

  /* navigate the page */
  $("testframe").setAttribute("onload", "afterNavigation()");
  // Use a click on an <a> so that the current page is included in session history.
  iframeDoc.getElementById("navigate").click();
}

addLoadEvent(afterLoad);

function afterNavigation() {
  info("Navigated to a new document");
  var iframeDoc = $("testframe").contentDocument;
  $("testframe").setAttribute("onload", "afterBack()");
  // Calling `history.back()` on the contentWindow from here doesn't use bfcache
  // so call it from within the contentDocument.
  iframeDoc.getElementById("back").click();
}

function afterBack() {
  info("Should be back showing the first document from bfcache");
  var iframeDoc = $("testframe").contentDocument;

  is(iframeDoc.getElementById("un").value, "username",
     "username field value remembered");
  is(iframeDoc.getElementById("pw1").value, "",
     "type=password field value not remembered");
  is(iframeDoc.getElementById("pw2").value, "",
     "former type=password field value not remembered");
  SimpleTest.finish();
}
</script>
</pre>
</body>
</html>