browser_inspector_search-sidebar.js (2771B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that depending where the user last clicked in the inspector, the right search 6 // field is focused when ctrl+F is pressed. 7 8 add_task(async function () { 9 const { inspector } = await openInspectorForURL( 10 "data:text/html;charset=utf-8,Search!" 11 ); 12 13 info("Check that by default, the inspector search field gets focused"); 14 pressCtrlF(); 15 isInInspectorSearchBox(inspector); 16 17 info("Click somewhere in the rule-view"); 18 moveFocusInRuleView(inspector); 19 20 info("Check that the rule-view search field gets focused"); 21 pressCtrlF(); 22 isInRuleViewSearchBox(inspector); 23 24 info("Click in the inspector again"); 25 await clickContainer("head", inspector); 26 27 info( 28 "Check that now we're back in the inspector, its search field gets focused" 29 ); 30 pressCtrlF(); 31 isInInspectorSearchBox(inspector); 32 33 info("Switch to the computed view, and click somewhere inside it"); 34 selectComputedView(inspector); 35 clickInComputedView(inspector); 36 37 info("Check that the computed-view search field gets focused"); 38 pressCtrlF(); 39 isInComputedViewSearchBox(inspector); 40 41 info("Click in the inspector yet again"); 42 await clickContainer("body", inspector); 43 44 info( 45 "We're back in the inspector again, check the inspector search field focuses" 46 ); 47 pressCtrlF(); 48 isInInspectorSearchBox(inspector); 49 }); 50 51 function pressCtrlF() { 52 EventUtils.synthesizeKey("f", { accelKey: true }); 53 } 54 55 function moveFocusInRuleView(inspector) { 56 // Only focus an element in the view so this has no unintended effects. 57 // Put the focus on the `element` closing bracket, which should always be visible 58 // and is focusable as it's a button. 59 inspector.panelDoc 60 .querySelector("#sidebar-panel-ruleview .ruleview-ruleclose") 61 .focus(); 62 } 63 64 function clickInComputedView(inspector) { 65 const el = inspector.panelDoc.querySelector("#sidebar-panel-computedview"); 66 EventUtils.synthesizeMouseAtCenter(el, {}, inspector.panelDoc.defaultView); 67 } 68 69 function isInInspectorSearchBox(inspector) { 70 // Focus ends up in an anonymous child of the XUL textbox. 71 ok( 72 inspector.panelDoc.activeElement.closest("#inspector-searchbox"), 73 "The inspector search field is focused when ctrl+F is pressed" 74 ); 75 } 76 77 function isInRuleViewSearchBox(inspector) { 78 is( 79 inspector.panelDoc.activeElement, 80 inspector.getPanel("ruleview").view.searchField, 81 "The rule-view search field is focused when ctrl+F is pressed" 82 ); 83 } 84 85 function isInComputedViewSearchBox(inspector) { 86 is( 87 inspector.panelDoc.activeElement, 88 inspector.getPanel("computedview").computedView.searchField, 89 "The computed-view search field is focused when ctrl+F is pressed" 90 ); 91 }