summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/encoding/api/streaming-decode.html
blob: 34ffccc0161a644bda48a424fdb73612c96b8b3b (plain)
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
<!DOCTYPE html>
<title>Encoding API: Streaming decode</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="resources/shared.js"></script>
<script>

var string = '\\x00123ABCabc\\x80\\xFF\\u0100\\u1000\\uFFFD\\uD800\\uDC00\\uDBFF\\uDFFF';

utf_encodings.forEach(function (encoding) {
    for (var len = 1; len <= 5; ++len) {
        test(function() {
            var encoded = new TextEncoder(encoding).encode(string);

            var out = '';
            var decoder = new TextDecoder(encoding);
            for (var i = 0; i < encoded.length; i += len) {
                var sub = [];
                for (var j = i; j < encoded.length && j < i + len; ++j)
                    sub.push(encoded[j]);
                out += decoder.decode(new Uint8Array(sub), {stream: true});
            }
            out += decoder.decode();
            assert_equals(out, string);
        }, 'Streaming decode: ' + encoding + ', ' + len + ' byte window');
    }
});

</script>