helper_focus_state_bug1860414.html (3859B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="initial-scale=1,width=device-width"> 6 <script src="apz_test_utils.js"></script> 7 <script src="apz_test_native_event_utils.js"></script> 8 <script src="/tests/SimpleTest/EventUtils.js"></script> 9 <script src="/tests/SimpleTest/NativeKeyCodes.js"></script> 10 <script src="/tests/SimpleTest/paint_listener.js"></script> 11 <style> 12 body { 13 margin: 0; 14 padding: 0; 15 } 16 .spacer { 17 height: 5000px; 18 } 19 20 #target { 21 height:50px; 22 width: 50px; 23 } 24 25 #target:focus { 26 outline: none; 27 } 28 </style> 29 </head> 30 <body> 31 <div class="spacer"> 32 </div> 33 <div tabindex=1 id="target"> 34 </div> 35 </body> 36 <script> 37 38 function nativeHomeKey() { 39 switch (getPlatform()) { 40 case "windows": 41 return WIN_VK_HOME; 42 case "mac": 43 return MAC_VK_Home; 44 } 45 throw new Error( 46 "Native key events not supported on platform " + getPlatform() 47 ); 48 } 49 50 function nativeEndKey() { 51 switch (getPlatform()) { 52 case "windows": 53 return WIN_VK_END; 54 case "mac": 55 return MAC_VK_End; 56 } 57 throw new Error( 58 "Native key events not supported on platform " + getPlatform() 59 ); 60 } 61 62 function nativeTabKey() { 63 switch (getPlatform()) { 64 case "windows": 65 return WIN_VK_TAB; 66 case "mac": 67 return MAC_VK_Tab; 68 } 69 throw new Error( 70 "Native key events not supported on platform " + getPlatform() 71 ); 72 } 73 74 async function test() { 75 let utils = SpecialPowers.DOMWindowUtils; 76 77 if (!SpecialPowers.getBoolPref("apz.keyboard.focus-optimization")) { 78 ok(true, "Skip test if paints are not guaranteed on each focus changing event"); 79 return; 80 } 81 82 is(document.scrollingElement.scrollTop, 0, "No scroll should have occured yet"); 83 84 utils.advanceTimeAndRefresh(50); 85 utils.restoreNormalRefresh(); 86 await promiseApzFlushedRepaints(); 87 await promiseFrame(); 88 89 let transformEndPromise = promiseTransformEnd(); 90 91 info("Synthesize a End key to trigger keyboard scroll to the bottom"); 92 await new Promise(resolve => { 93 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, nativeEndKey(), {}, 94 "", "", resolve); 95 }); 96 97 await transformEndPromise; 98 await promiseApzFlushedRepaints(); 99 await promiseFrame(); 100 101 is(checkHasAsyncKeyScrolled(), false, 102 "We should have no async scrolls in the test setup"); 103 104 info("Synthesize a TAB key to trigger a focus state change"); 105 await new Promise(resolve => { 106 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, nativeTabKey(), {}, 107 "", "", resolve); 108 }); 109 // Remove focus from the target to ensure that we can async scroll. 110 target.blur(); 111 112 utils.advanceTimeAndRefresh(50); 113 utils.restoreNormalRefresh(); 114 await promiseApzFlushedRepaints(); 115 116 info("Synthesize a Home key to trigger keyboard scroll to the top"); 117 transformEndPromise = promiseTransformEnd(); 118 await new Promise(resolve => { 119 synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, nativeHomeKey(), {}, 120 "", "", resolve); 121 }); 122 123 await transformEndPromise; 124 await promiseApzFlushedRepaints(); 125 await promiseFrame(); 126 127 is(checkHasAsyncKeyScrolled(), true, 128 "The focus change should not have invalidated our focus state"); 129 } 130 131 function checkHasAsyncKeyScrolled() { 132 // Reconstruct the APZC tree structure in the last paint. 133 var apzcTree = getLastApzcTree(); 134 var rcd = findRcdNode(apzcTree); 135 136 if (rcd) { 137 return rcd.hasAsyncKeyScrolled === "1"; 138 } 139 140 info("Last paint rcd is null"); 141 return false; 142 } 143 144 function isOnChaosMode() { 145 return SpecialPowers.Services.env.get("MOZ_CHAOSMODE"); 146 } 147 148 if ((getPlatform() == "mac" || getPlatform() == "windows") && 149 !isOnChaosMode()) { 150 waitUntilApzStable() 151 .then(test) 152 .then(subtestDone, subtestFailed); 153 } else { 154 ok(true, "Skipping test, native key events are not supported on " + 155 getPlatform()); 156 subtestDone(); 157 } 158 </script> 159 </html>