summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_autofill_related_realms_no_dupes.html
blob: b229993a4207c53f479eff9e5eff0e5b0a4af7c3 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Login Manager: Related Realms</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" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content"></div>
<pre id="test">
Testing related realms

Related realms is feature to provide login suggestion based on similar domains.

Out of the scope of this feature is subdomain handling, which is already part
of the base functionality. 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

The related realms feature can be enabled via the preference
signon.relatedRealms.enabled. It is disabled by default.

This test proves that related logins show up in the autocomplete menu when
the feature is enabled and that the related logins do not count as duplicates
and therefore the form gets filled directly.

<template id="form1-template">
  <form id="form1" action="https://www.example.com">
    <input type="text" name="uname">
    <input type="password" name="pword">
  </form>
</template>

<script class="testbody" type="text/javascript">
  const formTemplate = document.getElementById("form1-template");

  add_setup(async () => {
    await setStoredLoginsDuringTest(
      ["https://example.com", "https://example.com", null, "example.com-user", "password", "uname", "pword"],

      // 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, "other-example.com-user", "password", "uname", "pword"],

      // example.com and example.co.uk are related, so sub.example.co.uk is also related
      ["https://sub.example.co.uk", "https://sub.example.co.uk", null, "sub.example.co.uk-user", "password", "uname", "pword"],

      // www subdomain on same TLD
      ["https://www.example.com", "https://www.example.com", null, "www.example.com-user", "password", "uname", "pword"],

      // other subdomain on same TLD
      ["https://sub.example.com", "https://sub.example.com", null, "sub.example.com-user", "password", "uname", "pword"],
    );
  });

  add_named_task("with relatedRealms disabled, related logins do not show up in autocomplete menu", async () => {
    await setPreferencesForTask(["signon.relatedRealms.enabled", false]);

    const form = setContentForTask(formTemplate);

    const autofillResult = await formAutofillResult(form.id);
    is(autofillResult, "filled", "form has been filled");

    // reset the form and open autocomplete popup by focusing username input
    form.reset();
    const results = await popupBy(() => form.uname.focus());
    checkAutoCompleteResults(results, [
      "example.com-user",
      "sub.example.com-user",
      "www.example.com-user",
    ], window.location.host, "all logins are present and in order");
  });

  add_named_task("with relatedRealms enabled, related logins show up in autocomplete menu", async () => {
    await setPreferencesForTask(["signon.relatedRealms.enabled", true]);

    const form = setContentForTask(formTemplate);

    const result = await formAutofillResult(form.id);
    is(result, "filled", "form has been filled");

    // reset the form and open autocomplete popup by focusing username input
    form.reset();
    const results = await popupBy(() => form.uname.focus());
    checkAutoCompleteResults(results, [
      "example.com-user",
      "other-example.com-user",
      "sub.example.co.uk-user",
      "sub.example.com-user",
      "www.example.com-user",
    ], window.location.host, "all logins are present and in order");
  });

  add_named_task("even with relatedRealms enabled, related logins are not considered duplicates, so form will be filled", async () => {
    await setPreferencesForTask(["signon.relatedRealms.enabled", true]);

    const form = setContentForTask(formTemplate);

    const autofillResult = await formAutofillResult(form.id);
    is(autofillResult, "filled", "form has been filled");

    is(form.uname.value, "example.com-user", "username from exact tld is filled in");
  });
</script>
</pre>
</body>
</html>