browser_inputHistory_emptystring.js (3013B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * This tests input history in cases where the search string is empty. 6 * In the future we may want to not account for these, but for now they are 7 * stored with an empty input field. 8 */ 9 10 "use strict"; 11 12 async function checkInputHistory(len = 0) { 13 await PlacesUtils.withConnectionWrapper( 14 "test::checkInputHistory", 15 async db => { 16 let rows = await db.executeCached(`SELECT input FROM moz_inputhistory`); 17 Assert.equal(rows.length, len, "There should only be 1 entry"); 18 if (len) { 19 Assert.equal(rows[0].getResultByIndex(0), "", "Input should be empty"); 20 } 21 } 22 ); 23 } 24 25 const TEST_URL = "http://example.com/"; 26 27 async function do_test(openFn, pickMethod) { 28 await BrowserTestUtils.withNewTab( 29 { 30 gBrowser, 31 url: "about:blank", 32 }, 33 async function (browser) { 34 await PlacesTestUtils.clearInputHistory(); 35 await openFn(); 36 await UrlbarTestUtils.promiseSearchComplete(window); 37 let promise = BrowserTestUtils.waitForDocLoadAndStopIt(TEST_URL, browser); 38 if (pickMethod == "keyboard") { 39 info(`Test pressing Enter`); 40 EventUtils.sendKey("down"); 41 EventUtils.sendKey("return"); 42 } else { 43 info("Test with click"); 44 let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 0); 45 EventUtils.synthesizeMouseAtCenter(result.element.row, {}); 46 } 47 await promise; 48 await checkInputHistory(1); 49 } 50 ); 51 } 52 53 add_setup(async function () { 54 await PlacesUtils.history.clear(); 55 for (let i = 0; i < 5; i++) { 56 await PlacesTestUtils.addVisits(TEST_URL); 57 } 58 59 await updateTopSites(sites => sites && sites[0] && sites[0].url == TEST_URL); 60 registerCleanupFunction(async () => { 61 await PlacesUtils.history.clear(); 62 }); 63 }); 64 65 add_task(async function test_history_no_search_terms() { 66 for (let pickMethod of ["keyboard", "mouse"]) { 67 // If a testFn returns false, it will be skipped. 68 for (let openFn of [ 69 () => { 70 info("Test opening panel with down key"); 71 gURLBar.focus(); 72 EventUtils.sendKey("down"); 73 }, 74 async () => { 75 info("Test opening panel on focus"); 76 gURLBar.blur(); 77 EventUtils.synthesizeMouseAtCenter(gURLBar, {}); 78 }, 79 async () => { 80 info("Test opening panel on focus on a page"); 81 let selectedBrowser = gBrowser.selectedBrowser; 82 // A page other than TEST_URL must be loaded, or the first Top Site 83 // result will be a switch-to-tab result and page won't be reloaded when 84 // the result is selected. 85 BrowserTestUtils.startLoadingURIString( 86 selectedBrowser, 87 "http://example.org/" 88 ); 89 await BrowserTestUtils.browserLoaded(selectedBrowser); 90 gURLBar.blur(); 91 EventUtils.synthesizeMouseAtCenter(gURLBar, {}); 92 }, 93 ]) { 94 await do_test(openFn, pickMethod); 95 } 96 } 97 });