browser_inspector_search-clear.js (2751B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Bug 1295081 Test searchbox clear button's display behavior is correct 6 7 const XHTML = ` 8 <!DOCTYPE html> 9 <html xmlns="http://www.w3.org/1999/xhtml" 10 xmlns:svg="http://www.w3.org/2000/svg"> 11 <body> 12 <svg:svg width="100" height="100"> 13 <svg:clipPath> 14 <svg:rect x="0" y="0" width="10" height="5"></svg:rect> 15 </svg:clipPath> 16 <svg:circle cx="0" cy="0" r="5"></svg:circle> 17 </svg:svg> 18 </body> 19 </html> 20 `; 21 22 const TEST_URI = "data:application/xhtml+xml;charset=utf-8," + encodeURI(XHTML); 23 24 // Type "d" in inspector-searchbox, Enter [Back space] key and check if the 25 // clear button is shown correctly 26 add_task(async function () { 27 const { inspector } = await openInspectorForURL(TEST_URI); 28 const { searchBox, searchClearButton, search } = inspector; 29 30 await focusSearchBoxUsingShortcut(inspector.panelWin); 31 32 info("Type d and the clear button will be shown"); 33 34 const command = once(searchBox, "input"); 35 let onSearchProcessingDone = 36 inspector.searchSuggestions.once("processing-done"); 37 EventUtils.synthesizeKey("c", {}, inspector.panelWin); 38 await command; 39 40 info("Waiting for search query to complete and getting the suggestions"); 41 await onSearchProcessingDone; 42 43 ok( 44 !searchClearButton.hidden, 45 "The clear button is shown when some word is in searchBox" 46 ); 47 48 onSearchProcessingDone = inspector.searchSuggestions.once("processing-done"); 49 EventUtils.synthesizeKey("VK_BACK_SPACE", {}, inspector.panelWin); 50 await command; 51 52 info("Waiting for search query to complete and getting the suggestions"); 53 await onSearchProcessingDone; 54 55 ok( 56 searchClearButton.hidden, 57 "The clear button is hidden when no word is in searchBox" 58 ); 59 60 info("Check that clear button is keyboard accessible"); 61 onSearchProcessingDone = inspector.searchSuggestions.once("processing-done"); 62 EventUtils.synthesizeKey("w", {}, inspector.panelWin); 63 await onSearchProcessingDone; 64 65 ok( 66 !searchClearButton.hidden, 67 "The clear button is shown when some word is in searchBox" 68 ); 69 70 info("Focus clear button with Tab"); 71 EventUtils.synthesizeKey("VK_TAB", {}, inspector.panelWin); 72 is( 73 inspector.panelDoc.activeElement, 74 searchClearButton, 75 "Search clear button is focused" 76 ); 77 78 info("Hit Enter to clear search input"); 79 const onSearchCleared = search.once("search-cleared"); 80 EventUtils.synthesizeKey("VK_RETURN", {}, inspector.panelWin); 81 await onSearchCleared; 82 is(searchBox.value, "", "input was cleared"); 83 is( 84 inspector.panelDoc.activeElement, 85 searchBox, 86 "input is focused after hitting the clear button" 87 ); 88 });