Update WPT tests for embedded content
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / semantics / embedded-content / the-object-element / object-fallback-failed-cross-origin-navigation.sub.html
1 n<!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   // The host exists but the resource is unavailable.
9   const cross_origin_url_a = "http://{{hosts[alt][www]}}:{{ports[http][0]}}/foo.html";
10   // The destination does not even exist and the navigation fails.
11   const cross_origin_url_b = "http://{{hosts[alt][nonexistent]}}:{{ports[http][0]}}/foo.html";
12
13   // Returns a promise which is resolved when |callback| returns true. The |callback| is invoked at
14   // every animation frame.
15   function for_each_animation_frame(callback) {
16     return new Promise((resolve) => {
17       function on_raf() {
18         if (!callback())
19           resolve();
20         window.requestAnimationFrame(on_raf);
21       }
22       window.requestAnimationFrame(on_raf);
23     });
24   }
25
26   // Create an <object> with some fallback content.
27   function create_object_with_fallback(url) {
28     var object = document.createElement("object");
29     var fallback = document.createElement("button");
30     fallback.textContent = "FALLBACK CONTENT";
31     object.appendChild(fallback);
32     object.data = url;
33     object.type = "text/html";
34     document.body.appendChild(object);
35     return object;
36   }
37
38   function area(el) {
39     let bounds = el.getBoundingClientRect();
40     return el.width * el.height;
41   }
42
43   promise_test(async() => {
44     var object = create_object_with_fallback(cross_origin_url_a);
45     await for_each_animation_frame(() => area(object.firstChild) > 0);
46     object.parentElement.removeChild(object);
47     object = create_object_with_fallback(cross_origin_url_b);
48     await for_each_animation_frame(() => area(object.firstChild) > 0);
49     object.parentElement.removeChild(object);
50   }, "Verify fallback content for failed cross-origin navigations is shown correctly.");
51 </script>
52 </body>