-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_password_unmask_API.html
164 lines (150 loc) · 6.56 KB
/
test_password_unmask_API.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE HTML>
<html>
<head>
<title>Test for unmasking password API</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<input type="text">
<input type="password">
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(() => {
let input = document.getElementsByTagName("input")[0];
let password = document.getElementsByTagName("input")[1];
let editor = SpecialPowers.wrap(input).editor;
let passwordEditor = SpecialPowers.wrap(password).editor;
try {
editor.mask();
ok(false,
`nsIEditor.mask() should throw exception when called for <input type="text"> before nsIEditor.unmask()`);
} catch (e) {
ok(true,
`nsIEditor.mask() should throw exception when called for <input type="text"> before nsIEditor.unmask() ${e}`);
}
try {
editor.unmask();
ok(false,
`nsIEditor.unmask() should throw exception when called for <input type="text">`);
} catch (e) {
ok(true,
`nsIEditor.unmask() should throw exception when called for <input type="text"> ${e}`);
}
try {
editor.unmask(0);
ok(false,
`nsIEditor.unmask(0) should throw exception when called for <input type="text">`);
} catch (e) {
ok(true,
`nsIEditor.unmask(0) should throw exception when called for <input type="text"> ${e}`);
}
input.value = "abcdef";
try {
editor.unmask();
ok(false,
`nsIEditor.unmask() should throw exception when called for <input type="text" value="abcdef">`);
} catch (e) {
ok(true,
`nsIEditor.unmask() should throw exception when called for <input type="text" value="abcdef"> ${e}`);
}
try {
editor.mask();
ok(false,
`nsIEditor.mask() should throw exception when called for <input type="text" value="abcdef"> after nsIEditor.unmask()`);
} catch (e) {
ok(true,
`nsIEditor.mask() should throw exception when called for <input type="text" value="abcdef"> after nsIEditor.unmask() ${e}`);
}
try {
passwordEditor.mask();
ok(true,
`nsIEditor.mask() shouldn't throw exception when called for <input type="password"> before nsIEditor.unmask()`);
ok(passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be true after nsIEditor.mask() for <input type="password"> before nsIEditor.unmask()`);
} catch (e) {
ok(false,
`nsIEditor.mask() shouldn't throw exception when called for <input type="password"> before nsIEditor.unmask() ${e}`);
}
try {
editor.unmask(5);
ok(false,
`nsIEditor.unmask(5) should throw exception when called for <input type="password" value="">`);
} catch (e) {
ok(true,
`nsIEditor.unmask(5) should throw exception when called for <input type="password" value=""> ${e}`);
ok(passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should keep true (<input type="password">)`);
}
try {
passwordEditor.unmask();
ok(true,
`nsIEditor.unmask() shouldn't throw exception when called for <input type="password">`);
ok(!passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be false after nsIEditor.unmask() for <input type="password">)`);
is(passwordEditor.unmaskedStart, 0,
`nsIEditor.unmaskedStart should be 0 after nsIEditor.unmask() for <input type="password">`);
is(passwordEditor.unmaskedEnd, 0,
`nsIEditor.unmaskedEnd should be 0 after nsIEditor.unmask() for <input type="password">`);
} catch (e) {
ok(false,
`nsIEditor.unmask() shouldn't throw exception when called for <input type="password"> ${e}`);
}
password.value = "abcdef";
try {
passwordEditor.unmask();
ok(true,
`nsIEditor.unmask() shouldn't throw exception when called for <input type="password" value="abcdef">)`);
ok(!passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be false after nsIEditor.unmask() for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedStart, 0,
`nsIEditor.unmaskedStart should be 0 after nsIEditor.unmask() for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedEnd, 6,
`nsIEditor.unmaskedEnd should be 0 after nsIEditor.unmask() for <input type="password" value="abcdef">`);
} catch (e) {
ok(false,
`nsIEditor.unmask() shouldn't throw exception when called for <input type="password" value="abcdef"> ${e}`);
}
try {
passwordEditor.mask();
ok(true,
`nsIEditor.mask() shouldn't throw exception when called for <input type="password" value="abcdef">`);
ok(passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be true after nsIEditor.mask() for <input type="password" value="abcdef">`);
} catch (e) {
ok(false,
`nsIEditor.mask() shouldn't throw exception when called for <input type="password" value="abcdef"> ${e}`);
}
try {
passwordEditor.unmask(0, 100, 1000);
ok(true,
`nsIEditor.unmask(0, 100, 1000) shouldn't throw exception when called for <input type="password" value="abcdef">`);
ok(passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be true after nsIEditor.unmask(0, 100, 1000) for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedStart, 0,
`nsIEditor.unmaskedStart should be 0 after nsIEditor.unmask(0, 100, 1000) for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedEnd, 6,
`nsIEditor.unmaskedEnd should be 6 after nsIEditor.unmask(0, 100, 1000) for <input type="password" value="abcdef">`);
} catch (e) {
ok(false,
`nsIEditor.unmask(0, 100, 1000) shouldn't throw exception when called for <input type="password" value="abcdef"> ${e}`);
}
try {
passwordEditor.unmask(3);
ok(true,
`nsIEditor.unmask(3) shouldn't throw exception when called for <input type="password" value="abcdef">`);
ok(!passwordEditor.autoMaskingEnabled,
`nsIEditor.autoMaskingEnabled should be false after nsIEditor.unmask(3) for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedStart, 3,
`nsIEditor.unmaskedStart should be 3 after nsIEditor.unmask(3) for <input type="password" value="abcdef">`);
is(passwordEditor.unmaskedEnd, 6,
`nsIEditor.unmaskedEnd should be 6 after nsIEditor.unmask(3) for <input type="password" value="abcdef">`);
} catch (e) {
ok(false,
`nsIEditor.unmask(3) shouldn't throw exception when called for <input type="password" value="abcdef"> ${e}`);
}
SimpleTest.finish();
});
</script>
</body>
</html>