tor-browser

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

client-navigate-worker.js (3922B)


      1 importScripts("worker-testharness.js");
      2 importScripts("test-helpers.sub.js");
      3 importScripts("/common/get-host-info.sub.js")
      4 importScripts("testharness-helpers.js")
      5 
      6 setup({ explicit_done: true });
      7 
      8 self.onfetch = function(e) {
      9  if (e.request.url.indexOf("client-navigate-frame.html") >= 0) {
     10    return;
     11  }
     12  e.respondWith(new Response(e.clientId));
     13 };
     14 
     15 function pass(test, url) {
     16  return { result: test,
     17           url: url };
     18 }
     19 
     20 function fail(test, reason) {
     21  return { result: "FAILED " + test + " " + reason }
     22 }
     23 
     24 self.onmessage = function(e) {
     25  var port = e.data.port;
     26  var test = e.data.test;
     27  var clientId = e.data.clientId;
     28  var clientUrl = "";
     29  if (test === "test_client_navigate_success") {
     30    promise_test(function(t) {
     31      this.add_cleanup(() => port.postMessage(pass(test, clientUrl)));
     32      return self.clients.get(clientId)
     33                 .then(client => client.navigate("client-navigated-frame.html"))
     34                 .then(client => {
     35                   clientUrl = client.url;
     36                   assert_true(client instanceof WindowClient);
     37                 })
     38                 .catch(unreached_rejection(t));
     39    }, "Return value should be instance of WindowClient");
     40    done();
     41  } else if (test === "test_client_navigate_cross_origin") {
     42    promise_test(function(t) {
     43      this.add_cleanup(() => port.postMessage(pass(test, clientUrl)));
     44      var path = new URL('client-navigated-frame.html', self.location.href).pathname;
     45      var url = get_host_info()['HTTPS_REMOTE_ORIGIN'] + path;
     46      return self.clients.get(clientId)
     47                 .then(client => client.navigate(url))
     48                 .then(client => {
     49                   clientUrl = (client && client.url) || "";
     50                   assert_equals(client, null,
     51                                 'cross-origin navigate resolves with null');
     52                 })
     53                 .catch(unreached_rejection(t));
     54    }, "Navigating to different origin should resolve with null");
     55    done();
     56  } else if (test === "test_client_navigate_about_blank") {
     57    promise_test(function(t) {
     58      this.add_cleanup(function() { port.postMessage(pass(test, "")); });
     59      return self.clients.get(clientId)
     60                 .then(client => promise_rejects_js(t, TypeError, client.navigate("about:blank")))
     61                 .catch(unreached_rejection(t));
     62    }, "Navigating to about:blank should reject with TypeError");
     63    done();
     64  } else if (test === "test_client_navigate_mixed_content") {
     65    promise_test(function(t) {
     66      this.add_cleanup(function() { port.postMessage(pass(test, "")); });
     67      var path = new URL('client-navigated-frame.html', self.location.href).pathname;
     68      // Insecure URL should fail since the frame is owned by a secure parent
     69      // and navigating to http:// would create a mixed-content violation.
     70      var url = get_host_info()['HTTP_REMOTE_ORIGIN'] + path;
     71      return self.clients.get(clientId)
     72                 .then(client => promise_rejects_js(t, TypeError, client.navigate(url)))
     73                 .catch(unreached_rejection(t));
     74    }, "Navigating to mixed-content iframe should reject with TypeError");
     75    done();
     76  } else if (test === "test_client_navigate_redirect") {
     77    var host_info = get_host_info();
     78    var url = new URL(host_info['HTTPS_REMOTE_ORIGIN']).toString() +
     79              new URL("client-navigated-frame.html", location).pathname.substring(1);
     80    promise_test(function(t) {
     81      this.add_cleanup(() => port.postMessage(pass(test, clientUrl)));
     82      return self.clients.get(clientId)
     83                 .then(client => client.navigate("redirect.py?Redirect=" + url))
     84                 .then(client => {
     85                   clientUrl = (client && client.url) || ""
     86                   assert_equals(client, null);
     87                 })
     88                 .catch(unreached_rejection(t));
     89    }, "Redirecting to another origin should resolve with null");
     90    done();
     91  }
     92 };