browser_test_select_popup_position.js (4683B)
1 /* This test is a a mash up of 2 https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/gfx/layers/apz/test/mochitest/browser_test_group_fission.js 3 https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/gfx/layers/apz/test/mochitest/helper_basic_zoom.html 4 https://searchfox.org/mozilla-central/rev/559b25eb41c1cbffcb90a34e008b8288312fcd25/browser/base/content/test/forms/browser_selectpopup.js 5 */ 6 7 /* import-globals-from helper_browser_test_utils.js */ 8 Services.scriptloader.loadSubScript( 9 new URL("helper_browser_test_utils.js", gTestPath).href, 10 this 11 ); 12 13 async function runPopupPositionTest(parentDocumentFileName) { 14 function httpURL(filename) { 15 let chromeURL = getRootDirectory(gTestPath) + filename; 16 return chromeURL.replace( 17 "chrome://mochitests/content/", 18 "http://mochi.test:8888/" 19 ); 20 } 21 22 function httpCrossOriginURL(filename) { 23 let chromeURL = getRootDirectory(gTestPath) + filename; 24 return chromeURL.replace( 25 "chrome://mochitests/content/", 26 "http://example.com/" 27 ); 28 } 29 30 const pageUrl = httpURL(parentDocumentFileName); 31 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl); 32 33 // Load the OOP iframe. 34 const iframeUrl = httpCrossOriginURL( 35 "helper_test_select_popup_position.html" 36 ); 37 const iframe = await SpecialPowers.spawn( 38 tab.linkedBrowser, 39 [iframeUrl], 40 async url => { 41 const target = content.document.querySelector("iframe"); 42 target.src = url; 43 await new Promise(resolve => { 44 target.addEventListener("load", resolve, { once: true }); 45 }); 46 return target.browsingContext; 47 } 48 ); 49 50 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 51 await content.wrappedJSObject.promiseApzFlushedRepaints(); 52 await content.wrappedJSObject.waitUntilApzStable(); 53 }); 54 55 const selectRect = await SpecialPowers.spawn(iframe, [], () => { 56 return content.document.querySelector("select").getBoundingClientRect(); 57 }); 58 59 // Get focus on the select element. 60 await SpecialPowers.spawn(iframe, [], async () => { 61 const select = content.document.querySelector("select"); 62 const focusPromise = new Promise(resolve => { 63 select.addEventListener("focus", resolve, { once: true }); 64 }); 65 select.focus(); 66 await focusPromise; 67 }); 68 69 const selectPopup = await openSelectPopup(); 70 71 const popupRect = selectPopup.getBoundingClientRect(); 72 const popupMarginTop = parseFloat(getComputedStyle(selectPopup).marginTop); 73 const popupMarginLeft = parseFloat(getComputedStyle(selectPopup).marginLeft); 74 let sidebarRevampEnabled = Services.prefs.getBoolPref( 75 "sidebar.revamp", 76 false 77 ); 78 let sidebarWidth; 79 if (sidebarRevampEnabled) { 80 const sidebar = document.querySelector("sidebar-main"); 81 sidebarWidth = sidebar.getBoundingClientRect().width; 82 } 83 84 info( 85 `popup rect: (${popupRect.x}, ${popupRect.y}) ${popupRect.width}x${popupRect.height}` 86 ); 87 info(`popup margins: ${popupMarginTop} / ${popupMarginLeft}`); 88 info( 89 `select rect: (${selectRect.x}, ${selectRect.y}) ${selectRect.width}x${selectRect.height}` 90 ); 91 92 is( 93 !sidebarRevampEnabled 94 ? popupRect.left - popupMarginLeft 95 : popupRect.left - popupMarginLeft - sidebarWidth, 96 selectRect.x * 2.0, 97 "select popup position x should be scaled by the desktop zoom" 98 ); 99 100 // On platforms other than MaxOSX the popup menu is positioned below the 101 // option element. 102 if (!navigator.platform.includes("Mac")) { 103 is( 104 popupRect.top - popupMarginTop, 105 tab.linkedBrowser.getBoundingClientRect().top + 106 (selectRect.y + selectRect.height) * 2.0, 107 "select popup position y should be scaled by the desktop zoom" 108 ); 109 } else { 110 // On mac it's aligned to the selected menulist option. 111 const offsetToSelectedItem = 112 selectPopup.querySelector("menuitem[selected]").getBoundingClientRect() 113 .top - popupRect.top; 114 is( 115 popupRect.top - popupMarginTop + offsetToSelectedItem, 116 tab.linkedBrowser.getBoundingClientRect().top + selectRect.y * 2.0, 117 "select popup position y should be scaled by the desktop zoom" 118 ); 119 } 120 121 await hideSelectPopup(); 122 123 BrowserTestUtils.removeTab(tab); 124 } 125 126 add_task(async function () { 127 if (!SpecialPowers.useRemoteSubframes) { 128 ok( 129 true, 130 "popup window position in non OOP iframe will be fixed by bug 1691346" 131 ); 132 return; 133 } 134 await runPopupPositionTest( 135 "helper_test_select_popup_position_transformed_in_parent.html" 136 ); 137 }); 138 139 add_task(async function () { 140 await runPopupPositionTest("helper_test_select_popup_position_zoomed.html"); 141 });