summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
blob: ae4586f1bbee8fe8ae90cc6c5567d1396d4b53b8 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test login autocomplete is activated when focused by js on load</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" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>

<div id="content">
  <iframe></iframe>
</div>

<pre id="test">
<script class="testbody" type="text/javascript">
const iframe = document.getElementsByTagName("iframe")[0];
let iframeDoc, hostname;

add_setup(async () => {
  SpecialPowers.pushPrefEnv({"set": [["signon.webauthn.autocomplete", false]]});

  const origin = window.location.origin;
  await setStoredLoginsAsync(
    [origin, origin, null, "name", "pass"],
    [origin, origin, null, "name1", "pass1"]
  );

  const processedPromise = promiseFormsProcessed();
  iframe.src = "/tests/toolkit/components/passwordmgr/test/mochitest/form_autofocus_js.html";
  await new Promise(resolve => {
    iframe.addEventListener("load", function() {
      resolve();
    }, {once: true});
  });

  await processedPromise;

  hostname = await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    return this.content.document.documentURIObject.host;
  });

  SimpleTest.requestFlakyTimeout("Giving a chance for the unexpected popupshown to occur");
});

add_task(async function test_initial_focus() {
  let results = await notifyMenuChanged(3, "name");
  checkAutoCompleteResults(results, ["name", "name1"], hostname, "Two login results");
  synthesizeKey("KEY_ArrowDown");
  synthesizeKey("KEY_Enter");
  await promiseFormsProcessedInSameProcess();
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    Assert.equal(this.content.document.getElementById("form-basic-password").value, "pass", "Check first password filled");
  });
  let popupState = await getPopupState();
  is(popupState.open, false, "Check popup is now closed");
});

// This depends on the filling from the previous test.
add_task(async function test_not_reopened_if_filled() {
  listenForUnexpectedPopupShown();
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    this.content.document.getElementById("form-basic-username").focus();
  });
  info("Waiting to see if a popupshown occurs");
  await new Promise(resolve => setTimeout(resolve, 1000));

  // cleanup
  gPopupShownExpected = true;
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    this.content.document.getElementById("form-basic-submit").focus();
  });
});

add_task(async function test_reopened_after_edit_not_matching_saved() {
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    this.content.document.getElementById("form-basic-username").value = "nam";
  });
  await popupBy(async () => {
    await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
      this.content.document.getElementById("form-basic-username").focus();
    });
  });
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    this.content.document.getElementById("form-basic-submit").focus();
  });
});

add_task(async function test_not_reopened_after_selecting() {
  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    this.content.document.getElementById("form-basic-username").value = "";
    this.content.document.getElementById("form-basic-password").value = "";
  });
  listenForUnexpectedPopupShown();

  await SpecialPowers.spawn(getIframeBrowsingContext(window), [], function() {
    const actor = content.windowGlobalChild.getActor("AutoComplete");
    let usernameField = this.content.document.getElementById("form-basic-username");
    actor.markAsAutoCompletableField(usernameField);
  });

  info("Waiting to see if a popupshown occurs");
  await new Promise(resolve => setTimeout(resolve, 1000));

  // Cleanup
  gPopupShownExpected = true;
});

</script>
</pre>
</body>
</html>