tor-browser

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

object-fallback-failed-cross-origin-navigation.sub.html (2625B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>Test that &lt;object&gt; renders its own fallback.</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <body>
      7 <script>
      8  const URIS = [
      9    // The host exists but the resource is unavailable.
     10    "http://{{hosts[alt][www]}}:{{ports[http][0]}}/foo.html",
     11    // The destination does not even exist and the navigation fails.
     12    "http://{{hosts[alt][nonexistent]}}:{{ports[http][0]}}/foo.html",
     13  ];
     14 
     15  // Create an <object> with some fallback content.
     16  function create_object_with_fallback(url, t) {
     17    var object = document.createElement("object");
     18    var fallback = document.createElement("button");
     19    fallback.textContent = "FALLBACK CONTENT";
     20    object.appendChild(fallback);
     21    object.data = url;
     22    object.type = "text/html";
     23    let promise = new Promise(resolve => {
     24      object.addEventListener("load", t.unreached_func("Should never reach the load event"), {once: true});
     25      object.addEventListener("error", () => resolve(object), {once: true});
     26    });
     27    document.body.appendChild(object);
     28    t.add_cleanup(() => object.remove());
     29    return promise;
     30  }
     31 
     32  function area(el) {
     33    let bounds = el.getBoundingClientRect();
     34    return bounds.width * bounds.height;
     35  }
     36 
     37  for (let uri of URIS) {
     38    promise_test(async(t) => {
     39      let object = await create_object_with_fallback(uri, t);
     40 
     41      // XXX In Chrome this is needed, fallback doesn't seem to be ready after
     42      // the error event, which seems weird/odd.
     43      await new Promise(resolve => requestAnimationFrame(resolve));
     44 
     45      assert_true(area(object.firstChild) > 0, "Should be showing fallback");
     46 
     47      // Per https://html.spec.whatwg.org/#the-object-element:
     48      //
     49      //     The object element can represent an external resource, which,
     50      //     depending on the type of the resource, will either be treated as
     51      //     image, as a child browsing context, or as an external resource to
     52      //     be processed by a plugin.
     53      //
     54      //     [...]
     55      //
     56      //     If the load failed (e.g. there was an HTTP 404 error, there was a
     57      //     DNS error), fire an event named error at the element, then jump to
     58      //     the step below labeled fallback.
     59      //
     60      // (And that happens before "Determine the resource type" which is what
     61      // sets the nested browsing context).
     62      //
     63      // So the expected window.length is 0.
     64      assert_equals(window.length, 0);
     65    }, `Verify fallback content for failed cross-origin navigations is shown correctly: ${uri}`);
     66  }
     67 </script>
     68 </body>