summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/constraints/form-validation-reportValidity.html
blob: c68e21c9d5f7eed6fc3d048c68817fcc6975da36 (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>The constraint validation API Test: element.reportValidity()</title>
<link rel="author" title="Intel" href="http://www.intel.com/">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-constraint-validation-api">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/validator.js"></script>
<div id="log"></div>
<script>
  var testElements = [
    {
      tag: "input",
      types: ["text", "search", "tel", "password"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {maxLength: "4", value: "abcdef"}, expected: true, name: "[target] not suffering from being too long", dirty: true},
        {conditions: {pattern: "[A-Z]", value: "abc"}, expected: false, name: "[target] suffering from a pattern mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["url"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {maxLength: "20", value: "http://www.example.com"}, expected: true, name: "[target] not suffering from being too long", dirty: true},
        {conditions: {pattern: "http://www.example.com", value: "http://www.example.net"}, expected: false, name: "[target] suffering from a pattern mismatch"},
        {conditions: {value: "abc"}, expected: false, name: "[target] suffering from a type mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["email"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {maxLength: "10", value: "test@example.com"}, expected: true, name: "[target] not suffering from being too long", dirty: true},
        {conditions: {pattern: "test@example.com", value: "test@example.net"}, expected: false, name: "[target] suffering from a pattern mismatch"},
        {conditions: {value: "abc"}, expected: false, name: "[target] suffering from a type mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["datetime-local"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {max: "2000-01-01T12:00:00", value: "2001-01-01T12:00:00"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "2001-01-01T12:00:00", value: "2000-01-01T12:00:00"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 2 * 60 * 1000, value: "2001-01-01T12:03:00"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["date"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {max: "2000-01-01", value: "2001-01-01"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "2001-01-01", value: "2000-01-01"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 2 * 1 * 86400000, value: "2001-01-03"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["month"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {max: "2000-01", value: "2001-01"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "2001-01", value: "2000-01"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 3 * 1 * 1, value: "2001-03"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["week"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {max: "2000-W01", value: "2001-W01"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "2001-W01", value: "2000-W01"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 2 * 1 * 604800000, value: "2001-W03"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["time"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {max: "12:00:00", value: "13:00:00"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "12:00:00", value: "11:00:00"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 2 * 60 * 1000, value: "12:03:00"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["number"],
      testData: [
        {conditions: {max: "5", value: "6"}, expected: false, name: "[target] suffering from an overflow"},
        {conditions: {min: "5", value: "4"}, expected: false, name: "[target] suffering from an underflow"},
        {conditions: {step: 2 * 1 * 1, value: "3"}, expected: false, name: "[target] suffering from a step mismatch"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["checkbox", "radio"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {required: true, checked: false, name: "test1"}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "input",
      types: ["file"],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {required: true, files: null}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "select",
      types: [],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    },
    {
      tag: "textarea",
      types: [],
      testData: [
        {conditions: {}, expected: true, name: "[target] no constraint"},
        {conditions: {required: true, value: ""}, expected: false, name: "[target] suffering from being missing"}
      ]
    }
  ];

  validator.run_test(testElements, "reportValidity");
</script>