window-resize.html (1890B)
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 function tryRun(func) { 8 try { 9 func(); 10 } catch (e) { 11 const testChannel = new PrerenderChannel('test-channel'); 12 testChannel.postMessage({status: 'FAIL: ' + e}); 13 } 14 } 15 16 const params = new URLSearchParams(location.search); 17 18 // The main test page (restriction-window-resize.html) loads the 19 // initiator page, then the initiator page will prerender itself with the 20 // `prerendering` parameter. 21 const isPrerendering = params.has('prerendering'); 22 23 if (!isPrerendering) { 24 // Ensure that the primary page can resize this window. 25 tryRun(() => { 26 const expectedRect = { 27 width: window.outerWidth - 1, 28 height: window.outerHeight - 1 29 }; 30 window.resizeTo(expectedRect.width, expectedRect.height); 31 assert_equals(window.outerWidth, expectedRect.width, 'width for primary'); 32 assert_equals( 33 window.outerHeight, expectedRect.height, 'height for primary'); 34 }); 35 36 // Start prerendering a page which tries to resize this window. 37 loadInitiatorPage(); 38 } else { 39 const prevRect = {width: window.outerWidth, height: window.outerHeight}; 40 tryRun(() => { 41 // Try to resize this window, and should not succeed. 42 const resizeToOrResizeBy = params.get('resize'); 43 switch (resizeToOrResizeBy) { 44 case 'resizeTo': 45 window.resizeTo(prevRect.width + 1, prevRect.height + 1); 46 break; 47 case 'resizeBy': 48 window.resizeBy(1, 1); 49 break; 50 default: 51 assert_unreached(`wrong parameter: ${resizeToOrResizeBy}`); 52 } 53 }); 54 55 const bc = new PrerenderChannel('test-channel'); 56 bc.postMessage({ 57 'status': 'PASS', 58 'prevRect': prevRect, 59 'newRect': {width: window.outerWidth, height: window.outerHeight} 60 }); 61 bc.close(); 62 } 63 64 </script>