window-move.html (1970B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="utils.js"></script> 5 <script> 6 7 const params = new URLSearchParams(location.search); 8 9 // The main test page (restriction-window-move.html) loads the 10 // initiator page, then the initiator page will prerender itself with the 11 // `prerendering` parameter. 12 const isPrerendering = params.has('prerendering'); 13 14 function tryRun(func) { 15 try { 16 func(); 17 } catch (e) { 18 const testChannel = new PrerenderChannel('test-channel'); 19 testChannel.postMessage({status: 'FAIL: ' + e}); 20 } 21 } 22 23 if (!isPrerendering) { 24 // Ensure that the primary page can move this window. 25 tryRun(() => { 26 const expectedPosition = {x: screen.availLeft + 1, y: screen.availTop + 1}; 27 window.moveTo(expectedPosition.x, expectedPosition.y); 28 assert_equals(window.screenX, expectedPosition.x, 'x position for primary'); 29 assert_equals(window.screenY, expectedPosition.y, 'y position for primary'); 30 }); 31 // Start prerendering a page which tries to move this window. 32 loadInitiatorPage(); 33 } else { 34 const prevPosition = {x: window.screenX, y: window.screenY}; 35 tryRun( 36 () => { 37 // Try to move this window, and should not succeed. 38 const moveToOrMoveBy = params.get('move'); 39 switch (moveToOrMoveBy) { 40 case 'moveTo': 41 window.moveTo(screen.availLeft + 10, screen.availTop + 10); 42 break; 43 case 'moveBy': 44 window.moveBy(screen.availLeft + 10 - window.screenX, 45 screen.availTop + 10 - window.screenY); 46 break; 47 default: 48 assert_unreached(`wrong parameter: ${moveToOrMoveBy}`); 49 } 50 } 51 ); 52 53 const bc = new PrerenderChannel('test-channel'); 54 bc.postMessage({ 55 'status': 'PASS', 56 'prevPosition': prevPosition, 57 'newPosition': {x: window.screenX, y: window.screenY} 58 }); 59 bc.close(); 60 } 61 62 </script>