nested-documents.html (2825B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/resources/testdriver.js"></script> 5 <script src="/resources/testdriver-vendor.js"></script> 6 <body> 7 <script type="module"> 8 import { 9 attachIframe, 10 makeCleanup, 11 getOppositeOrientation, 12 } from "./resources/orientation-utils.js"; 13 14 promise_test(async (t) => { 15 t.add_cleanup(makeCleanup()); 16 const iframe = await attachIframe(); 17 const iframeWin = iframe.contentWindow; 18 19 // Go full screen 20 await test_driver.bless("request full screen"); 21 await document.body.requestFullscreen(); 22 23 // Lock the orientation from the iframe 24 const opposite = getOppositeOrientation(); 25 const iframePromise = iframeWin.screen.orientation.lock(opposite); 26 27 // Calling lock() from top-level will cancel the iframe's promise 28 const topPromise = window.screen.orientation.lock(opposite); 29 await promise_rejects_dom( 30 t, 31 "AbortError", 32 iframeWin.DOMException, 33 iframePromise 34 ); 35 await topPromise; 36 }, "Requesting orientation lock from one document cancels the lock request from another document"); 37 38 promise_test(async (t) => { 39 t.add_cleanup(makeCleanup()); 40 // Create 2 nested iframes 41 const src = "/screen-orientation/resources/empty.html"; 42 const outerIframe = await attachIframe({ src: `${src}#1` }); 43 const innerIframe = await attachIframe({ 44 context: outerIframe.contentWindow, 45 src: `${src}#2`, 46 }); 47 48 const iframes = [outerIframe, innerIframe]; 49 50 // Go full screen 51 await test_driver.bless( 52 "request full screen" 53 ); 54 await document.documentElement.requestFullscreen(); 55 const opposite = getOppositeOrientation(); 56 57 // Each iframe tries to lock the orientation 58 const requestToLock = iframes.map((iframe) => { 59 return { 60 promise: iframe.contentWindow.screen.orientation.lock(opposite), 61 context: iframe.contentWindow, 62 }; 63 }); 64 65 // But calling lock() from top-level will aborts all iframe's promises 66 const topPromise = window.screen.orientation.lock(opposite); 67 68 // Check that all promises are rejected with AbortError 69 for (let i = 0; i < requestToLock.length; i++) { 70 const { promise, context } = requestToLock[i]; 71 await promise_rejects_dom( 72 t, 73 "AbortError", 74 context.DOMException, 75 promise, 76 `Expected request to lock orientation from iframe ${i} to abort` 77 ); 78 } 79 // Finally, top-level promise resolves 80 await topPromise; 81 }, "The orientation lock from one document affects lock requests from other documents"); 82 </script> 83 </body>