tor-browser

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

origin-comparison.any.js (2820B)


      1 // META: title=`Origin` comparison
      2 
      3 test(t => {
      4  const opaqueA = new Origin();
      5  const opaqueB = new Origin();
      6  assert_true(opaqueA.opaque);
      7  assert_true(opaqueB.opaque);
      8 
      9  assert_true(opaqueA.isSameOrigin(opaqueA), "Opaque origin should be same-origin with itself.");
     10  assert_true(opaqueA.isSameSite(opaqueA), "Opaque origin should be same-site with itself.");
     11  assert_false(opaqueA.isSameOrigin(opaqueB), "Opaque origin should not be same-origin with another opaque origin.");
     12  assert_false(opaqueA.isSameSite(opaqueB), "Opaque origin should not be same-site with another opaque origin.");
     13 }, "Comparison of opaque origins.");
     14 
     15 test(t => {
     16  const a = Origin.from("https://a.example");
     17  const a_a = Origin.from("https://a.a.example");
     18  const b_a = Origin.from("https://b.a.example");
     19  const b = Origin.from("https://b.example");
     20  const b_b = Origin.from("https://b.b.example");
     21 
     22  assert_true(a.isSameOrigin(a), "Origin should be same-origin with itself.");
     23  assert_false(a.isSameOrigin(a_a), "Origins with different subdomains should not be same-origin.");
     24  assert_false(a.isSameOrigin(b_a), "Origins with different subdomains should not be same-origin.");
     25  assert_false(a.isSameOrigin(b), "Origins with different domains should not be same-origin.");
     26  assert_false(a.isSameOrigin(b_b), "Origins with different domains should not be same-origin.");
     27 
     28  assert_true(a.isSameSite(a), "Origin should be same-site with itself.");
     29  assert_true(a.isSameSite(a_a), "Origins with same registrable domain should be same-site.");
     30  assert_true(a.isSameSite(b_a), "Origins with same registrable domain should be same-site.");
     31  assert_false(a.isSameSite(b), "Origins with different registrable domains should not be same-site.");
     32  assert_false(a.isSameSite(b_b), "Origins with different registrable domains should not be same-site.");
     33 
     34  assert_true(a_a.isSameSite(a), "Origins with same registrable domain should be same-site.");
     35  assert_true(a_a.isSameSite(a_a), "Origin should be same-site with itself.");
     36  assert_true(a_a.isSameSite(b_a), "Origins with same registrable domain should be same-site.");
     37  assert_false(a_a.isSameSite(b), "Origins with different registrable domains should not be same-site.");
     38  assert_false(a_a.isSameSite(b_b), "Origins with different registrable domains should not be same-site.");
     39 }, "Comparison of tuple origins.");
     40 
     41 test(t => {
     42  const http = Origin.from("http://a.example");
     43  const https = Origin.from("https://a.example");
     44 
     45  assert_false(http.isSameOrigin(https), "http is not same-site with https");
     46  assert_false(https.isSameOrigin(http), "https is not same-site with http");
     47 
     48  assert_false(http.isSameSite(https), "http is not same-site with https");
     49  assert_false(https.isSameSite(http), "https is not same-site with http");
     50 }, "Comparisons are schemeful.");