summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autofill_password-only.html
blob: 755a1f3f1d3bf921951a14a211b273ef344c541a (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test password-only forms should prefer a password-only login when present</title>
  <script 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>
Login Manager test: Bug 444968
<script>
PWMGR_COMMON_PARENT.sendAsyncMessage("setupParent", { selfFilling: true });

SimpleTest.waitForExplicitFinish();

const chromeScript = runInParent(async function chromeSetup() {
  const login1A = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
  const login1B = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
  const login2A = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
  const login2B = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
  const login2C = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);

  login1A.init("http://mochi.test:8888", "http://bug444968-1", null, "testuser1A", "testpass1A", "", "");
  login1B.init("http://mochi.test:8888", "http://bug444968-1", null, "", "testpass1B", "", "");

  login2A.init("http://mochi.test:8888", "http://bug444968-2", null, "testuser2A", "testpass2A", "", "");
  login2B.init("http://mochi.test:8888", "http://bug444968-2", null, "", "testpass2B", "", "");
  login2C.init("http://mochi.test:8888", "http://bug444968-2", null, "testuser2C", "testpass2C", "", "");

  await Services.logins.addLogins([
    login1A,
    login1B,
    login2A,
    login2B,
    login2C,
  ]);

  addMessageListener("removeLogins", function removeLogins() {
    Services.logins.removeLogin(login1A);
    Services.logins.removeLogin(login1B);
    Services.logins.removeLogin(login2A);
    Services.logins.removeLogin(login2B);
    Services.logins.removeLogin(login2C);
  });
});

SimpleTest.registerCleanupFunction(() => chromeScript.sendAsyncMessage("removeLogins"));

registerRunTests();
</script>

<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const DEFAULT_ORIGIN = window.location.origin;

/* Test for Login Manager: 444968 (password-only forms should prefer a
 * password-only login when present )
 */
async function startTest() {
  const win = window.open("about:blank");
  SimpleTest.registerCleanupFunction(() => win.close());
  await loadFormIntoWindow(DEFAULT_ORIGIN, `
    <!-- first 3 forms have matching user+pass and pass-only logins -->

    <!-- user+pass form. -->
    <form id="form1" action="http://bug444968-1">
      <input  type="text"     name="uname">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>

    <!-- password-only form. -->
    <form id="form2" action="http://bug444968-1">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>

    <!-- user+pass form, username prefilled -->
    <form id="form3" action="http://bug444968-1">
      <input  type="text"     name="uname" value="testuser1A">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>


    <!-- next 4 forms have matching user+pass (2x) and pass-only (1x) logins -->

    <!-- user+pass form. -->
    <form id="form4" action="http://bug444968-2">
      <input  type="text"     name="uname">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>

    <!-- password-only form. -->
    <form id="form5" action="http://bug444968-2">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>

    <!-- user+pass form, username prefilled -->
    <form id="form6" action="http://bug444968-2">
      <input  type="text"     name="uname" value="testuser2A">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>

    <!-- user+pass form, username prefilled -->
    <form id="form7" action="http://bug444968-2">
      <input  type="text"     name="uname" value="testuser2C">
      <input  type="password" name="pword">
      <button type="submit">Submit</button>
    </form>`, win, 7);

  await checkLoginFormInFrameWithElementValues(win, 1, "testuser1A", "testpass1A");
  await checkLoginFormInFrameWithElementValues(win, 2, "testpass1B");
  await checkLoginFormInFrameWithElementValues(win, 3, "testuser1A", "testpass1A");

  checkUnmodifiedFormInFrame(win, 4); // 2 logins match
  await checkLoginFormInFrameWithElementValues(win, 5, "testpass2B");
  await checkLoginFormInFrameWithElementValues(win, 6, "testuser2A", "testpass2A");
  await checkLoginFormInFrameWithElementValues(win, 7, "testuser2C", "testpass2C");

  SimpleTest.finish();
}

window.addEventListener("runTests", startTest);
</script>
</pre>
</body>
</html>