Bug 1451079 - Fix runtime.setUninstallURL to honor empty string, r=zombie
authorsagarwala <shailja.agarwala21@gmail.com>
Mon, 11 Mar 2019 17:46:44 +0000
changeset 524407 7d64886307e5b72f2425ec990590653b5f71dc5c
parent 524406 16b947cb279ad6a8b3232d6ca78405211e66828e
child 524408 3338bffc95e30eb488aa3da2789bd50ee80a0260
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1451079
milestone67.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 1451079 - Fix runtime.setUninstallURL to honor empty string, r=zombie Differential Revision: https://phabricator.services.mozilla.com/D18499
browser/components/extensions/test/browser/browser_ext_runtime_setUninstallURL.js
toolkit/components/extensions/parent/ext-runtime.js
toolkit/components/extensions/schemas/runtime.json
--- a/browser/components/extensions/test/browser/browser_ext_runtime_setUninstallURL.js
+++ b/browser/components/extensions/test/browser/browser_ext_runtime_setUninstallURL.js
@@ -67,16 +67,37 @@ add_task(async function test_setuninstal
 
   addon.uninstall(true);
   info("uninstalled");
 
   // no need to explicitly check for the absence of a new tab,
   // BrowserTestUtils will eventually complain if one is opened.
 });
 
+// Test the documented behavior of setUninstallURL() that passing an
+// empty string is equivalent to not setting an uninstall URL
+// (i.e., no new tab is opened upon uninstall)
+// here we pass a null value to string and test
+add_task(async function test_setuninstall_null_url() {
+  async function backgroundScript() {
+    await browser.runtime.setUninstallURL(null);
+    browser.tabs.create({url: "http://example.com/addon_loaded"});
+  }
+
+  let addon = await makeAndInstallXPI("test_uinstallurl2@tests.mozilla.org",
+                                      backgroundScript,
+                                      "http://example.com/addon_loaded");
+
+  addon.uninstall(true);
+  info("uninstalled");
+
+  // no need to explicitly check for the absence of a new tab,
+  // BrowserTestUtils will eventually complain if one is opened.
+});
+
 add_task(async function test_setuninstallurl() {
   async function backgroundScript() {
     await browser.runtime.setUninstallURL("http://example.com/addon_uninstalled");
     browser.tabs.create({url: "http://example.com/addon_loaded"});
   }
 
   let addon = await makeAndInstallXPI("test_uinstallurl@tests.mozilla.org",
                                       backgroundScript,
--- a/toolkit/components/extensions/parent/ext-runtime.js
+++ b/toolkit/components/extensions/parent/ext-runtime.js
@@ -129,17 +129,18 @@ this.runtime = class extends ExtensionAP
 
           // This expects openOptionsPage to be defined in the file using this,
           // e.g. the browser/ version of ext-runtime.js
           /* global openOptionsPage:false */
           return openOptionsPage(extension).then(() => {});
         },
 
         setUninstallURL: function(url) {
-          if (url.length == 0) {
+          if (url === null || url.length === 0) {
+            extension.uninstallURL = null;
             return Promise.resolve();
           }
 
           let uri;
           try {
             uri = new URL(url);
           } catch (e) {
             return Promise.reject({message: `Invalid URL: ${JSON.stringify(url)}`});
--- a/toolkit/components/extensions/schemas/runtime.json
+++ b/toolkit/components/extensions/schemas/runtime.json
@@ -226,16 +226,17 @@
         "name": "setUninstallURL",
         "type": "function",
         "description": "Sets the URL to be visited upon uninstallation. This may be used to clean up server-side data, do analytics, and implement surveys. Maximum 255 characters.",
         "async": "callback",
         "parameters": [
           {
             "type": "string",
             "name": "url",
+            "optional": true,
             "maxLength": 255,
             "description": "URL to be opened after the extension is uninstalled. This URL must have an http: or https: scheme. Set an empty string to not open a new tab upon uninstallation."
           },
           {
             "type": "function",
             "name": "callback",
             "optional": true,
             "description": "Called when the uninstall URL is set. If the given URL is invalid, $(ref:runtime.lastError) will be set.",