Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / dom / HTMLProgressElement / script-tests / set-progress-properties.js
1 description('Test setting valid and invalid properties of HTMLProgressElement.');
2
3 var p = document.createElement('progress');
4
5 debug("Test values before properties were set");
6 shouldBe("p.value", "0");
7 shouldBe("p.max", "1");
8 shouldBe("p.position", "-1");
9
10 debug("Set valid values");
11 p.value = 7e1;
12 p.max = "1e2";
13 shouldBe("p.value", "70");
14 shouldBe("p.max", "100");
15 shouldBe("p.position", "0.7");
16
17 debug("Set value bigger than max");
18 p.value = 200;
19 p.max = 100.0;
20 shouldBe("p.value", "100");
21 shouldBe("p.max", "100");
22 shouldBe("p.position", "1");
23
24 debug("Set value less than zero");
25 p.value = -42;
26 shouldBe('p.value', '0');
27 shouldBe('p.position', '0');
28
29 debug("Set invalid value, should throw");
30 shouldThrow('p.value = "200A";', '"TypeError: Failed to set the \'value\' property on \'HTMLProgressElement\': The value provided is not a number."');
31
32 debug("Set invalid max, should throw");
33 shouldThrow('p.max = "max";', '"TypeError: Failed to set the \'max\' property on \'HTMLProgressElement\': The value provided is not a number."');
34
35 debug("Set max to Infinity, should throw");
36 shouldThrow('p.max = Infinity;', '"TypeError: Failed to set the \'max\' property on \'HTMLProgressElement\': The value provided is infinite."');
37
38 debug("Set value to NaN, should throw");
39 shouldThrow('p.value = NaN;', '"TypeError: Failed to set the \'value\' property on \'HTMLProgressElement\': The value provided is not a number."');
40
41 debug("Set value to null and max to 0");
42 p.value = null;
43 p.max = 0;
44 shouldBe("p.value", "0");
45 shouldBe("p.max", "1");
46 shouldBe("p.position", "0");
47
48 debug("Set attributes to valid numbers");
49 p.setAttribute("value", 5);
50 p.setAttribute("max", 10);
51 shouldBe("p.value", "5");
52 shouldBe("p.max", "10");
53 shouldBe("parseInt(p.getAttribute('value'))", "5");
54 shouldBe("parseInt(p.getAttribute('max'))", "10");
55
56 debug("Set attributes to invalid values");
57 p.setAttribute("value", "ABC");
58 p.setAttribute("max", "#");
59 shouldBe("p.value", "0");
60 shouldBe("p.max", "1");
61 shouldBe("p.getAttribute('value')", "'ABC'");
62 shouldBe("p.getAttribute('max')", "'#'");
63
64 debug("Set value and max to numbers with leading spaces");
65 p.setAttribute("value", " 5");
66 p.setAttribute("max", " 10");
67 shouldBe("p.value", "0");
68 shouldBe("p.max", "1");
69 shouldBe("p.position", "0");