LCOV - code coverage report
Current view: top level - test/wpt/xhr - send-sync-no-response-event-order.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 91 91 100.0 %
Date: 2024-12-07 00:20:21 Functions: 4 8 50.0 %
Branches: 6 6 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 :         let expect = [4, 'load', 'loadend'];
       7                 :          1 :         let actual = [];
       8                 :          1 : 
       9                 :          1 :         let xhr = new XMLHttpRequest();
      10                 :          1 : 
      11            [ + ]:          1 :         xhr.onreadystatechange = () => {
      12                 :          2 : 
      13            [ + ]:          2 :                 if(xhr.readyState === 4){
      14                 :          1 :                         actual.push(xhr.readyState);
      15                 :          1 :                 }
      16                 :          1 :         };
      17                 :          1 : 
      18                 :          1 :         xhr.onloadstart        = (e) => { actual.push(e.type); };
      19            [ + ]:          1 :         xhr.onload             = (e) => { actual.push(e.type); };
      20            [ + ]:          1 :         xhr.onloadend          = (e) => { actual.push(e.type); };
      21                 :          1 : 
      22                 :          1 :         xhr.upload.onload      = (e) => { actual.push('upload.' + e.type); };
      23                 :          1 :         xhr.upload.onloadstart = (e) => { actual.push('upload.' + e.type); };
      24                 :          1 :         xhr.upload.onloadend   = (e) => { actual.push('upload.' + e.type); };
      25                 :          1 : 
      26                 :          1 :         xhr.open('POST', `${activeURL}/content.py`, false);
      27                 :          1 :         xhr.send();
      28                 :          1 : 
      29                 :          1 :         assert.strictEqual(xhr.response, '');
      30                 :          1 :         assert.deepStrictEqual(actual, expect);
      31                 :          1 : }
      32                 :          2 : 
      33                 :          2 : /*
      34                 :          2 :  * send-sync-no-response-event-order.htm
      35                 :          2 :  *
      36                 :          2 : 
      37                 :          2 : <!DOCTYPE html>
      38                 :          2 : <html>
      39                 :          2 : <head>
      40                 :          2 :     <title>XMLHttpRequest: The send() method: event order when synchronous flag is set and there is no response entity body</title>
      41                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadstart" data-tested-assertations="../.." />
      42                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#handler-xhr-onloadend" data-tested-assertations="../.." />
      43                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-loadstart" data-tested-assertations="../.." />
      44                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#event-xhr-loadend" data-tested-assertations="../.." />
      45                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following-sibling::ol[1]/li[9]" />
      46                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#same-origin-request-steps" data-tested-assertations="following::DL[1]/DT[1]"/>
      47                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#infrastructure-for-the-send()-method" data-tested-assertations="following::dt[11] following::a[contains(@href,'#switch-done')]/.." />
      48                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#switch-done" data-tested-assertations="following::ol[1]/li[1] following::ol[1]/li[3] following::ol[1]/li[4] following::ol[1]/li[6] following::ol[1]/li[7]" />
      49                 :          2 :     <link rel="help" href="https://xhr.spec.whatwg.org/#the-response-attribute" data-tested-assertations="following::ol/li[3]" />
      50                 :          2 :     <script src="/resources/testharness.js"></script>
      51                 :          2 :     <script src="/resources/testharnessreport.js"></script>
      52                 :          2 : </head>
      53                 :          2 : 
      54                 :          2 : <body>
      55                 :          2 :     <div id="log"></div>
      56                 :          2 : 
      57                 :          2 :     <script type="text/javascript">
      58                 :          2 :         test(function () {
      59                 :          2 :             var xhr = new XMLHttpRequest();
      60                 :          2 :             var expect = [4, "load", "loadend"];
      61                 :          2 :             var actual = [];
      62                 :          2 : 
      63                 :          2 :             xhr.onreadystatechange = function()
      64                 :          2 :             {
      65                 :          2 :                 if (xhr.readyState == 4)
      66                 :          2 :                 {
      67                 :          2 :                     actual.push(xhr.readyState);
      68                 :          2 :                 }
      69                 :          2 :             };
      70                 :          2 : 
      71                 :          2 :             xhr.onloadstart        = function(e){ actual.push(e.type); };
      72                 :          2 :             xhr.onload             = function(e){ actual.push(e.type); };
      73                 :          2 :             xhr.onloadend          = function(e){ actual.push(e.type); };
      74                 :          2 : 
      75                 :          2 :             xhr.upload.onload      = function(e){ actual.push("upload." + e.type); };
      76                 :          2 :             xhr.upload.onloadstart = function(e){ actual.push("upload." + e.type); };
      77                 :          2 :             xhr.upload.onloadend   = function(e){ actual.push("upload." + e.type);};
      78                 :          2 : 
      79                 :          2 :             xhr.open("POST", "./resources/content.py", false);
      80                 :          2 :             xhr.send();
      81                 :          2 : 
      82                 :          2 :             assert_equals(xhr.response, "");
      83                 :          2 :             assert_array_equals(actual, expect);
      84                 :          2 :         });
      85                 :          2 :     </script>
      86                 :          2 : </body>
      87                 :          2 : </html>
      88                 :          2 : 
      89                 :          2 :  *
      90                 :          2 :  * send-sync-no-response-event-order.htm
      91                 :          2 :  */

Generated by: LCOV version 1.14