1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.html;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21
22
23
24
25
26
27 @RunWith(BrowserRunner.class)
28 public class HtmlRangeInput2Test extends SimpleWebTestCase {
29
30
31
32
33 @Test
34 public void testDefault() throws Exception {
35 final String htmlContent = DOCTYPE_HTML
36 + "<html>\n"
37 + "<head></head>\n"
38 + "<body>\n"
39 + "<form id='form1'>\n"
40 + " <input type='range' id='first'>\n"
41 + " <input type='range' id='second' min='-100' max='100'>\n"
42 + " <input type='range' id='third' min='-15' max='85'>\n"
43 + " <input type='range' id='forth' min='foo' max='bar'>\n"
44 + "</form>\n"
45 + "</body></html>";
46
47 final HtmlPage page = loadPage(htmlContent);
48
49 final HtmlRangeInput first = (HtmlRangeInput) page.getElementById("first");
50 final HtmlRangeInput second = (HtmlRangeInput) page.getElementById("second");
51 final HtmlRangeInput third = (HtmlRangeInput) page.getElementById("third");
52 final HtmlRangeInput forth = (HtmlRangeInput) page.getElementById("forth");
53
54 assertEquals("", first.getValueAttribute());
55 assertEquals("50", first.getValue());
56 assertEquals("", second.getValueAttribute());
57 assertEquals("0", second.getValue());
58 assertEquals("", third.getValueAttribute());
59 assertEquals("35", third.getValue());
60 assertEquals("", forth.getValueAttribute());
61 assertEquals("50", forth.getValue());
62 }
63
64
65
66
67 @Test
68 public void minValidation() throws Exception {
69 final String htmlContent = DOCTYPE_HTML
70 + "<html>\n"
71 + "<head></head>\n"
72 + "<body>\n"
73 + "<form id='form1'>\n"
74 + " <input type='range' id='first' min='10'>\n"
75 + " <input type='range' id='second'>\n"
76 + " <input type='range' id='third' min='foo'>\n"
77 + "</form>\n"
78 + "</body></html>";
79
80 final HtmlPage page = loadPage(htmlContent);
81
82 final HtmlRangeInput first = (HtmlRangeInput) page.getElementById("first");
83 final HtmlRangeInput second = (HtmlRangeInput) page.getElementById("second");
84 final HtmlRangeInput third = (HtmlRangeInput) page.getElementById("third");
85
86 final String defaultFirstValue = first.getValue();
87
88
89 assertTrue(first.isValid());
90
91 first.setValue("foo");
92 assertTrue(first.isValid());
93 assertEquals("", first.getValueAttribute());
94 assertEquals(defaultFirstValue, first.getValue());
95
96 first.setValue("1");
97 assertTrue(first.isValid());
98 assertEquals("", first.getValueAttribute());
99 assertEquals("10", first.getValue());
100
101 first.setValue("10");
102 assertTrue(first.isValid());
103 assertEquals("", first.getValueAttribute());
104 assertEquals("10", first.getValue());
105
106 first.setValue("100");
107 assertTrue(first.isValid());
108 assertEquals("", first.getValueAttribute());
109 assertEquals("100", first.getValue());
110
111 second.setValue("0");
112 assertTrue(second.isValid());
113 assertEquals("", second.getValueAttribute());
114 assertEquals("0", second.getValue());
115
116 third.setValue("0");
117 assertTrue(third.isValid());
118 assertEquals("", third.getValueAttribute());
119 assertEquals("0", third.getValue());
120 }
121
122
123
124
125 @Test
126 public void maxValidation() throws Exception {
127 final String htmlContent = DOCTYPE_HTML
128 + "<html>\n"
129 + "<head></head>\n"
130 + "<body>\n"
131 + "<form id='form1'>\n"
132 + " <input type='range' id='first' max='10'>\n"
133 + " <input type='range' id='second'>\n"
134 + " <input type='range' id='third' max='foo'>\n"
135 + "</form>\n"
136 + "</body></html>";
137
138 final HtmlPage page = loadPage(htmlContent);
139
140 final HtmlRangeInput first = (HtmlRangeInput) page.getElementById("first");
141 final HtmlRangeInput second = (HtmlRangeInput) page.getElementById("second");
142 final HtmlRangeInput third = (HtmlRangeInput) page.getElementById("third");
143
144 final String defaultFirstValue = first.getValue();
145
146
147 assertTrue(first.isValid());
148
149 first.setValue("foo");
150 assertTrue(first.isValid());
151 assertEquals("", first.getValueAttribute());
152 assertEquals(defaultFirstValue, first.getValue());
153
154 first.setValue("1");
155 assertTrue(first.isValid());
156 assertEquals("", first.getValueAttribute());
157 assertEquals("1", first.getValue());
158
159 first.setValue("10");
160 assertTrue(first.isValid());
161 assertEquals("", first.getValueAttribute());
162 assertEquals("10", first.getValue());
163
164 first.setValue("100");
165 assertTrue(first.isValid());
166 assertEquals("", first.getValueAttribute());
167 assertEquals("10", first.getValue());
168
169 second.setValue("0");
170 assertTrue(second.isValid());
171 assertEquals("", second.getValueAttribute());
172 assertEquals("0", second.getValue());
173
174 third.setValue("0");
175 assertTrue(third.isValid());
176 assertEquals("", third.getValueAttribute());
177 assertEquals("0", third.getValue());
178 }
179 }