tor-browser

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

origin-from-window.window.js (2256B)


      1 // META: title=`Origin.from(Location)`
      2 // META: script=/common/get-host-info.sub.js
      3 
      4 test(t => {
      5  const origin = Origin.from(window);
      6  assert_true(!!origin);
      7  assert_false(origin.opaque);
      8  assert_true(origin.isSameOrigin(Origin.from(get_host_info().ORIGIN)));
      9 }, `Origin.from(window) returns a tuple origin.`);
     10 
     11 async_test(t => {
     12  const el = document.createElement('iframe');
     13  el.src = "/common/blank.html";
     14  el.onload = t.step_func_done(_ => {
     15    const origin = Origin.from(el.contentWindow);
     16    assert_true(!!origin);
     17    assert_false(origin.opaque);
     18    assert_true(origin.isSameOrigin(Origin.from(get_host_info().ORIGIN)));
     19  });
     20  document.body.appendChild(el);
     21 }, `Origin.from(Window) returns a tuple origin for same-origin frames.`);
     22 
     23 async_test(t => {
     24  const el = document.createElement('iframe');
     25  el.src = get_host_info().REMOTE_ORIGIN + "/common/blank.html";
     26  el.onload = t.step_func_done(_ => {
     27    assert_throws_js(TypeError, _ => Origin.from(el.contentWindow));
     28  });
     29  document.body.appendChild(el);
     30 }, `Origin.from(Window) throws for cross-origin frames.`);
     31 
     32 async_test(t => {
     33  const el = document.createElement('iframe');
     34  el.src = "/common/blank.html";
     35  el.sandbox = "allow-scripts";
     36  el.onload = t.step_func_done(_ => {
     37    assert_throws_js(TypeError, _ => Origin.from(el.contentWindow));
     38    t.done();
     39  });
     40  document.body.appendChild(el);
     41 }, `Origin.from(Window) throws for sandboxed frames.`);
     42 
     43 async_test(t => {
     44  const w = window.open("/html/browsers/windows/resources/post-to-opener.html");
     45  window.addEventListener("message", t.step_func(e => {
     46    if (e.source === w) {
     47      const origin = Origin.from(w);
     48      assert_true(!!origin);
     49      assert_false(origin.opaque);
     50      assert_true(origin.isSameOrigin(Origin.from(get_host_info().ORIGIN)));
     51      t.done();
     52    }
     53  }));
     54 }, `Origin.from(Window) returns a tuple origin for same-origin windows.`);
     55 
     56 async_test(t => {
     57  const w = window.open(get_host_info().REMOTE_ORIGIN + "/html/browsers/windows/resources/post-to-opener.html");
     58  window.addEventListener("message", t.step_func(e => {
     59    if (e.source === w) {
     60      assert_throws_js(TypeError, _ => Origin.from(w));
     61      t.done();
     62    }
     63  }));
     64 }, `Origin.from(Window) throws for cross-origin windows.`);