forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge autoland to mozilla-central. a=merge
- Loading branch information
Showing
71 changed files
with
643 additions
and
6,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
browser/components/search/test/browser/browser_trending_suggestions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
ChromeUtils.defineESModuleGetters(this, { | ||
SearchTestUtils: "resource://testing-common/SearchTestUtils.sys.mjs", | ||
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs", | ||
}); | ||
|
||
const CONFIG_DEFAULT = [ | ||
{ | ||
webExtension: { id: "basic@search.mozilla.org" }, | ||
urls: { | ||
trending: { | ||
fullPath: | ||
"http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/searchSuggestionEngine.sjs", | ||
query: "", | ||
}, | ||
}, | ||
appliesTo: [{ included: { everywhere: true } }], | ||
default: "yes", | ||
}, | ||
{ | ||
webExtension: { id: "private@search.mozilla.org" }, | ||
appliesTo: [{ included: { everywhere: true } }], | ||
default: "yes", | ||
}, | ||
]; | ||
|
||
SearchTestUtils.init(this); | ||
UrlbarTestUtils.init(this); | ||
|
||
add_setup(async () => { | ||
// Use engines in test directory | ||
let searchExtensions = getChromeDir(getResolvedURI(gTestPath)); | ||
searchExtensions.append("search-engines"); | ||
await SearchTestUtils.useMochitestEngines(searchExtensions); | ||
|
||
await SpecialPowers.pushPrefEnv({ | ||
set: [["browser.urlbar.suggest.searches", true]], | ||
}); | ||
|
||
SearchTestUtils.useMockIdleService(); | ||
await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_DEFAULT); | ||
|
||
registerCleanupFunction(async () => { | ||
let settingsWritten = SearchTestUtils.promiseSearchNotification( | ||
"write-settings-to-disk-complete" | ||
); | ||
await SearchTestUtils.updateRemoteSettingsConfig(); | ||
await settingsWritten; | ||
}); | ||
}); | ||
|
||
add_task(async function test_trending_results() { | ||
await check_results({ | ||
featureEnabled: true, | ||
searchMode: "@basic ", | ||
expectedResults: 2, | ||
}); | ||
await check_results({ | ||
featureEnabled: true, | ||
requireSearchModeEnabled: false, | ||
expectedResults: 2, | ||
}); | ||
await check_results({ | ||
featureEnabled: true, | ||
requireSearchModeEnabled: false, | ||
searchMode: "@basic ", | ||
expectedResults: 2, | ||
}); | ||
await check_results({ | ||
featureEnabled: false, | ||
searchMode: "@basic ", | ||
expectedResults: 0, | ||
}); | ||
await check_results({ | ||
featureEnabled: false, | ||
expectedResults: 0, | ||
}); | ||
await check_results({ | ||
featureEnabled: false, | ||
requireSearchModeEnabled: false, | ||
expectedResults: 0, | ||
}); | ||
await check_results({ | ||
featureEnabled: false, | ||
requireSearchModeEnabled: false, | ||
searchMode: "@basic ", | ||
expectedResults: 0, | ||
}); | ||
|
||
// The private engine is not configured with any trending url. | ||
await check_results({ | ||
featureEnabled: true, | ||
searchMode: "@private ", | ||
expectedResults: 0, | ||
}); | ||
}); | ||
|
||
async function check_results({ | ||
featureEnabled = false, | ||
requireSearchModeEnabled = true, | ||
searchMode = "", | ||
expectedResults = 0, | ||
}) { | ||
await SpecialPowers.pushPrefEnv({ | ||
set: [ | ||
["browser.urlbar.trending.featureGate", featureEnabled], | ||
["browser.urlbar.trending.requireSearchMode", requireSearchModeEnabled], | ||
], | ||
}); | ||
|
||
// If we are not in a search mode and there are no results. The urlbar | ||
// will not open. | ||
if (!searchMode && !expectedResults) { | ||
window.gURLBar.inputField.focus(); | ||
Assert.ok(!UrlbarTestUtils.isPopupOpen(window)); | ||
return; | ||
} | ||
|
||
await UrlbarTestUtils.promiseAutocompleteResultPopup({ | ||
window, | ||
value: searchMode, | ||
waitForFocus: SimpleTest.waitForFocus, | ||
}); | ||
|
||
Assert.equal( | ||
UrlbarTestUtils.getResultCount(window), | ||
expectedResults, | ||
"We matched the expected number of results" | ||
); | ||
|
||
if (expectedResults) { | ||
for (let i = 0; i < expectedResults; i++) { | ||
let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, i); | ||
Assert.equal(result.type, UrlbarUtils.RESULT_TYPE.SEARCH); | ||
Assert.equal(result.providerName, "SearchSuggestions"); | ||
Assert.equal(result.payload.engine, "basic"); | ||
} | ||
} | ||
|
||
if (searchMode) { | ||
await UrlbarTestUtils.exitSearchMode(window); | ||
} | ||
await UrlbarTestUtils.promisePopupClose(window, () => { | ||
EventUtils.synthesizeKey("KEY_Escape"); | ||
}); | ||
await SpecialPowers.popPrefEnv(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.