tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fetch-request-xhr-sync.https.html (1743B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: Synchronous XHR is intercepted</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="resources/test-helpers.sub.js"></script>
      6 <script>
      7 'use strict';
      8 
      9 promise_test(function(t) {
     10    var url = 'resources/fetch-request-xhr-sync-worker.js';
     11    var scope = 'resources/fetch-request-xhr-sync-iframe.html';
     12    var non_existent_file = 'non-existent-file.txt';
     13 
     14    return service_worker_unregister_and_register(t, url, scope)
     15      .then(function(registration) {
     16          t.add_cleanup(function() {
     17              return registration.unregister();
     18            });
     19 
     20          return wait_for_state(t, registration.installing, 'activated');
     21        })
     22      .then(function() { return with_iframe(scope); })
     23      .then(function(frame) {
     24          t.add_cleanup(function() {
     25              frame.remove();
     26            });
     27 
     28          return new Promise(function(resolve, reject) {
     29              t.step_timeout(function() {
     30                  var xhr;
     31                  try {
     32                    xhr = frame.contentWindow.performSyncXHR(non_existent_file);
     33                    resolve(xhr);
     34                  } catch (err) {
     35                    reject(err);
     36                  }
     37                }, 0);
     38            })
     39        })
     40      .then(function(xhr) {
     41          assert_equals(
     42              xhr.status,
     43              200,
     44              'HTTP response status code for intercepted request'
     45            );
     46          assert_equals(
     47              xhr.responseText,
     48              'Response from service worker',
     49              'HTTP response text for intercepted request'
     50            );
     51        });
     52  }, 'Verify SyncXHR is intercepted');
     53 </script>