File: Determining-Encoding.html

package info (click to toggle)
icedove 1%3A45.8.0-3~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,488,584 kB
  • ctags: 1,068,813
  • sloc: cpp: 4,801,496; ansic: 1,929,291; python: 379,296; java: 252,018; xml: 173,182; asm: 146,741; sh: 89,229; makefile: 23,462; perl: 16,380; objc: 4,088; yacc: 1,841; lex: 1,222; exp: 499; php: 437; lisp: 228; awk: 152; pascal: 116; sed: 51; ruby: 47; csh: 31; ada: 16
file content (91 lines) | stat: -rw-r--r-- 3,278 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<meta charset=utf-8>
<title>FileAPI Test: Blob Determining Encoding</title>
<link ref="author" title="march1993" href="mailto:march511@gmail.com">
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#enctype">
<link rel=help href="http://encoding.spec.whatwg.org/#decode">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test("Blob Determing Encoding with encoding argument");
t.step(function() {
    // string 'hello'
    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
    var blob = new Blob([new Uint8Array(data)]);
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
    }, reader);

    reader.readAsText(blob, "UTF-16BE");
});

var t = async_test("Blob Determing Encoding with type attribute");
t.step(function() {
    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
    var blob = new Blob([new Uint8Array(data)], {type:"text/plain;charset=UTF-16BE"});
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.")
    }, reader);

    reader.readAsText(blob);
});


var t = async_test("Blob Determing Encoding with UTF-8 BOM");
t.step(function() {
    var data = [0xEF,0xBB,0xBF,0x68,0x65,0x6C,0x6C,0xC3,0xB6];
    var blob = new Blob([new Uint8Array(data)]);
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hellö", "The FileReader should read the blob with UTF-8.");
    }, reader);

    reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding without anything implying charset.");
t.step(function() {
    var data = [0x68,0x65,0x6C,0x6C,0xC3,0xB6];
    var blob = new Blob([new Uint8Array(data)]);
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hellö", "The FileReader should read the blob by default with UTF-8.");
    }, reader);

    reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding with UTF-16BE BOM");
t.step(function() {
    var data = [0xFE,0xFF,0x00,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F];
    var blob = new Blob([new Uint8Array(data)]);
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16BE.");
    }, reader);

    reader.readAsText(blob);
});

var t = async_test("Blob Determing Encoding with UTF-16LE BOM");
t.step(function() {
    var data = [0xFF,0xFE,0x68,0x00,0x65,0x00,0x6C,0x00,0x6C,0x00,0x6F,0x00];
    var blob = new Blob([new Uint8Array(data)]);
    var reader = new FileReader();

    reader.onloadend = t.step_func_done (function(event) {
        assert_equals(this.result, "hello", "The FileReader should read the ArrayBuffer through UTF-16LE.");
    }, reader);

    reader.readAsText(blob);
});

</script>