Bug 1595985 - Add browser.urlbar.closeView webextension API. r=mak,mixedpuppy
authorDrew Willcoxon <adw@mozilla.com>
Wed, 13 Nov 2019 17:59:08 +0000
changeset 501819 73c69599b3f12fa0f2dc45ee29fb202c93a9a695
parent 501818 a65a260a14fe1950e0b061b12c62e55cea49df4a
child 501820 3d5e40454c304b5614cb5725c3f5d8cab82c7be3
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, mixedpuppy
bugs1595985
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595985 - Add browser.urlbar.closeView webextension API. r=mak,mixedpuppy This is based on D52612 Differential Revision: https://phabricator.services.mozilla.com/D52792
browser/components/extensions/parent/ext-urlbar.js
browser/components/extensions/schemas/urlbar.json
browser/components/extensions/test/browser/browser_ext_urlbar.js
--- a/browser/components/extensions/parent/ext-urlbar.js
+++ b/browser/components/extensions/parent/ext-urlbar.js
@@ -130,16 +130,21 @@ this.urlbar = class extends ExtensionAPI
         UrlbarContextualTip.removeClickListener(type, listener);
       };
     };
   }
 
   getAPI(context) {
     return {
       urlbar: {
+        closeView() {
+          let window = windowTracker.getTopNormalWindow(context);
+          window.gURLBar.view.close();
+        },
+
         focus(select = false) {
           let window = windowTracker.getTopNormalWindow(context);
           if (select) {
             window.focusAndSelectUrlBar();
           } else {
             window.gURLBar.focus();
           }
         },
--- a/browser/components/extensions/schemas/urlbar.json
+++ b/browser/components/extensions/schemas/urlbar.json
@@ -110,16 +110,23 @@
       },
       "engagementTelemetry": {
         "$ref": "types.Setting",
         "description": "Enables or disables the engagement telemetry."
       }
     },
     "functions": [
       {
+        "name": "closeView",
+        "type": "function",
+        "async": true,
+        "description": "Closes the urlbar view in the current window.",
+        "parameters": []
+      },
+      {
         "name": "focus",
         "type": "function",
         "async": true,
         "description": "Focuses the urlbar in the current window.",
         "parameters": [
           {
             "name": "select",
             "type": "boolean",
--- a/browser/components/extensions/test/browser/browser_ext_urlbar.js
+++ b/browser/components/extensions/test/browser/browser_ext_urlbar.js
@@ -419,8 +419,29 @@ add_task(async function focusSelectTrue(
   await TestUtils.waitForCondition(() => gURLBar.focused);
   Assert.ok(gURLBar.focused);
   Assert.ok(gURLBar.hasAttribute("focused"));
   Assert.equal(gURLBar.selectionStart, 0);
   Assert.equal(gURLBar.selectionEnd, "test".length);
 
   await ext.unload();
 });
+
+// Tests the closeView function.
+add_task(async function closeView() {
+  await UrlbarTestUtils.promiseAutocompleteResultPopup({
+    window,
+    waitForFocus,
+    value: "test",
+  });
+
+  let ext = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["urlbar"],
+    },
+    isPrivileged: true,
+    background: () => {
+      browser.urlbar.closeView();
+    },
+  });
+  await UrlbarTestUtils.promisePopupClose(window, () => ext.startup());
+  await ext.unload();
+});