summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/encoding/textdecoder-ignorebom.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/encoding/textdecoder-ignorebom.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/encoding/textdecoder-ignorebom.html')
-rw-r--r--testing/web-platform/tests/encoding/textdecoder-ignorebom.html45
1 files changed, 45 insertions, 0 deletions
diff --git a/testing/web-platform/tests/encoding/textdecoder-ignorebom.html b/testing/web-platform/tests/encoding/textdecoder-ignorebom.html
new file mode 100644
index 000000000..26381568f
--- /dev/null
+++ b/testing/web-platform/tests/encoding/textdecoder-ignorebom.html
@@ -0,0 +1,45 @@
+<!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);
+});
+
+test(function() {
+ assert_true('ignoreBOM' in new TextDecoder(), 'The ignoreBOM attribute should exist on TextDecoder.');
+ assert_equals(typeof new TextDecoder().ignoreBOM, 'boolean', 'The type of the ignoreBOM attribute should be boolean.');
+ assert_false(new TextDecoder().ignoreBOM, 'The ignoreBOM attribute should default to false.');
+ assert_true(new TextDecoder('utf-8', {ignoreBOM: true}).ignoreBOM, 'The ignoreBOM attribute can be set using an option.');
+
+}, 'The ignoreBOM attribute of TextDecoder');
+
+</script>