4 <link rel=
"help" href=
"http://www.w3.org/TR/2012/WD-dom-20121206/#interface-characterdata">
5 <script src=
"../../resources/js-test.js"></script>
9 description("Tests that the CharacterData API arguments are correctly validated.");
11 var text
= document
.createTextNode("abcd");
12 shouldBeEqualToString("text.data", "abcd");
13 shouldBe("text.__proto__.__proto__", "CharacterData.prototype");
16 shouldNotThrow("text.appendData('efg')");
17 shouldBeEqualToString("text.data", "abcdefg");
18 shouldThrow("text.appendData()", '"TypeError: Failed to execute \'appendData\' on \'CharacterData\': 1 argument required, but only 0 present."');
19 shouldBeEqualToString("text.data", "abcdefg");
23 shouldNotThrow("text.insertData(0, 'abcd')");
24 shouldBeEqualToString("text.data", "abcdefg");
25 shouldThrow("text.insertData()", '"TypeError: Failed to execute \'insertData\' on \'CharacterData\': 2 arguments required, but only 0 present."');
26 shouldBeEqualToString("text.data", "abcdefg");
27 shouldThrow("text.insertData(0)", '"TypeError: Failed to execute \'insertData\' on \'CharacterData\': 2 arguments required, but only 1 present."');
28 shouldBeEqualToString("text.data", "abcdefg");
29 shouldThrow("text.insertData(999, 'test')", '"IndexSizeError: Failed to execute \'insertData\' on \'CharacterData\': The offset 999 is greater than the node\'s length (7)."');
30 shouldBeEqualToString("text.data", "abcdefg");
31 shouldNotThrow("text.insertData(-4294967294, 'test')"); // Wraps to 2, which is a valid offset.
32 shouldBeEqualToString("text.data", "abtestcdefg");
35 text
.data
= "abcdefg";
36 shouldNotThrow("text.deleteData(4, 3)");
37 shouldBeEqualToString("text.data", "abcd");
38 shouldThrow("text.deleteData()", '"TypeError: Failed to execute \'deleteData\' on \'CharacterData\': 2 arguments required, but only 0 present."');
39 shouldBeEqualToString("text.data", "abcd");
40 shouldThrow("text.deleteData(0)", '"TypeError: Failed to execute \'deleteData\' on \'CharacterData\': 2 arguments required, but only 1 present."');
41 shouldBeEqualToString("text.data", "abcd");
42 shouldThrow("text.deleteData(999, 3)", '"IndexSizeError: Failed to execute \'deleteData\' on \'CharacterData\': The offset 999 is greater than the node\'s length (4)."');
43 shouldBeEqualToString("text.data", "abcd");
44 shouldThrow("text.deleteData(-1, 3)", '"IndexSizeError: Failed to execute \'deleteData\' on \'CharacterData\': The offset 4294967295 is greater than the node\'s length (4)."'); // Wraps to 4294967295 which is greater than the data length
45 shouldBeEqualToString("text.data", "abcd");
46 shouldNotThrow("text.deleteData(-4294967294, 2)"); // Wraps to 2, which is a valid offset.
47 shouldBeEqualToString("text.data", "ab");
48 shouldNotThrow("text.deleteData(1, 999)"); // Length argument is too large, should be adjusted.
49 shouldBeEqualToString("text.data", "a");
53 shouldNotThrow("text.replaceData(0, 0, 'abcd')");
54 shouldBeEqualToString("text.data", "abcdefg");
55 shouldThrow("text.replaceData()", '"TypeError: Failed to execute \'replaceData\' on \'CharacterData\': 3 arguments required, but only 0 present."');
56 shouldBeEqualToString("text.data", "abcdefg");
57 shouldThrow("text.replaceData(0)", '"TypeError: Failed to execute \'replaceData\' on \'CharacterData\': 3 arguments required, but only 1 present."');
58 shouldBeEqualToString("text.data", "abcdefg");
59 shouldThrow("text.replaceData(0, 0)", '"TypeError: Failed to execute \'replaceData\' on \'CharacterData\': 3 arguments required, but only 2 present."');
60 shouldBeEqualToString("text.data", "abcdefg");
61 shouldThrow("text.replaceData(999, 3, 'test')", '"IndexSizeError: Failed to execute \'replaceData\' on \'CharacterData\': The offset 999 is greater than the node\'s length (7)."');
62 shouldBeEqualToString("text.data", "abcdefg");
63 shouldThrow("text.replaceData(-1, 3, 'test')", '"IndexSizeError: Failed to execute \'replaceData\' on \'CharacterData\': The offset 4294967295 is greater than the node\'s length (7)."'); // Wraps to 4294967295 which is greater than the data length
64 shouldBeEqualToString("text.data", "abcdefg");
65 shouldNotThrow("text.replaceData(-4294967294, 0, 'test')"); // Wraps to 2, which is a valid offset.
66 shouldBeEqualToString("text.data", "abtestcdefg");
67 shouldNotThrow("text.replaceData(1, 999, 'aaa')"); // Length argument is too large, should be adjusted.
68 shouldBeEqualToString("text.data", "aaaa");
71 text
.data
= "abcdefg";
72 shouldBeEqualToString("text.substringData(4, 3)", "efg");
73 shouldThrow("text.substringData()", '"TypeError: Failed to execute \'substringData\' on \'CharacterData\': 2 arguments required, but only 0 present."');
74 shouldThrow("text.substringData(0)", '"TypeError: Failed to execute \'substringData\' on \'CharacterData\': 2 arguments required, but only 1 present."');
75 shouldBeEqualToString("text.substringData(4, 999)", "efg"); // Length argument is too large, should be adjusted.
76 shouldBeEqualToString("text.substringData(4, -1)", "efg"); // Length argument is too large (after wrapping), should be adjusted.
77 shouldThrow("text.substringData(-1, 2)", '"IndexSizeError: Failed to execute \'substringData\' on \'CharacterData\': The offset 4294967295 is greater than the node\'s length (7)."'); // Wraps to 4294967295 which is greater than the data length
78 shouldBeEqualToString("text.substringData(-4294967294, 3)", "cde"); // Wraps to 2, which is a valid offset.