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
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test no duplicate logins using autofill/autocomplete with related realms</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.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" href="/tests/SimpleTest/test.css"/>
</head>
<body>
Login Manager test: no duplicate logins when using autofill and autocomplete with related realms
<p id="display"></p>
<div id="content"></div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: related realms autofill/autocomplete. **/
function restoreForm(form) {
form.uname.value = "";
form.pword.value = "";
form.uname.focus();
}
function sendFakeAutocompleteEvent(element) {
const acEvent = document.createEvent("HTMLEvents");
acEvent.initEvent("DOMAutoComplete", true, false);
element.dispatchEvent(acEvent);
}
function spinEventLoop() {
return Promise.resolve();
}
async function promiseACPopupClosed() {
return SimpleTest.promiseWaitForCondition(async () => {
const popupState = await getPopupState();
return !popupState.open;
}, "Wait for AC popup to be closed");
}
add_setup(async () => {
await addLoginsInParent(
// Simple related domain relationship where example.com and other-example.com are in the related domains list
["https://other-example.com", "https://other-example.com", null, "relatedUser1", "relatedPass1", "uname", "pword"],
// Example.com and example.co.uk are related, so sub.example.co.uk should appear on example.com's autocomplete dropdown
// The intent is to cover the ebay.com/ebay.co.uk and all other country TLD cases
// where the sign in page is actually signin.ebay.com/signin.ebay.co.uk but credentials could have manually been entered
// for ebay.com/ebay.co.uk or automatically stored as signin.ebay.com/sigin.ebay.co.uk
["https://sub.example.co.uk", "https://sub.example.co.uk", null, "subUser1", "subPass1", "uname", "pword"],
// Ensures there are no duplicates for the exact domain that the user is on
["https://example.com", "https://example.com", null, "exactUser1", "exactPass1", "uname", "pword"],
["https://www.example.com", "https://www.example.com", null, "exactWWWUser1", "exactWWWPass1", "uname", "pword"],
);
listenForUnexpectedPopupShown();
});
add_task(async function test_no_duplicates_autocomplete_autofill() {
const form = createLoginForm({
action: "https://www.example.com"
});
await promiseFormsProcessedInSameProcess();
await SimpleTest.promiseFocus(window);
const results = await popupBy(() => {
checkLoginForm(form.uname, "exactUser1", form.pword, "exactPass1")
restoreForm(form);
});
const popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entires are selected upon opening");
const expectedMenuItems = ["exactUser1", "exactWWWUser1", "relatedUser1", "subUser1"];
checkAutoCompleteResults(results, expectedMenuItems, window.location.host, "Check all menuitems are displayed correctly");
const acEvents = await getTelemetryEvents({ process: "parent", filterProps: TelemetryFilterPropsAC, clear: true });
is(acEvents.length, 1, "One autocomplete event");
checkACTelemetryEvent(acEvents[0], form.uname, {
"hadPrevious": "0",
"login": expectedMenuItems.length + "",
"loginsFooter": "1"
});
restoreForm(form);
synthesizeKey("KEY_Escape");
});
</script>
</pre>
</body>
</html>
|