Add support of setPasswordEchoEnabled and setPasswordEchoDuration for password echo...
[WebKit-https.git] / LayoutTests / editing / input / resources / password-echo.js
1 var testnode;
2
3 function secureChar()
4 {
5     var element = testnode;
6     var securechar = document.defaultView.getComputedStyle(element, "").getPropertyValue("-webkit-text-security");
7     switch(securechar) {
8     case "square":
9         return String.fromCharCode(0x25A0);
10     case "disc":
11         return String.fromCharCode(0x2022);
12     case "circle":
13         return String.fromCharCode(0x25E6);
14     }
15 }
16
17 function secureText(textLength)
18 {
19     var text = "";
20     for (var counter = 0; counter < textLength; counter++)
21         text += secureChar();
22     return text;
23 }
24
25 function log(msg)
26 {
27     var console = document.getElementById("console");
28     var li = document.createElement("li");
29     li.appendChild(document.createTextNode(msg));
30     console.appendChild(li);
31 }
32
33 function assert(expected, actual, msg)
34 {
35     if (expected != actual)
36         log("Error: " + msg + " expected=" + expected + ", actual=" + actual);
37     else
38         log("Success: " + msg + " expected=" + expected + ", actual=" + actual);
39 }
40
41 function run(tests, testIdx)
42 {
43     var expectedSecureTextLen;
44     if (testIdx >= 0) {
45         textInputController.doCommand("moveForward:");
46         if(tests[testIdx][3])
47             assert(tests[testIdx][2], window.find(secureText(testnode.value.length), false, true), "secured after delay.");
48     }
49     testIdx++;
50     if (testIdx >= tests.length) {
51         layoutTestController.notifyDone();
52         return;
53     }
54
55     testnode.focus();
56     textInputController.doCommand("moveForward:");
57
58     var charSequence = tests[testIdx][0];
59     for (var i = 0; i < charSequence.length - 1; i++) {
60         textInputController.setMarkedText(charSequence[i], testnode.value.length, testnode.value.length);
61     }
62     if (charSequence[charSequence.length - 1] == "backspace")
63         textInputController.doCommand("deleteBackward:");
64     else
65         textInputController.insertText(charSequence[charSequence.length - 1]);
66
67     if(tests[testIdx][3])
68         assert(tests[testIdx][1], window.find(secureText(testnode.value.length), false, true), "secured right after.");
69
70     if(tests[testIdx][3])
71         window.setTimeout(function(){ run(tests, testIdx); }, 600);
72     else
73         window.setTimeout(function(){ run(tests, testIdx); }, 0);
74 }
75
76 function init(tests)
77 {
78     if (window.layoutTestController && window.textInputController) {
79         layoutTestController.dumpAsText();
80         layoutTestController.waitUntilDone();
81         if (window.internals) {
82             window.internals.setPasswordEchoEnabled(document, true);
83             window.internals.setPasswordEchoDurationInSeconds(document, 0.1);
84             testnode = document.getElementById('testnode');
85             run(tests, -1);
86         }
87     }
88 }
89