navigate-ancestor-helper.js (3111B)
1 async function runNavigateAncestorTest(test_type, ancestor_type) { 2 // Set up a detector to check that the top-level page doesn't navigate away. 3 window.onbeforeunload = 4 e => { 5 assert_unreached( 6 `The top-level test runner document does not navigate when a ` + 7 `${test_type} navigates ${ancestor_type}`); 8 } 9 10 let fenced_frame = await attachFencedFrameContext(); 11 await multiClick(10, 10, fenced_frame.element); 12 13 // This is the page that the inner frames will navigate to. 14 const [uuid, url] = generateRemoteContextURL([]); 15 16 switch (test_type) { 17 case 'top-level fenced frame': 18 // This fenced frame will attempt to navigate its parent. It should end up 19 // navigating *itself* since it is a top-level browsing context. Just in 20 // case it accidentally navigates *this* frame, we have an 21 // `onbeforeunload` handler that will automatically fail the test before. 22 await fenced_frame.execute(async (url, ancestor_type) => { 23 window.executor.suspend(() => { 24 window[ancestor_type].location = url; 25 }); 26 }, [url, ancestor_type]); 27 // Ensure that a navigation took place via the `window.location` call. 28 fenced_frame.context_id = uuid; 29 await fenced_frame.execute(() => {}); 30 break; 31 case 'nested fenced frame': 32 await fenced_frame.execute(async (url, uuid, ancestor_type) => { 33 const inner_fenced_frame = await attachFencedFrameContext(); 34 await inner_fenced_frame.execute((url, ancestor_type) => { 35 window.executor.suspend(() => { 36 window[ancestor_type].location = url; 37 }); 38 }, [url, ancestor_type]); 39 // Ensure that a navigation took place via the `window.location` call. 40 inner_fenced_frame.context_id = uuid; 41 await inner_fenced_frame.execute(() => {}); 42 }, [url, uuid, ancestor_type]); 43 // Check that the root fenced frame did not unload. The test will time out 44 // if it did. 45 await fenced_frame.execute(() => {}); 46 break; 47 case 'nested iframe': 48 // When the iframe tries to navigate its ancestor frame, it should not 49 // navigate *this* frame, because the sandboxed navigation browsing 50 // context flag must be set in fenced frame trees. See: 51 // https://html.spec.whatwg.org/multipage/origin.html#sandboxed-navigation-browsing-context-flag 52 await fenced_frame.execute(async (url, ancestor_type) => { 53 const inner_iframe = await attachIFrameContext(); 54 await inner_iframe.execute((url, ancestor_type) => { 55 try { 56 window[ancestor_type].location = url; 57 assert_unreached( 58 'The navigation from the nested iframe should ' + 59 'not be successful.'); 60 } catch (error) { 61 assert_equals(error.name, 'SecurityError'); 62 } 63 }, [url, ancestor_type]); 64 }, [url, ancestor_type]); 65 // Check that the root fenced frame did not unload. The test will time out 66 // if it did. 67 await fenced_frame.execute(() => {}); 68 break; 69 } 70 }