LCOV - code coverage report
Current view: top level - test/wpt/xhr - send-receive-utf16.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 84 84 100.0 %
Date: 2024-12-07 00:20:21 Functions: 5 5 100.0 %
Branches: 8 8 100.0 %

           Branch data     Line data    Source code
       1            [ + ]:          2 : import assert from 'node:assert/strict';
       2                 :          2 : import { XMLHttpRequest } from '../../../lib/whatwg-xhr.js';
       3                 :          2 : 
       4            [ + ]:          2 : export default (activeURL) => {
       5                 :          1 : 
       6            [ + ]:          1 :         (() => {
       7                 :          1 :                 let xhr = new XMLHttpRequest();
       8                 :          1 : 
       9            [ + ]:          1 :                 xhr.onload = (e) => {
      10                 :          1 :                         assert.strictEqual(xhr.responseText, 'æøå\nテスト\n');
      11                 :          1 :                 };
      12                 :          1 : 
      13                 :          1 :                 xhr.open('GET', `${activeURL}/utf16.txt`);
      14                 :          1 :                 xhr.send();
      15                 :          1 :         })('UTF-16 with BOM, no encoding in content-type');
      16                 :          1 : 
      17            [ + ]:          1 :         (() => {
      18                 :          1 :                 let xhr = new XMLHttpRequest();
      19                 :          1 : 
      20            [ + ]:          1 :                 xhr.onload = (e) => {
      21                 :          1 :                         assert.strictEqual(xhr.responseText, 'æøå\nテスト\n');
      22                 :          1 :                 };
      23                 :          1 : 
      24                 :          1 :                 xhr.open('GET', `${activeURL}/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-16&content=%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00`);
      25                 :          1 :                 xhr.send();
      26                 :          1 :         })('UTF-16 without BOM, with charset label in content-type');
      27                 :          1 : 
      28            [ + ]:          1 :         (() => {
      29                 :          1 :                 let xhr = new XMLHttpRequest();
      30                 :          1 : 
      31            [ + ]:          1 :                 xhr.onload = (e) => {
      32                 :          1 :                         assert.strictEqual(xhr.responseText, '\ufffd\u0000\ufffd\u0000\ufffd\u0000\u000a\u0000\ufffd\u0030\ufffd\u0030\ufffd\u0030\u000a\u0000');
      33                 :          1 :                 };
      34                 :          1 : 
      35                 :          1 :                 xhr.open('GET', `${activeURL}/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-8&content=%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00`);
      36                 :          1 :                 xhr.send();
      37                 :          1 :         })('UTF-16 without BOM, mislabelled as UTF-8 in content-type');
      38                 :          1 : }
      39                 :          2 : 
      40                 :          2 : /*
      41                 :          2 :  * send-receive-utf16.htm
      42                 :          2 :  *
      43                 :          2 : 
      44                 :          2 : <!doctype html>
      45                 :          2 : <meta charset=utf-8>
      46                 :          2 : <title>XMLHttpRequest: The send() method: receive data which is UTF-16 encoded</title>
      47                 :          2 : <script src="/resources/testharness.js"></script>
      48                 :          2 : <script src="/resources/testharnessreport.js"></script>
      49                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#text-response" data-tested-assertations="following::ol/li[9]" />
      50                 :          2 : <div id="log"></div>
      51                 :          2 : 
      52                 :          2 : <script>
      53                 :          2 :   async_test(function() {
      54                 :          2 :     var client = new XMLHttpRequest();
      55                 :          2 :     client.onload = this.step_func_done(function(e) {
      56                 :          2 :       assert_equals(client.responseText, 'æøå\nテスト\n')
      57                 :          2 :     });
      58                 :          2 :     client.open("GET", "resources/utf16.txt");
      59                 :          2 :     client.send(null);
      60                 :          2 :   }, 'UTF-16 with BOM, no encoding in content-type');
      61                 :          2 : 
      62                 :          2 :   async_test(function() {
      63                 :          2 :     var client = new XMLHttpRequest();
      64                 :          2 :     client.onload = this.step_func_done(function(e) {
      65                 :          2 :       assert_equals(client.responseText, 'æøå\nテスト\n')
      66                 :          2 :     });
      67                 :          2 :     client.open("GET", "resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-16&content=%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00");
      68                 :          2 :     client.send(null);
      69                 :          2 :   }, 'UTF-16 without BOM, with charset label in content-type');
      70                 :          2 : 
      71                 :          2 :   async_test(function() {
      72                 :          2 :     var client = new XMLHttpRequest();
      73                 :          2 :     client.onload = this.step_func_done(function(e) {
      74                 :          2 :       // plenty of EF BF BD Replacement Character in this invalid input..
      75                 :          2 :       assert_equals(client.responseText, "\ufffd\u0000\ufffd\u0000\ufffd\u0000\u000a\u0000\ufffd\u0030\ufffd\u0030\ufffd\u0030\u000a\u0000")
      76                 :          2 :     });
      77                 :          2 :     client.open("GET", "resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-8&content=%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00");
      78                 :          2 :     client.send(null);
      79                 :          2 :   }, 'UTF-16 without BOM, mislabelled as UTF-8 in content-type');
      80                 :          2 : </script>
      81                 :          2 : 
      82                 :          2 :  *
      83                 :          2 :  * send-receive-utf16.htm
      84                 :          2 :  */

Generated by: LCOV version 1.14