Index: LayoutTests/fast/encoding/api/textdecoder-ignorebom.html |
diff --git a/LayoutTests/fast/encoding/api/textdecoder-ignorebom.html b/LayoutTests/fast/encoding/api/textdecoder-ignorebom.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80be41e88d9ed890796c188846b5b5dee627ec46 |
--- /dev/null |
+++ b/LayoutTests/fast/encoding/api/textdecoder-ignorebom.html |
@@ -0,0 +1,37 @@ |
+<!DOCTYPE html> |
+<title>Encoding API: TextDecoder ignoreBOM option</title> |
+<script src="../../../resources/testharness.js"></script> |
+<script src="../../../resources/testharnessreport.js"></script> |
+<script> |
+ |
+var cases = [ |
+ {encoding: 'utf-8', bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63]}, |
+ {encoding: 'utf-16le', bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]}, |
+ {encoding: 'utf-16be', bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63]} |
+]; |
+ |
+cases.forEach(function(testCase) { |
+ test(function() { |
+ var BOM = '\uFEFF'; |
+ var decoder = new TextDecoder(testCase.encoding, {ignoreBOM: true}); |
+ var bytes = new Uint8Array(testCase.bytes); |
+ assert_equals( |
+ decoder.decode(bytes), |
+ BOM + 'abc', |
+ testCase.encoding + ': BOM should be present in decoded string if ignored'); |
+ |
+ decoder = new TextDecoder(testCase.encoding, {ignoreBOM: false}); |
+ assert_equals( |
+ decoder.decode(bytes), |
+ 'abc', |
+ testCase.encoding + ': BOM should be absent from decoded string if not ignored'); |
+ |
+ decoder = new TextDecoder(testCase.encoding); |
+ assert_equals( |
+ decoder.decode(bytes), |
+ 'abc', |
+ testCase.encoding + ': BOM should be absent from decoded string by default'); |
+ }, 'BOM is ignored if ignoreBOM option is specified: ' + testCase.encoding); |
+}); |
+ |
+</script> |