lock-sandboxed-iframe.html (1947B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <meta viewport="width=device-width, initial-scale=1" /> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script type="module"> 9 import { 10 attachIframe 11 } from "./resources/orientation-utils.js"; 12 13 function wait_result() { 14 return new Promise((resolve) => { 15 function callback(evt) { 16 switch (evt.data.result) { 17 case "locked": 18 resolve(evt.data.orientation); 19 break; 20 case "errored": 21 resolve(evt.data); 22 break; 23 default: 24 assert_unreached(`Unexpected message: ${evt.data.result}`); 25 return; 26 } 27 window.removeEventListener("message", callback); 28 } 29 window.addEventListener("message", callback); 30 }); 31 } 32 33 promise_test(async (t) => { 34 const iframe = await attachIframe({ 35 src: "resources/sandboxed-iframe-locking.html", 36 sandbox: "allow-scripts allow-same-origin", 37 }); 38 const message = await wait_result(); 39 assert_equals( 40 message.lock_name, 41 "SecurityError", 42 "screen.lockOrientation() throws a SecurityError" 43 ); 44 assert_equals( 45 message.unlock_name, 46 "SecurityError", 47 "screen.orientation.unlock() throws a SecurityError" 48 ); 49 }, "Test without 'allow-orientation-lock' sandboxing directive"); 50 51 promise_test(async (t) => { 52 const iframe = await attachIframe({ 53 src: "resources/sandboxed-iframe-locking.html", 54 sandbox: "allow-scripts allow-same-origin allow-orientation-lock", 55 }); 56 const message = await wait_result(); 57 assert_equals( 58 message, 59 "portrait-primary", 60 "screen.orientation lock to portrait-primary" 61 ); 62 }, "Test with 'allow-orientation-lock' sandboxing directive"); 63 </script>