tor-browser

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

test_http3.js (4285B)


      1 "use strict";
      2 
      3 /* import-globals-from http3_common.js */
      4 
      5 // Max concurent stream number in neqo is 100.
      6 // Openning 120 streams will test queuing of streams.
      7 let number_of_parallel_requests = 120;
      8 let h3Route;
      9 let httpsOrigin;
     10 let h3AltSvc;
     11 let h3Port;
     12 let h3ServerDomain;
     13 let prefs;
     14 
     15 add_setup(async function () {
     16  let h2Port = Services.env.get("MOZHTTP2_PORT");
     17  Assert.notEqual(h2Port, null);
     18  Assert.notEqual(h2Port, "");
     19  h3Port = Services.env.get("MOZHTTP3_PORT");
     20  Assert.notEqual(h3Port, null);
     21  Assert.notEqual(h3Port, "");
     22  h3AltSvc = ":" + h3Port;
     23  h3ServerDomain = "foo.example.com";
     24  h3Route = `${h3ServerDomain}:${h3Port}`;
     25  do_get_profile();
     26  prefs = Services.prefs;
     27 
     28  prefs.setBoolPref("network.http.http3.enable", true);
     29  prefs.setCharPref(
     30    "network.dns.localDomains",
     31    "foo.example.com, alt1.example.com"
     32  );
     33  // We always resolve elements of localDomains as it's hardcoded without the
     34  // following pref:
     35  prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
     36  prefs.setBoolPref("network.http.altsvc.oe", true);
     37 
     38  if (mozinfo.os == "android") {
     39    // Set necessary prefs to make Firefox connect to the http3Server on the
     40    // host machine.
     41    prefs.setCharPref("network.dns.localDomains", "");
     42    const overrideService = Cc[
     43      "@mozilla.org/network/native-dns-override;1"
     44    ].getService(Ci.nsINativeDNSResolverOverride);
     45    overrideService.addIPOverride(h3ServerDomain, "10.0.2.2");
     46    prefs.setCharPref(
     47      "network.http.http3.alt-svc-mapping-for-testing",
     48      `${h3ServerDomain};h3=:${h3Port}`
     49    );
     50  }
     51 
     52  // The certificate for the http3server server is for foo.example.com and
     53  // is signed by http2-ca.pem so add that cert to the trust list as a
     54  // signing cert.
     55  let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     56    Ci.nsIX509CertDB
     57  );
     58  addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
     59  httpsOrigin = `https://${h3ServerDomain}:${h2Port}/`;
     60 
     61  registerCleanupFunction(() => {
     62    prefs.clearUserPref("network.http.http3.enable");
     63    prefs.clearUserPref("network.dns.localDomains");
     64    prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
     65    prefs.clearUserPref("network.http.altsvc.oe");
     66  });
     67 });
     68 
     69 add_task(async function test_https_alt_svc() {
     70  await waitForHttp3Route(httpsOrigin + "http3-test", h3Route, h3AltSvc, {
     71    delayMs: 500,
     72  });
     73 });
     74 
     75 add_task(async function test_multiple_requests() {
     76  await do_test_multiple_requests(
     77    number_of_parallel_requests,
     78    h3Route,
     79    httpsOrigin
     80  );
     81 });
     82 
     83 add_task(async function test_request_cancelled_by_server() {
     84  await do_test_request_cancelled_by_server(h3Route, httpsOrigin);
     85 });
     86 
     87 add_task(async function test_stream_cancelled_by_necko() {
     88  await do_test_stream_cancelled_by_necko(h3Route, httpsOrigin);
     89 });
     90 
     91 add_task(async function test_multiple_request_one_is_cancelled() {
     92  await do_test_multiple_request_one_is_cancelled(
     93    number_of_parallel_requests,
     94    h3Route,
     95    httpsOrigin
     96  );
     97 });
     98 
     99 add_task(async function test_multiple_request_one_is_cancelled_by_necko() {
    100  await do_test_multiple_request_one_is_cancelled_by_necko(
    101    number_of_parallel_requests,
    102    h3Route,
    103    httpsOrigin
    104  );
    105 });
    106 
    107 add_task(async function test_post() {
    108  await do_test_post(httpsOrigin, h3Route);
    109 });
    110 
    111 add_task(async function test_patch() {
    112  await do_test_patch(httpsOrigin, h3Route);
    113 });
    114 
    115 add_task(
    116  {
    117    // Skip this test on Android because the httpOrigin (http://foo.example.com)
    118    // is on 127.0.0.1, while the http3Server (https://foo.example.com) is
    119    // on 10.0.2.2. Currently, we can't change the IP mapping dynamically.
    120    skip_if: () => mozinfo.os == "android",
    121  },
    122  async function test_http_alt_svc() {
    123    setup_h1_server(h3ServerDomain);
    124    await waitForHttp3Route(httpOrigin + "http3-test", h3Route, h3AltSvc, {
    125      delayMs: 500,
    126    });
    127  }
    128 );
    129 
    130 add_task(async function test_slow_receiver() {
    131  await do_test_slow_receiver(httpsOrigin, h3Route);
    132 });
    133 
    134 // This test should be at the end, because it will close http3
    135 // connection and the transaction will switch to already existing http2
    136 // connection.
    137 // TODO: Bug 1582667 should try to fix issue with connection being closed.
    138 add_task(async function test_version_fallback() {
    139  await do_test_version_fallback(httpsOrigin);
    140 });