lock-basic.html (2874B)
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 { attachIframe, makeCleanup, getOppositeOrientation } from "./resources/orientation-utils.js"; 10 11 promise_test(async t => { 12 t.add_cleanup(makeCleanup()); 13 await test_driver.bless("request full screen") 14 await document.documentElement.requestFullscreen(); 15 const value = await screen.orientation.lock('any'); 16 assert_equals(value, undefined); 17 }, "Test that screen.orientation.lock returns a promise which will be fulfilled with a void value."); 18 19 promise_test(async t => { 20 t.add_cleanup(makeCleanup()); 21 await test_driver.bless("request full screen") 22 await document.documentElement.requestFullscreen(); 23 const initialOrientation = screen.orientation.type; 24 const orientations = [ 25 'any', 26 'natural', 27 'portrait', 28 'landscape', 29 'portrait-secondary', 30 'landscape-primary', 31 'landscape-secondary', 32 'portrait-primary', 33 ]; 34 for (const orientation of orientations) { 35 try { 36 await screen.orientation.lock(orientation); 37 } catch(err) { 38 if (err.name === "NotSupportedError") { 39 continue; 40 } 41 assert_unreached("Unknown error: " + err); 42 } 43 const { type } = screen.orientation; 44 switch (orientation) { 45 case 'any': 46 break; 47 case 'natural': 48 assert_true(type.endsWith("primary"), `Expected primary orientation for "${orientation}", got "${type}"`); 49 break; 50 case 'portrait': 51 assert_true(type.startsWith("portrait"), `Expected portrait orientation for "${orientation}", got "${type}"`); 52 break; 53 case 'landscape': 54 assert_true(type.startsWith("landscape"), `Expected landscape orientation for "${orientation}", got "${type}"`); 55 break; 56 default: 57 assert_equals(type, orientation, "Expected orientation to change"); 58 break; 59 } 60 await screen.orientation.lock(initialOrientation); 61 } 62 }, "Test that screen.orientation.lock returns a pending promise."); 63 64 promise_test(async t => { 65 t.add_cleanup(makeCleanup()); 66 await test_driver.bless("request full screen") 67 await document.documentElement.requestFullscreen(); 68 const initialType = screen.orientation.type; 69 const newType = getOppositeOrientation(); 70 const p = screen.orientation.lock(newType); 71 assert_equals(screen.orientation.type, initialType, "Must not change orientation until next spin of event loop"); 72 await p; 73 const finalType = screen.orientation.type; 74 assert_true(finalType.startsWith(newType), `Expected type to start with ${newType}, got "${finalType}"`); 75 }, "Test that screen.orientation.lock() is actually async"); 76 </script>