summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/ValidityState-customError.html
blob: f509e156992b893cefa260c18daf9f2be9d07569 (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
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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<fieldset name="set" id="fieldset-set"></fieldset>
<button   name="set" id="button-set"></button>
<button   name="set" id="button-button-set" type="button"></button>
<button   name="set" id="button-reset-set" type="reset"></button>
<select   name="set" id="select-set"></select>
<textarea name="set" id="textarea-set"></textarea>
<input    name="set" id="input-set" />
<input    name="set" id="input-submit-set" type="submit" />

<fieldset name="set-and-empty" id="fieldset-set-and-empty"></fieldset>
<button   name="set-and-empty" id="button-set-and-empty"></button>
<button   name="set-and-empty" id="button-button-set-and-empty" type="button"></button>
<button   name="set-and-empty" id="button-reset-set-and-empty" type="reset"></button>
<select   name="set-and-empty" id="select-set-and-empty"></select>
<textarea name="set-and-empty" id="textarea-set-and-empty"></textarea>
<input    name="set-and-empty" id="input-set-and-empty" />
<input    name="set-and-empty" id="input-submit-set-and-empty" type="submit" />

<fieldset name="no-changes" id="fieldset-no-changes"></fieldset>
<button   name="no-changes" id="button-no-changes"></button>
<button   name="no-changes" id="button-button-no-changes" type="button"></button>
<button   name="no-changes" id="button-reset-no-changes" type="reset"></button>
<select   name="no-changes" id="select-no-changes"></select>
<textarea name="no-changes" id="textarea-no-changes"></textarea>
<input    name="no-changes" id="input-no-changes" />
<input    name="no-changes" id="input-submit-no-changes" type="submit" />

<fieldset name="many-changes" id="fieldset-many-changes"></fieldset>
<button   name="many-changes" id="button-many-changes"></button>
<button   name="many-changes" id="button-button-many-changes" type="button"></button>
<button   name="many-changes" id="button-reset-many-changes" type="reset"></button>
<select   name="many-changes" id="select-many-changes"></select>
<textarea name="many-changes" id="textarea-many-changes"></textarea>
<input    name="many-changes" id="input-many-changes" />
<input    name="many-changes" id="input-submit-many-changes" type="submit" />

<script language="JavaScript" type="text/javascript">
function customErrorFor(id) {
    return document.getElementById(id).validity.customError;
}

description("This test checks validity.customError.");

debug('Set some value for customError.');
v = document.getElementsByName("set");
for (i = 0; i < v.length; i++)
    v[i].setCustomValidity("Custom validation message");
shouldBeFalse('customErrorFor("fieldset-set")');
shouldBeTrue('customErrorFor("button-set")');
shouldBeFalse('customErrorFor("button-button-set")');
shouldBeFalse('customErrorFor("button-reset-set")');
shouldBeTrue('customErrorFor("select-set")');
shouldBeTrue('customErrorFor("textarea-set")');
shouldBeTrue('customErrorFor("input-set")');
shouldBeTrue('customErrorFor("input-submit-set")');

debug('');
debug('Set some value for customError, and clear it.');
v = document.getElementsByName("set-and-empty");
for (i = 0; i < v.length; i++)
    v[i].setCustomValidity("Custom validation message");
for (i = 0; i < v.length; i++)
    v[i].setCustomValidity("");
shouldBeFalse('customErrorFor("fieldset-set-and-empty")');
shouldBeFalse('customErrorFor("button-set-and-empty")');
shouldBeFalse('customErrorFor("button-button-set-and-empty")');
shouldBeFalse('customErrorFor("button-reset-set-and-empty")');
shouldBeFalse('customErrorFor("select-set-and-empty")');
shouldBeFalse('customErrorFor("textarea-set-and-empty")');
shouldBeFalse('customErrorFor("input-set-and-empty")');
shouldBeFalse('customErrorFor("input-submit-set-and-empty")');

debug('');
debug('Not any changes for customError.');
shouldBeFalse('customErrorFor("fieldset-no-changes")');
shouldBeFalse('customErrorFor("button-no-changes")');
shouldBeFalse('customErrorFor("button-button-no-changes")');
shouldBeFalse('customErrorFor("button-reset-no-changes")');
shouldBeFalse('customErrorFor("select-no-changes")');
shouldBeFalse('customErrorFor("textarea-no-changes")');
shouldBeFalse('customErrorFor("input-no-changes")');
shouldBeFalse('customErrorFor("input-submit-no-changes")');

debug('');
debug('Many changes for customError:');
debug('Set some value, and set with no arguments.');
v = document.getElementsByName("many-changes");
for (i = 0; i < v.length; i++) {
    v[i].setCustomValidity("Custom string");
    try {
        v[i].setCustomValidity();
        testFailed("setCustomValidity() did not throw");
    } catch(err) {
        testPassed("setCustomValidity() threw " + err.message);
    }
    v[i].setCustomValidity(undefined);
}
shouldBeFalse('customErrorFor("fieldset-many-changes")');
shouldBeTrue('customErrorFor("button-many-changes")');
shouldBeFalse('customErrorFor("button-button-many-changes")');
shouldBeFalse('customErrorFor("button-reset-many-changes")');
shouldBeTrue('customErrorFor("select-many-changes")');
shouldBeTrue('customErrorFor("textarea-many-changes")');
shouldBeTrue('customErrorFor("input-many-changes")');
shouldBeTrue('customErrorFor("input-submit-many-changes")');

debug('Set with three arguments.');
for (i = 0; i < v.length; i++)
    v[i].setCustomValidity("one", "two", "three");
shouldBeFalse('customErrorFor("fieldset-many-changes")');
shouldBeTrue('customErrorFor("button-many-changes")');
shouldBeFalse('customErrorFor("button-button-many-changes")');
shouldBeFalse('customErrorFor("button-reset-many-changes")');
shouldBeTrue('customErrorFor("select-many-changes")');
shouldBeTrue('customErrorFor("textarea-many-changes")');
shouldBeTrue('customErrorFor("input-many-changes")');
shouldBeTrue('customErrorFor("input-submit-many-changes")');

debug('Set null.');
for (i = 0; i < v.length; i++)
    v[i].setCustomValidity(null);
shouldBeFalse('customErrorFor("fieldset-many-changes")');
shouldBeTrue('customErrorFor("button-many-changes")');
shouldBeFalse('customErrorFor("button-button-many-changes")');
shouldBeFalse('customErrorFor("button-reset-many-changes")');
shouldBeTrue('customErrorFor("select-many-changes")');
shouldBeTrue('customErrorFor("textarea-many-changes")');
shouldBeTrue('customErrorFor("input-many-changes")');
shouldBeTrue('customErrorFor("input-submit-many-changes")');

debug('Set some value, and set undefined.');
for (i = 0; i < v.length; i++) {
    v[i].setCustomValidity("Custom string");
    v[i].setCustomValidity(undefined);
}
shouldBeFalse('customErrorFor("fieldset-many-changes")');
shouldBeTrue('customErrorFor("button-many-changes")');
shouldBeFalse('customErrorFor("button-button-many-changes")');
shouldBeFalse('customErrorFor("button-reset-many-changes")');
shouldBeTrue('customErrorFor("select-many-changes")');
shouldBeTrue('customErrorFor("textarea-many-changes")');
shouldBeTrue('customErrorFor("input-many-changes")');
shouldBeTrue('customErrorFor("input-submit-many-changes")');

debug('');
</script>
</body>
</html>