Bug 1608601 - Add browser.experiments.urlbar.clearInput() experiment API. r=harry a=RyanVM
authorDrew Willcoxon <adw@mozilla.com>
Sun, 12 Jan 2020 02:49:06 +0000
changeset 571174 52fba9ebcb6f9f1460edc899a24b4fd41517cac6
parent 571173 320b0ab4cfe30e63ee86b3a2a1ee9e2bbc83fd25
child 571175 087b0cab93cc2c55a84e3fd491160cc183e60bfd
push id12554
push usercbrindusan@mozilla.com
push dateWed, 15 Jan 2020 02:09:58 +0000
treeherdermozilla-beta@087b0cab93cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersharry, RyanVM
bugs1608601, 1608613
milestone73.0
Bug 1608601 - Add browser.experiments.urlbar.clearInput() experiment API. r=harry a=RyanVM We need to also set the pageproxystate to invalid so that we show the magnifying glass icon in the input instead of the lock and shield. This is used in the extension's background script here: https://github.com/0c0w3/urlbar-tips-experiment/pull/8/files#diff-961641dd6af66f5e3313307cf4eb8f1dR339 (Bug 1608613 tracks that PR) Differential Revision: https://phabricator.services.mozilla.com/D59591
browser/components/urlbar/tests/ext/api.js
browser/components/urlbar/tests/ext/browser/browser.ini
browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_clearInput.js
browser/components/urlbar/tests/ext/schema.json
--- a/browser/components/urlbar/tests/ext/api.js
+++ b/browser/components/urlbar/tests/ext/api.js
@@ -66,16 +66,22 @@ this.experiments_urlbar = class extends 
   getAPI() {
     return {
       experiments: {
         urlbar: {
           checkForBrowserUpdate() {
             appUpdater.check();
           },
 
+          clearInput() {
+            let window = BrowserWindowTracker.getTopWindow();
+            window.gURLBar.value = "";
+            window.SetPageProxyState("invalid");
+          },
+
           engagementTelemetry: this._getDefaultSettingsAPI(
             "browser.urlbar.eventTelemetry.enabled"
           ),
 
           getBrowserUpdateStatus() {
             return appUpdaterStatusToStringMap.get(appUpdater.status);
           },
 
--- a/browser/components/urlbar/tests/ext/browser/browser.ini
+++ b/browser/components/urlbar/tests/ext/browser/browser.ini
@@ -4,14 +4,15 @@
 
 [DEFAULT]
 support-files =
   ../../browser/head-common.js
   ../api.js
   ../schema.json
   head.js
 
+[browser_ext_urlbar_clearInput.js]
 [browser_ext_urlbar_engagementTelemetry.js]
 [browser_ext_urlbar_isBrowserShowingNotification.js]
 [browser_ext_urlbar_lastBrowserUpdateDate.js]
 [browser_ext_urlbar_openClearHistoryDialog.js]
 [browser_ext_urlbar_openViewOnFocus.js]
 [browser_ext_urlbar_resetBrowser.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_clearInput.js
@@ -0,0 +1,29 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* global browser */
+
+// This tests the browser.experiments.urlbar.clearInput WebExtension Experiment
+// API.
+
+"use strict";
+
+add_task(async function test() {
+  // Load a page so that pageproxystate is valid.  When the extension calls
+  // clearInput, the pageproxystate should become invalid.
+  await BrowserTestUtils.withNewTab("http://example.com/", async () => {
+    Assert.notEqual(gURLBar.value, "", "Input is not empty");
+    Assert.equal(gURLBar.getAttribute("pageproxystate"), "valid");
+
+    let ext = await loadExtension(async () => {
+      await browser.experiments.urlbar.clearInput();
+      browser.test.sendMessage("done");
+    });
+    await ext.awaitMessage("done");
+
+    Assert.equal(gURLBar.value, "", "Input is empty");
+    Assert.equal(gURLBar.getAttribute("pageproxystate"), "invalid");
+
+    await ext.unload();
+  });
+});
--- a/browser/components/urlbar/tests/ext/schema.json
+++ b/browser/components/urlbar/tests/ext/schema.json
@@ -24,16 +24,23 @@
       {
         "name": "checkForBrowserUpdate",
         "type": "function",
         "async": true,
         "description": "Checks for an update to the app. If an update is available and the user's preferences allow, the update will automatically be downloaded and installed. This function will not restart the browser, however.",
         "parameters": []
       },
       {
+        "name": "clearInput",
+        "type": "function",
+        "async": true,
+        "description": "Sets urlbar.value to the empty string and the pageproxystate to invalid.",
+        "parameters": []
+      },
+      {
         "name": "getBrowserUpdateStatus",
         "type": "function",
         "async": true,
         "description": "Returns the browser's current update status. The return value is one of the <code>BrowserUpdateStatus</code> enums.",
         "parameters": []
       },
       {
         "name": "installBrowserUpdateAndRestart",