browser_inspector_search-08.js (2079B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that searching for namespaced elements does work. 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 // An array of (key, suggestions) pairs where key is a key to press and 25 // suggestions is an array of suggestions that should be shown in the popup. 26 const TEST_DATA = [ 27 { 28 key: "c", 29 suggestions: ["circle", "clipPath"], 30 }, 31 { 32 key: "VK_BACK_SPACE", 33 suggestions: [], 34 }, 35 { 36 key: "s", 37 suggestions: ["svg"], 38 }, 39 ]; 40 41 add_task(async function () { 42 const { inspector } = await openInspectorForURL(TEST_URI); 43 const { searchBox } = inspector; 44 const popup = inspector.searchSuggestions.searchPopup; 45 46 await focusSearchBoxUsingShortcut(inspector.panelWin); 47 48 for (const { key, suggestions } of TEST_DATA) { 49 info("Pressing " + key + " to get " + suggestions.join(", ")); 50 51 const command = once(searchBox, "input"); 52 const onSearchProcessingDone = 53 inspector.searchSuggestions.once("processing-done"); 54 EventUtils.synthesizeKey(key, {}, inspector.panelWin); 55 await command; 56 57 info("Waiting for search query to complete and getting the suggestions"); 58 await onSearchProcessingDone; 59 const actualSuggestions = popup.getItems(); 60 61 is( 62 popup.isOpen ? actualSuggestions.length : 0, 63 suggestions.length, 64 "There are expected number of suggestions." 65 ); 66 67 for (let i = 0; i < suggestions.length; i++) { 68 is( 69 actualSuggestions[i].label, 70 suggestions[i], 71 "The suggestion at " + i + "th index is correct." 72 ); 73 } 74 } 75 });