summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_basic_form_2pw_2.html
blob: a2c60e59642c5c0e77e91fbda3f23c5ca8076c9e (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for form fill with 2 password fields</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
  <script type="text/javascript" src="pwmgr_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: form fill, 2 password fields
<p id="display"></p>

<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Login Manager: form fill, 2 password fields **/

/*
 * If a form has two password fields, other things may be going on....
 *
 * 1 - The user might be creating a new login (2nd field for typo checking)
 * 2 - The user is changing a password (old and new password each have field)
 *
 * This test is for case #1.
 */

var numSubmittedForms = 0;
var numStartingLogins = 0;

function startTest() {
  // Check for unfilled forms
  is(getFormElementByName(1, "uname").value, "", "Checking username 1");
  is(getFormElementByName(1, "pword").value, "", "Checking password 1A");
  is(getFormElementByName(1, "qword").value, "", "Checking password 1B");

  // Fill in the username and password fields, for account creation.
  // Form 1
  SpecialPowers.wrap(getFormElementByName(1, "uname")).setUserInput("newuser1");
  SpecialPowers.wrap(getFormElementByName(1, "pword")).setUserInput("newpass1");
  SpecialPowers.wrap(getFormElementByName(1, "qword")).setUserInput("newpass1");

  // eslint-disable-next-line no-unused-vars
  var button = getFormSubmitButton(1);

  todo(false, "form submission disabled, can't auto-accept dialog yet");
  SimpleTest.finish();
}


// Called by each form's onsubmit handler.
function checkSubmit(formNum) {
  numSubmittedForms++;

  // End the test at the last form.
  if (formNum == 999) {
    is(numSubmittedForms, 999, "Ensuring all forms submitted for testing.");

    (async () => {
      var numEndingLogins = await LoginManager.countLogins("", "", "");

      ok(numEndingLogins > 0, "counting logins at end");
      is(numStartingLogins, numEndingLogins + 222, "counting logins at end");

      SimpleTest.finish();
    })();
    return false; // return false to cancel current form submission
  }

  // submit the next form.
  var button = getFormSubmitButton(formNum + 1);
  button.click();

  return false; // return false to cancel current form submission
}


function getFormSubmitButton(formNum) {
  var form = $("form" + formNum); // by id, not name
  ok(form != null, "getting form " + formNum);

  // we can't just call form.submit(), because that doesn't seem to
  // invoke the form onsubmit handler.
  var button = form.firstChild;
  while (button && button.type != "submit") {
    button = button.nextSibling;
  }
  ok(button != null, "getting form submit button");

  return button;
}

runChecksAfterCommonInit(startTest);

</script>
</pre>
<div id="content" style="display: none">
  <form id="form1" onsubmit="return checkSubmit(1)" action="http://newuser.com">
    <input  type="text"     name="uname">
    <input  type="password" name="pword">
    <input  type="password" name="qword">

    <button type="submit">Submit</button>
    <button type="reset"> Reset </button>
  </form>

</div>

</body>
</html>