зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1590461 - Add browser.urlbar.search() to the webextensions API r=mak,mixedpuppy
Differential Revision: https://phabricator.services.mozilla.com/D52127 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
84b6b1c6a8
Коммит
b257252e66
|
@ -135,6 +135,11 @@ this.urlbar = class extends ExtensionAPI {
|
|||
getAPI(context) {
|
||||
return {
|
||||
urlbar: {
|
||||
search(searchString) {
|
||||
let window = windowTracker.getTopNormalWindow(context);
|
||||
window.gURLBar.search(searchString);
|
||||
},
|
||||
|
||||
onBehaviorRequested: new EventManager({
|
||||
context,
|
||||
name: "urlbar.onBehaviorRequested",
|
||||
|
|
|
@ -100,6 +100,21 @@
|
|||
"description": "Enables or disables the engagement telemetry."
|
||||
}
|
||||
},
|
||||
"functions": [
|
||||
{
|
||||
"name": "search",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"description": "Starts a search in the urlbar in the current window.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "searchString",
|
||||
"type": "string",
|
||||
"description": "The search string."
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"name": "onBehaviorRequested",
|
||||
|
|
|
@ -6,7 +6,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
|
||||
});
|
||||
|
||||
async function loadExtension(options = {}) {
|
||||
async function loadTipExtension(options = {}) {
|
||||
let ext = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["urlbar"],
|
||||
|
@ -73,10 +73,10 @@ add_task(async function setUp() {
|
|||
});
|
||||
});
|
||||
|
||||
// Loads an extension without a main button URL and presses enter on the main
|
||||
// Loads a tip extension without a main button URL and presses enter on the main
|
||||
// button.
|
||||
add_task(async function testOnResultPicked_mainButton_noURL_enter() {
|
||||
let ext = await loadExtension();
|
||||
add_task(async function tip_onResultPicked_mainButton_noURL_enter() {
|
||||
let ext = await loadTipExtension();
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
waitForFocus,
|
||||
|
@ -88,9 +88,9 @@ add_task(async function testOnResultPicked_mainButton_noURL_enter() {
|
|||
await ext.unload();
|
||||
});
|
||||
|
||||
// Loads an extension without a main button URL and clicks the main button.
|
||||
add_task(async function testOnResultPicked_mainButton_noURL_mouse() {
|
||||
let ext = await loadExtension();
|
||||
// Loads a tip extension without a main button URL and clicks the main button.
|
||||
add_task(async function tip_onResultPicked_mainButton_noURL_mouse() {
|
||||
let ext = await loadTipExtension();
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
waitForFocus,
|
||||
|
@ -105,10 +105,10 @@ add_task(async function testOnResultPicked_mainButton_noURL_mouse() {
|
|||
await ext.unload();
|
||||
});
|
||||
|
||||
// Loads an extension with a main button URL and presses enter on the main
|
||||
// Loads a tip extension with a main button URL and presses enter on the main
|
||||
// button.
|
||||
add_task(async function testOnResultPicked_mainButton_url_enter() {
|
||||
let ext = await loadExtension({ buttonUrl: "http://example.com/" });
|
||||
add_task(async function tip_onResultPicked_mainButton_url_enter() {
|
||||
let ext = await loadTipExtension({ buttonUrl: "http://example.com/" });
|
||||
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
|
@ -129,9 +129,9 @@ add_task(async function testOnResultPicked_mainButton_url_enter() {
|
|||
await ext.unload();
|
||||
});
|
||||
|
||||
// Loads an extension with a main button URL and clicks the main button.
|
||||
add_task(async function testOnResultPicked_mainButton_url_mouse() {
|
||||
let ext = await loadExtension({ buttonUrl: "http://example.com/" });
|
||||
// Loads a tip extension with a main button URL and clicks the main button.
|
||||
add_task(async function tip_onResultPicked_mainButton_url_mouse() {
|
||||
let ext = await loadTipExtension({ buttonUrl: "http://example.com/" });
|
||||
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
|
@ -155,10 +155,10 @@ add_task(async function testOnResultPicked_mainButton_url_mouse() {
|
|||
await ext.unload();
|
||||
});
|
||||
|
||||
// Loads an extension with a help button URL and presses enter on the help
|
||||
// Loads a tip extension with a help button URL and presses enter on the help
|
||||
// button.
|
||||
add_task(async function testOnResultPicked_helpButton_url_enter() {
|
||||
let ext = await loadExtension({ helpUrl: "http://example.com/" });
|
||||
add_task(async function tip_onResultPicked_helpButton_url_enter() {
|
||||
let ext = await loadTipExtension({ helpUrl: "http://example.com/" });
|
||||
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
|
@ -179,9 +179,9 @@ add_task(async function testOnResultPicked_helpButton_url_enter() {
|
|||
await ext.unload();
|
||||
});
|
||||
|
||||
// Loads an extension with a help button URL and clicks the help button.
|
||||
add_task(async function testOnResultPicked_helpButton_url_mouse() {
|
||||
let ext = await loadExtension({ helpUrl: "http://example.com/" });
|
||||
// Loads a tip extension with a help button URL and clicks the help button.
|
||||
add_task(async function tip_onResultPicked_helpButton_url_mouse() {
|
||||
let ext = await loadTipExtension({ helpUrl: "http://example.com/" });
|
||||
await BrowserTestUtils.withNewTab("about:blank", async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
|
@ -204,3 +204,80 @@ add_task(async function testOnResultPicked_helpButton_url_mouse() {
|
|||
});
|
||||
await ext.unload();
|
||||
});
|
||||
|
||||
// Tests the search function with a non-empty string.
|
||||
add_task(async function search() {
|
||||
gURLBar.blur();
|
||||
|
||||
let ext = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["urlbar"],
|
||||
},
|
||||
isPrivileged: true,
|
||||
background: () => {
|
||||
browser.urlbar.search("test");
|
||||
},
|
||||
});
|
||||
await ext.startup();
|
||||
|
||||
let context = await UrlbarTestUtils.promiseSearchComplete(window);
|
||||
Assert.equal(gURLBar.value, "test");
|
||||
Assert.equal(context.searchString, "test");
|
||||
Assert.ok(gURLBar.focused);
|
||||
Assert.equal(gURLBar.getAttribute("focused"), "true");
|
||||
|
||||
await UrlbarTestUtils.promisePopupClose(window);
|
||||
await ext.unload();
|
||||
});
|
||||
|
||||
// Tests the search function with an empty string.
|
||||
add_task(async function searchEmpty() {
|
||||
gURLBar.blur();
|
||||
|
||||
// Searching for an empty string shows the history view, but there may be no
|
||||
// history here since other tests may have cleared it or since this test is
|
||||
// running in isolation. We want to make sure providers are called and their
|
||||
// results are shown, so add a provider that returns a tip.
|
||||
let ext = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["urlbar"],
|
||||
},
|
||||
isPrivileged: true,
|
||||
background() {
|
||||
browser.urlbar.onBehaviorRequested.addListener(query => {
|
||||
return "restricting";
|
||||
}, "test");
|
||||
browser.urlbar.onResultsRequested.addListener(query => {
|
||||
return [
|
||||
{
|
||||
type: "tip",
|
||||
source: "local",
|
||||
heuristic: true,
|
||||
payload: {
|
||||
text: "Test",
|
||||
buttonText: "OK",
|
||||
},
|
||||
},
|
||||
];
|
||||
}, "test");
|
||||
browser.urlbar.search("");
|
||||
},
|
||||
});
|
||||
await ext.startup();
|
||||
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => UrlbarProvidersManager.getProvider("test"),
|
||||
"Waiting for provider to be registered"
|
||||
);
|
||||
|
||||
let context = await UrlbarTestUtils.promiseSearchComplete(window);
|
||||
Assert.equal(gURLBar.value, "");
|
||||
Assert.equal(context.searchString, "");
|
||||
Assert.equal(context.results.length, 1);
|
||||
Assert.equal(context.results[0].type, UrlbarUtils.RESULT_TYPE.TIP);
|
||||
Assert.ok(gURLBar.focused);
|
||||
Assert.equal(gURLBar.getAttribute("focused"), "true");
|
||||
|
||||
await UrlbarTestUtils.promisePopupClose(window);
|
||||
await ext.unload();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче