REGRESSION (r238078): Do not draw caps lock indicator when Strong Password button...
[WebKit-https.git] / LayoutTests / fast / forms / auto-fill-button / caps-lock-indicator-should-be-visible-after-hiding-auto-fill-strong-password-button.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/ui-helper.js"></script>
5 <script>
6 if (window.testRunner)
7     testRunner.waitUntilDone();
8 </script>
9 </head>
10 <body>
11 <p>This tests that the caps lock indicator is visible after hiding the Strong Password AutoFill button. It can only be tested in the test tool.</p>
12 <input type="password" value="A quick brown fox jumped over the lazy dog.">
13 <script>
14 function done()
15 {
16     if (window.testRunner)
17         testRunner.notifyDone();
18 }
19
20 function handleCapsLockEnabled(event)
21 {
22     console.assert(event.key === "CapsLock");
23     let input = document.querySelector("input");
24     internals.setAutofilled(input, false);
25     internals.setShowAutoFillButton(input, "None");
26
27     // Move the caret to the beginning of the field to ensure consistent test results.
28     input.setSelectionRange(0, 0);
29
30     // FIXME: For some reason it takes up to 100ms for the caps lock indicator to be painted (why?).
31     window.setTimeout(done, 100);
32 }
33
34 async function runTest()
35 {
36     if (!window.internals)
37         return;
38
39     let input = document.querySelector("input");
40     internals.setAutofilled(input, true);
41     internals.setShowAutoFillButton(input, "StrongPassword");
42
43     function handleFocus(event) {
44         console.assert(event.target === input);
45         input.addEventListener("keydown", handleCapsLockEnabled, { once: true });
46         UIHelper.toggleCapsLock();
47     }
48     input.addEventListener("focus", handleFocus, { once: true });
49     UIHelper.activateElement(input);
50 }
51
52 runTest();
53 </script>
54 </body>
55 </html>