navigate-descendant-by-name.https.html (3612B)
1 <!DOCTYPE html> 2 <title>Test named frame navigation of descendants</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="resources/utils.js"></script> 6 <script src="/common/utils.js"></script> 7 8 <body> 9 <!-- This anchor element is clicked via script to navigate a target frame by 10 name. The target frame will always exist inside a fenced frame tree, and 11 therefore shouldn't actually work. The expected behavior is that the 12 navigation should end up in a new top-level browsing context, as per [1], 13 which will communicate back to the main page (via the server stash) 14 letting us know that the navigation succeeded, and did not successfully 15 target a frame inside the fenced frame boundary. 16 17 [1]: https://html.spec.whatwg.org/C/#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name 18 --> 19 <script> 20 const kAssertion = "The anchor element did not navigate a frame inside the " + 21 "fenced frame boundary: "; 22 // This is used by `navigate-by-name-reporting-helper.html` to let us know if 23 // the navigation correctly opened a new top-level popup window, or 24 // incorrectly targeted a browsing context inside the fenced frame boundary. 25 const navigation_success_key = token(); 26 // This is sent by the `navigate-by-name-inner.html` to indicate that it has 27 // set up a frame whose name is `target_frame`, that we are supposed to try 28 // and navigate by name. 29 const ready_for_navigation_key = token(); 30 31 const a = document.createElement("a"); 32 a.href = generateURL('resources/navigate-by-name-reporting-helper.html', 33 [navigation_success_key]); 34 a.innerText = "Click to navigate target frame"; 35 a.target = "target_frame"; 36 document.body.append(a); 37 38 async function runTest(test_type) { 39 const fenced_frame = 40 attachFencedFrame(generateURL( 41 `resources/navigate-by-name-inner.html`, 42 [ready_for_navigation_key, test_type])); 43 44 // Wait for the fenced frame to say it is ready for us (the outer page) to 45 // initiate a named frame navigation, targeting a frame inside the fence. 46 let result = await nextValueFromServer(ready_for_navigation_key); 47 assert_equals(result, "READY", "The top-level fenced frame is ready for " + 48 "us to navigate"); 49 50 // Now that the fenced frame has a frame whose name is `target_frame`, let's 51 // try and navigate it. 52 a.click(); 53 result = await nextValueFromServer(navigation_success_key); 54 assert_equals(result, "PASS", kAssertion + test_type); 55 56 // Get a reference to the window opened up by the anchor navigation, and 57 // close it. 58 const win = window.open("", "target_frame"); 59 win.close(); 60 61 // Clean up the fenced frame 62 document.body.removeChild(fenced_frame); 63 } 64 65 promise_test(async() => { 66 // First just test that when we have no real target frame to navigate, 67 // everything works as expected. 68 a.click(); 69 const result = await nextValueFromServer(navigation_success_key); 70 assert_equals(result, "PASS", "The initial test works"); 71 72 // Get a reference to the already-opened window and close it. 73 const win = window.open("", "target_frame"); 74 win.close(); 75 }, "setup"); 76 77 promise_test(async () => { 78 return runTest("top-level fenced frame"); 79 }, "navigate top-level fenced frame by name"); 80 81 promise_test(async () => { 82 return runTest("nested iframe"); 83 }, "navigate iframe nested in a fenced frame by name"); 84 85 promise_test(async () => { 86 return runTest("nested fenced frame"); 87 }, "navigate nested fenced frame by name"); 88 89 </script> 90 </body>