| !DOCTYPE html> |
| <html> |
| <head> |
| <link rel="help" href="http://www.w3.org/TR/2012/WD-dom-20121206/#text"> |
| <script src="../../resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests that the Text API arguments are correctly validated."); |
| |
| var text = document.createTextNode("abcdefg"); |
| shouldBeEqualToString("text.data", "abcdefg"); |
| shouldBe("text.__proto__", "Text.prototype"); |
| |
| // Text splitText(unsigned long offset) |
| shouldBeEqualToString("text.splitText(4).data", "efg"); |
| shouldBeEqualToString("text.data", "abcd"); |
| shouldThrow("text.splitText()", '"TypeError: Failed to execute \'splitText\' on \'Text\': 1 argument required, but only 0 present."'); |
| shouldBeEqualToString("text.data", "abcd"); |
| shouldThrow("text.splitText(999)", '"IndexSizeError: Failed to execute \'splitText\' on \'Text\': The offset 999 is larger than the Text node\'s length."'); // offset greater than length |
| shouldBeEqualToString("text.data", "abcd"); |
| shouldThrow("text.splitText(-1)", '"IndexSizeError: Failed to execute \'splitText\' on \'Text\': The offset 4294967295 is larger than the Text node\'s length."'); // offset greater than length (after wrapping) |
| shouldBeEqualToString("text.data", "abcd"); |
| shouldBeEqualToString("text.splitText(-4294967294).data", "cd"); // Wraps to 2, which is a valid offset. |
| shouldBeEqualToString("text.data", "ab"); |
| </script> |
| </body> |
| </html> |