browser_jsterm_completion_bracket_cached_results.js (3677B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests that code completion works properly with `[` and cached results 5 6 "use strict"; 7 8 const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html><p>test [ completion cached results. 9 <script> 10 window.testObject = Object.create(null, Object.getOwnPropertyDescriptors({ 11 bar: 0, 12 dataTest: 1, 13 "data-test": 2, 14 'da"ta"test': 3, 15 "da\`ta\`test": 4, 16 "da'ta'test": 5, 17 "DATA-TEST": 6, 18 })); 19 </script>`; 20 21 add_task(async function () { 22 await pushPref("devtools.editor.autoclosebrackets", false); 23 const hud = await openNewTabAndConsole(TEST_URI); 24 const { jsterm } = hud; 25 26 info("Test that the autocomplete cache works with brackets"); 27 const { autocompletePopup } = jsterm; 28 29 const tests = [ 30 { 31 description: "Test that it works if the user did not type a quote", 32 initialInput: `window.testObject[dat`, 33 expectedItems: [`"data-test"`, `"dataTest"`, `"DATA-TEST"`], 34 expectedCompletionText: `a-test"]`, 35 sequence: [ 36 { 37 char: "a", 38 expectedItems: [`"data-test"`, `"dataTest"`, `"DATA-TEST"`], 39 expectedCompletionText: `-test"]`, 40 }, 41 { 42 char: "-", 43 expectedItems: [`"data-test"`, `"DATA-TEST"`], 44 expectedCompletionText: `test"]`, 45 }, 46 { 47 char: "t", 48 expectedItems: [`"data-test"`, `"DATA-TEST"`], 49 expectedCompletionText: `est"]`, 50 }, 51 { 52 char: "e", 53 expectedItems: [`"data-test"`, `"DATA-TEST"`], 54 expectedCompletionText: `st"]`, 55 }, 56 ], 57 }, 58 { 59 description: "Test that it works if the user did type a quote", 60 initialInput: `window.testObject['dat`, 61 expectedItems: [`'data-test'`, `'dataTest'`, `'DATA-TEST'`], 62 expectedCompletionText: `a-test']`, 63 sequence: [ 64 { 65 char: "a", 66 expectedItems: [`'data-test'`, `'dataTest'`, `'DATA-TEST'`], 67 expectedCompletionText: `-test']`, 68 }, 69 { 70 char: "-", 71 expectedItems: [`'data-test'`, `'DATA-TEST'`], 72 expectedCompletionText: `test']`, 73 }, 74 { 75 char: "t", 76 expectedItems: [`'data-test'`, `'DATA-TEST'`], 77 expectedCompletionText: `est']`, 78 }, 79 { 80 char: "e", 81 expectedItems: [`'data-test'`, `'DATA-TEST'`], 82 expectedCompletionText: `st']`, 83 }, 84 ], 85 }, 86 ]; 87 88 for (const test of tests) { 89 info(test.description); 90 91 let onPopupUpdate = jsterm.once("autocomplete-updated"); 92 EventUtils.sendString(test.initialInput); 93 await onPopupUpdate; 94 95 ok( 96 hasExactPopupLabels(autocompletePopup, test.expectedItems), 97 `popup has expected items, in expected order` 98 ); 99 100 checkInputCompletionValue( 101 hud, 102 test.expectedCompletionText, 103 `completeNode has expected value` 104 ); 105 for (const { 106 char, 107 expectedItems, 108 expectedCompletionText, 109 } of test.sequence) { 110 onPopupUpdate = jsterm.once("autocomplete-updated"); 111 EventUtils.sendString(char); 112 await onPopupUpdate; 113 114 ok( 115 hasExactPopupLabels(autocompletePopup, expectedItems), 116 `popup has expected items, in expected order` 117 ); 118 checkInputCompletionValue( 119 hud, 120 expectedCompletionText, 121 `completeNode has expected value` 122 ); 123 } 124 125 const onPopupClose = autocompletePopup.once("popup-closed"); 126 EventUtils.synthesizeKey("KEY_Escape"); 127 await onPopupClose; 128 setInputValue(hud, ""); 129 } 130 });