LCOV - code coverage report
Current view: top level - test/wpt/xhr - responsetext-decoding.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 206 206 100.0 %
Date: 2024-12-07 00:20:21 Functions: 7 7 100.0 %
Branches: 9 9 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 :         const encoded_content         = "%e6%a9%9f";
       7                 :          1 :         const decoded_as_windows_1252 = "\u00e6\u00a9\u0178";
       8                 :          1 :         const decoded_as_utf_8        = "\u6a5f";
       9                 :          1 : 
      10                 :          1 :         const encoded_xml                  = create_encoded_xml(encoded_content);
      11                 :          1 :         const encoded_html                 = create_encoded_html(encoded_content);
      12                 :          1 :         const xml_decoded_as_windows_1252  = create_xml(decoded_as_windows_1252);
      13                 :          1 :         const xml_decoded_as_utf_8         = create_xml(decoded_as_utf_8);
      14                 :          1 :         const html_decoded_as_windows_1252 = create_html(decoded_as_windows_1252);
      15                 :          1 :         const html_decoded_as_utf_8        = create_html(decoded_as_utf_8);
      16                 :          1 : 
      17                 :          1 :         // 'default' response type
      18                 :          1 :         // An XML-ish response is sniffed.
      19                 :          1 : 
      20                 :          1 :         request('application/xml', encoded_xml, xml_decoded_as_windows_1252);
      21                 :          1 : 
      22                 :          1 :         // An HTML-ish response isn't sniffed.
      23                 :          1 : 
      24                 :          1 :         request('text/html',                            encoded_html, html_decoded_as_utf_8);
      25                 :          1 :         request('application/xml;charset=utf-8',        encoded_xml,  xml_decoded_as_utf_8);
      26                 :          1 :         request('application/xml;charset=windows-1252', encoded_xml,  xml_decoded_as_windows_1252);
      27                 :          1 :         request('text/html;charset=utf-8',              encoded_html, html_decoded_as_utf_8);
      28                 :          1 :         request('text/html;charset=windows-1252',       encoded_html, html_decoded_as_windows_1252);
      29                 :          1 : 
      30                 :          1 :         request('text/plain;charset=windows-1252', '%FF', '\u00FF');
      31                 :          1 : 
      32                 :          1 :         request('text/plain', '%FF', '\uFFFD');
      33                 :          1 :         request('text/plain', '%FE%FF', '');
      34                 :          1 :         request('text/plain', '%FE%FF%FE%FF', '\uFEFF');
      35                 :          1 :         request('text/plain', '%EF%BB%BF', '');
      36                 :          1 :         request('text/plain', '%EF%BB%BF%EF%BB%BF', '\uFEFF');
      37                 :          1 :         request('text/plain', '%C2', '\uFFFD');
      38                 :          1 : 
      39                 :          1 :         request('text/xml',   '%FE%FF',             '');
      40                 :          1 :         request('text/xml',   '%FE%FF%FE%FF',       '\uFEFF');
      41                 :          1 :         request('text/xml',   '%EF%BB%BF',          '');
      42                 :          1 :         request('text/xml',   '%EF%BB%BF%EF%BB%BF', '\uFEFF');
      43                 :          1 :         request('text/plain', '%E3%81%B2',          '\u3072');
      44                 :          1 : 
      45                 :          1 :         // 'text' response type
      46                 :          1 :         // An XML-ish response isn't sniffed.
      47                 :          1 : 
      48                 :          1 :         request('application/xml', encoded_xml, xml_decoded_as_utf_8, 'text');
      49                 :          1 : 
      50                 :          1 :         // An HTML-ish response isn't sniffed.
      51                 :          1 : 
      52                 :          1 :         request('text/html',                            encoded_html, html_decoded_as_utf_8, 'text');
      53                 :          1 :         request('application/xml;charset=utf-8',        encoded_xml, xml_decoded_as_utf_8, 'text');
      54                 :          1 :         request('application/xml;charset=windows-1252', encoded_xml, xml_decoded_as_windows_1252, 'text');
      55                 :          1 :         request('text/html;charset=utf-8',              encoded_html, html_decoded_as_utf_8, 'text');
      56                 :          1 :         request('text/html;charset=windows-1252',       encoded_html, html_decoded_as_windows_1252, 'text');
      57                 :          1 : 
      58                 :          1 :         request('text/plain;charset=windows-1252', '%FF', '\u00FF', 'text');
      59                 :          1 :         request('text/plain', '%FF', '\uFFFD', 'text');
      60                 :          1 :         request('text/plain', '%FE%FF', '', 'text');
      61                 :          1 :         request('text/plain', '%FE%FF%FE%FF', '\uFEFF', 'text');
      62                 :          1 :         request('text/plain', '%EF%BB%BF', '', 'text');
      63                 :          1 :         request('text/plain', '%EF%BB%BF%EF%BB%BF', '\uFEFF', 'text');
      64                 :          1 :         request('text/plain', '%C2', '\uFFFD', 'text');
      65                 :          1 :         request('text/plain;charset=bogus', '%C2', '\uFFFD', 'text');
      66                 :          1 :         request('text/xml', '%FE%FF', '', 'text');
      67                 :          1 :         request('text/xml', '%FE%FF%FE%FF', '\uFEFF', 'text');
      68                 :          1 :         request('text/xml', '%EF%BB%BF', '', 'text');
      69                 :          1 :         request('text/xml', '%EF%BB%BF%EF%BB%BF', '\uFEFF', 'text');
      70                 :          1 :         request('text/plain', '%E3%81%B2', '\u3072', 'text');
      71                 :          1 : 
      72            [ + ]:          1 :         function create_html(content){
      73                 :          2 :                 return '<!doctype html><meta charset=windows-1252><x>' + content + '</x>';
      74                 :          2 :         }
      75                 :          1 : 
      76            [ + ]:          1 :         function create_encoded_html(encoded_content){
      77                 :          1 :                 return encodeURIComponent('<!doctype html><meta charset=windows-1252><x>') + encoded_content + encodeURIComponent('<\/x>');
      78                 :          1 :         }
      79                 :          1 : 
      80            [ + ]:          1 :         function create_xml(content){
      81                 :          2 :                 return '<?xml version="1.0" encoding="windows-1252"?><x>' + content + '</x>';
      82                 :          2 :         }
      83                 :          1 : 
      84            [ + ]:          1 :         function create_encoded_xml(encoded_content){
      85                 :          1 :                 return encodeURIComponent('<?xml version="1.0" encoding="windows-1252"?><x>') + encoded_content + encodeURIComponent('<\/x>');
      86                 :          1 :         }
      87                 :          1 : 
      88            [ + ]:          1 :         function request(type, input, output, responseType){
      89                 :         37 : 
      90                 :         37 :                 const xhr = new XMLHttpRequest();
      91                 :         37 : 
      92            [ + ]:         37 :                 if(responseType !== undefined) {
      93                 :         19 :                         xhr.responseType = responseType;
      94                 :         19 :                 }
      95                 :         37 : 
      96                 :         37 :                 xhr.open('GET', `${activeURL}/status.py?content=${input}&type=${encodeURIComponent(type)}`, true);
      97                 :         37 : 
      98            [ + ]:         37 :                 xhr.onload = () => {
      99                 :         37 :                         assert.strictEqual(xhr.responseText, output);
     100                 :         37 :                 };
     101                 :         37 : 
     102                 :         37 :                 xhr.send();
     103                 :         37 :         }
     104                 :          1 : }
     105                 :          2 : 
     106                 :          2 : /*
     107                 :          2 :  * responsetext-decoding.htm
     108                 :          2 :  *
     109                 :          2 : 
     110                 :          2 : <!doctype html>
     111                 :          2 : <html>
     112                 :          2 :   <head>
     113                 :          2 :     <meta charset="utf-8">
     114                 :          2 :     <title>XMLHttpRequest: responseText decoding</title>
     115                 :          2 :     <script src="/resources/testharness.js"></script>
     116                 :          2 :     <script src="/resources/testharnessreport.js"></script>
     117                 :          2 :   </head>
     118                 :          2 :   <body>
     119                 :          2 :     <script>
     120                 :          2 :       function create_html(content) {
     121                 :          2 :         return "<!doctype html><meta charset=windows-1252><x>" + content + "</x>";
     122                 :          2 :       }
     123                 :          2 :       function create_encoded_html(encoded_content) {
     124                 :          2 :         return encodeURIComponent("<!doctype html><meta charset=windows-1252><x>") + encoded_content + encodeURIComponent("<\/x>");
     125                 :          2 :       }
     126                 :          2 :       function create_xml(content) {
     127                 :          2 :         return "<?xml version='1.0' encoding='windows-1252'?><x>" + content + "</x>";
     128                 :          2 :       }
     129                 :          2 :       function create_encoded_xml(encoded_content) {
     130                 :          2 :         return encodeURIComponent("<?xml version='1.0' encoding='windows-1252'?><x>") + encoded_content + encodeURIComponent("<\/x>");
     131                 :          2 :       }
     132                 :          2 :       function request(type, input, output, responseType) {
     133                 :          2 :         async_test((test) => {
     134                 :          2 :           const client = new XMLHttpRequest();
     135                 :          2 :           if (responseType !== undefined) {
     136                 :          2 :             client.responseType = responseType;
     137                 :          2 :           }
     138                 :          2 :           client.open("GET", "resources/status.py?content=" + input + "&type=" + encodeURIComponent(type), true);
     139                 :          2 :           client.onload = test.step_func_done(() => {
     140                 :          2 :             assert_equals(client.responseText, output);
     141                 :          2 :           })
     142                 :          2 :           client.send(null);
     143                 :          2 :         }, document.title + " (" + type + " " + input + " " + (responseType ? " " + responseType : "empty") + ")");
     144                 :          2 :       }
     145                 :          2 : 
     146                 :          2 :       const encoded_content = "%e6%a9%9f";
     147                 :          2 :       const decoded_as_windows_1252 = "\u00e6\u00a9\u0178";
     148                 :          2 :       const decoded_as_utf_8 = "\u6a5f";
     149                 :          2 :       const encoded_xml = create_encoded_xml(encoded_content);
     150                 :          2 :       const encoded_html = create_encoded_html(encoded_content);
     151                 :          2 :       const xml_decoded_as_windows_1252 = create_xml(decoded_as_windows_1252);
     152                 :          2 :       const xml_decoded_as_utf_8 = create_xml(decoded_as_utf_8);
     153                 :          2 :       const html_decoded_as_windows_1252 = create_html(decoded_as_windows_1252);
     154                 :          2 :       const html_decoded_as_utf_8 = create_html(decoded_as_utf_8);
     155                 :          2 : 
     156                 :          2 :       // "default" response type
     157                 :          2 :       // An XML-ish response is sniffed.
     158                 :          2 :       request("application/xml", encoded_xml, xml_decoded_as_windows_1252);
     159                 :          2 :       // An HTML-ish response isn't sniffed.
     160                 :          2 :       request("text/html", encoded_html, html_decoded_as_utf_8);
     161                 :          2 :       request("application/xml;charset=utf-8", encoded_xml, xml_decoded_as_utf_8);
     162                 :          2 :       request("application/xml;charset=windows-1252", encoded_xml, xml_decoded_as_windows_1252);
     163                 :          2 :       request("text/html;charset=utf-8", encoded_html, html_decoded_as_utf_8);
     164                 :          2 :       request("text/html;charset=windows-1252", encoded_html, html_decoded_as_windows_1252);
     165                 :          2 :       request("text/plain;charset=windows-1252", "%FF", "\u00FF");
     166                 :          2 :       request("text/plain", "%FF", "\uFFFD");
     167                 :          2 :       request("text/plain", "%FE%FF", "");
     168                 :          2 :       request("text/plain", "%FE%FF%FE%FF", "\uFEFF");
     169                 :          2 :       request("text/plain", "%EF%BB%BF", "");
     170                 :          2 :       request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF");
     171                 :          2 :       request("text/plain", "%C2", "\uFFFD");
     172                 :          2 :       request("text/xml", "%FE%FF", "");
     173                 :          2 :       request("text/xml", "%FE%FF%FE%FF", "\uFEFF");
     174                 :          2 :       request("text/xml", "%EF%BB%BF", "");
     175                 :          2 :       request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF");
     176                 :          2 :       request("text/plain", "%E3%81%B2", "\u3072");
     177                 :          2 : 
     178                 :          2 :       // "text" response type
     179                 :          2 :       // An XML-ish response isn't sniffed.
     180                 :          2 :       request("application/xml", encoded_xml, xml_decoded_as_utf_8, "text");
     181                 :          2 :       // An HTML-ish response isn't sniffed.
     182                 :          2 :       request("text/html", encoded_html, html_decoded_as_utf_8, "text");
     183                 :          2 :       request("application/xml;charset=utf-8", encoded_xml, xml_decoded_as_utf_8, "text");
     184                 :          2 :       request("application/xml;charset=windows-1252", encoded_xml, xml_decoded_as_windows_1252, "text");
     185                 :          2 :       request("text/html;charset=utf-8", encoded_html, html_decoded_as_utf_8, "text");
     186                 :          2 :       request("text/html;charset=windows-1252", encoded_html, html_decoded_as_windows_1252, "text");
     187                 :          2 :       request("text/plain;charset=windows-1252", "%FF", "\u00FF", "text");
     188                 :          2 :       request("text/plain", "%FF", "\uFFFD", "text");
     189                 :          2 :       request("text/plain", "%FE%FF", "", "text");
     190                 :          2 :       request("text/plain", "%FE%FF%FE%FF", "\uFEFF", "text");
     191                 :          2 :       request("text/plain", "%EF%BB%BF", "", "text");
     192                 :          2 :       request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
     193                 :          2 :       request("text/plain", "%C2", "\uFFFD", "text");
     194                 :          2 :       request("text/plain;charset=bogus", "%C2", "\uFFFD", "text");
     195                 :          2 :       request("text/xml", "%FE%FF", "", "text");
     196                 :          2 :       request("text/xml", "%FE%FF%FE%FF", "\uFEFF", "text");
     197                 :          2 :       request("text/xml", "%EF%BB%BF", "", "text");
     198                 :          2 :       request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
     199                 :          2 :       request("text/plain", "%E3%81%B2", "\u3072", "text");
     200                 :          2 :     </script>
     201                 :          2 :   </body>
     202                 :          2 : </html>
     203                 :          2 : 
     204                 :          2 :  *
     205                 :          2 :  * responsetext-decoding.htm
     206                 :          2 :  */

Generated by: LCOV version 1.14