summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
blob: 316f59da767a7e9f5571195885f4c52b5749f7ab (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
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autocomplete due to multiple matching logins</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
  <script type="text/javascript" src="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: autocomplete due to multiple matching logins

<script>
runChecksAfterCommonInit(false);

SpecialPowers.loadChromeScript(function addLogins() {
  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
  Cu.import("resource://gre/modules/Services.jsm");

  // Create some logins just for this form, since we'll be deleting them.
  var nsLoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
                                           Ci.nsILoginInfo, "init");

  var login0 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
                               "name", "pass", "uname", "pword");

  var login1 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
                               "Name", "Pass", "uname", "pword");

  var login2 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
                               "USER", "PASS", "uname", "pword");

  try {
    Services.logins.addLogin(login0);
    Services.logins.addLogin(login1);
    Services.logins.addLogin(login2);
  } catch (e) {
    assert.ok(false, "addLogin threw: " + e);
  }
});
</script>
<p id="display"></p>

<!-- we presumably can't hide the content for this test. -->
<div id="content">

  <!-- form1 tests multiple matching logins -->
  <form id="form1" action="http://autocomplete:8888/formtest.js" onsubmit="return false;">
    <input  type="text"       name="uname">
    <input  type="password"   name="pword">
    <button type="submit">Submit</button>
  </form>

</div>

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

/** Test for Login Manager: autocomplete due to multiple matching logins **/

var uname = $_(1, "uname");
var pword = $_(1, "pword");

// Restore the form to the default state.
function restoreForm() {
    uname.value = "";
    pword.value = "";
    uname.focus();
}

// Check for expected username/password in form.
function checkACForm(expectedUsername, expectedPassword) {
  var formID = uname.parentNode.id;
  is(uname.value, expectedUsername, "Checking " + formID + " username");
  is(pword.value, expectedPassword, "Checking " + formID + " password");
}

add_task(function* test_empty_first_entry() {
  /* test 1 */
  // Make sure initial form is empty.
  checkACForm("", "");
  // Trigger autocomplete popup
  restoreForm();
  let popupState = yield getPopupState();
  is(popupState.open, false, "Check popup is initially closed");
  let shownPromise = promiseACShown();
  doKey("down");
  let results = yield shownPromise;
  popupState = yield getPopupState();
  is(popupState.selectedIndex, -1, "Check no entries are selected");
  checkArrayValues(results, ["name", "Name", "USER"], "initial");

  // Check first entry
  let index0Promise = notifySelectedIndex(0);
  doKey("down");
  yield index0Promise;
  checkACForm("", ""); // value shouldn't update
  doKey("return"); // not "enter"!
  yield promiseFormsProcessed();
  checkACForm("name", "pass");
});

add_task(function* test_empty_second_entry() {
  restoreForm();
  let shownPromise = promiseACShown();
  doKey("down"); // open
  yield shownPromise;
  doKey("down"); // first
  doKey("down"); // second
  doKey("return"); // not "enter"!
  yield promiseFormsProcessed();
  checkACForm("Name", "Pass");
});

add_task(function* test_empty_third_entry() {
  restoreForm();
  let shownPromise = promiseACShown();
  doKey("down"); // open
  yield shownPromise;
  doKey("down"); // first
  doKey("down"); // second
  doKey("down"); // third
  doKey("return");
  yield promiseFormsProcessed();
  checkACForm("USER", "PASS");
});

add_task(function* test_preserve_matching_username_case() {
  restoreForm();
  uname.value = "user";
  let shownPromise = promiseACShown();
  doKey("down"); // open
  yield shownPromise;

  // Check that we don't clobber user-entered text when tabbing away
  // (even with no autocomplete entry selected)
  doKey("tab");
  yield promiseFormsProcessed();
  checkACForm("user", "PASS");
});
</script>
</pre>
</body>
</html>