Bug 1575972 - Support favicon for defaultIcon on contextual tip r=adw
authorOmkar Konaraddi <okonaraddi@mozilla.com>
Fri, 23 Aug 2019 04:22:33 +0000
changeset 553359 a37d72905bf66ebacc4ef0bb0d2a46f86b7804f5
parent 553358 b79001cbab82ab3ea3666299e2fb88843487d2f5
child 553360 5cf62d6874c13813c83f0f459bce3349aaa9b871
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1575972
milestone70.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 1575972 - Support favicon for defaultIcon on contextual tip r=adw Differential Revision: https://phabricator.services.mozilla.com/D43153
browser/components/extensions/schemas/urlbar.json
browser/components/extensions/test/browser/browser_ext_urlbar_contextual_tip.js
--- a/browser/components/extensions/schemas/urlbar.json
+++ b/browser/components/extensions/schemas/urlbar.json
@@ -179,17 +179,25 @@
         "description": "An object containing the path to an icon, the title, button title, and link title to set on the contextual tip.",
         "properties": {
           "icon": {
             "type": "object",
             "optional": true,
             "description": "Specifies the default icon and theme icons",
             "properties": {
               "defaultIcon": {
-                "$ref": "manifest.IconPath",
+                "choices": [
+                  {
+                    "type": "string",
+                    "description": "A URL to an image (e.g. favicon's URL)"
+                  },
+                  {
+                    "$ref": "manifest.IconPath"
+                  }
+                ],
                 "description": "Specifies the default icon to use in the contextual tip."
               },
               "themeIcons": {
                 "type": "array",
                 "optional": true,
                 "minItems": 1,
                 "items": { "$ref": "manifest.ThemeIcons" },
                 "description": "Specifies icons to use for dark and light themes. Each item in the array is for a specified icon size."
--- a/browser/components/extensions/test/browser/browser_ext_urlbar_contextual_tip.js
+++ b/browser/components/extensions/test/browser/browser_ext_urlbar_contextual_tip.js
@@ -478,29 +478,67 @@ add_task(async () => {
   await add_onclick_to_element("link", true);
 });
 
 /**
  * The tests for below are for the contextual_tip's icon support.
  */
 
 /**
- * Tests that the contextual tip's default theme icon can be set.
+ * Tests that the contextual tip's default theme icon can be set
+ * to a favicon's url.
+ */
+add_task(async function test_set_icon_given_favicon() {
+  let win = await BrowserTestUtils.openNewBrowserWindow();
+
+  let ext = ExtensionTestUtils.loadExtension({
+    isPrivileged: true,
+    manifest: {
+      permissions: ["urlbar"],
+    },
+    background() {
+      browser.urlbar.contextualTip.set({
+        icon: { defaultIcon: "data:image/png;base64,SFRUUCBpY29uIGRhdGE=" },
+        title: "the title is required",
+      });
+      browser.test.sendMessage(
+        "ready",
+        browser.runtime.getURL("data:image/png;base64,SFRUUCBpY29uIGRhdGE=")
+      );
+    },
+  });
+
+  await ext.startup();
+  await BrowserTestUtils.waitForCondition(() =>
+    UrlbarTestUtils.isPopupOpen(win)
+  );
+  const iconURL = await ext.awaitMessage("ready");
+  const backgroundImageProperty = `url("${iconURL}")`;
+  const iconElement = win.gURLBar.view.contextualTip._elements.icon;
+  Assert.equal(
+    backgroundImageProperty,
+    win.getComputedStyle(iconElement).backgroundImage
+  );
+
+  await ext.unload();
+  await BrowserTestUtils.closeWindow(win);
+});
+
+/**
+ * Tests that the contextual tip's default theme icon can be set
+ * to the relative path of an icon.
  */
 add_task(async function test_set_icon_given_path() {
   let win = await BrowserTestUtils.openNewBrowserWindow();
 
   let ext = ExtensionTestUtils.loadExtension({
     isPrivileged: true,
     manifest: {
       permissions: ["urlbar"],
     },
-    files: {
-      "icons/icon.png": imageBuffer,
-    },
     background() {
       browser.urlbar.contextualTip.set({
         icon: { defaultIcon: "icons/icon.png" },
         title: "the title is required",
       });
       browser.test.sendMessage(
         "ready",
         browser.runtime.getURL("icons/icon.png")
@@ -536,19 +574,16 @@ add_task(async function test_set_icon_gi
   let ext = ExtensionTestUtils.loadExtension({
     isPrivileged: true,
     manifest: {
       permissions: ["urlbar"],
       icons: {
         "19": "extension_icon.png",
       },
     },
-    files: {
-      "extension_icon.png": imageBuffer,
-    },
     background() {
       browser.urlbar.contextualTip.set({
         title: "the title is required",
       });
       browser.test.sendMessage(
         "ready",
         browser.runtime.getURL("extension_icon.png")
       );
@@ -579,21 +614,16 @@ add_task(async function test_set_icon_gi
 add_task(async function test_themeIcons() {
   let win = await BrowserTestUtils.openNewBrowserWindow();
 
   let ext = ExtensionTestUtils.loadExtension({
     isPrivileged: true,
     manifest: {
       permissions: ["urlbar"],
     },
-    files: {
-      "icons/default.png": imageBuffer,
-      "icons/light.png": imageBuffer,
-      "icons/dark.png": imageBuffer,
-    },
     background() {
       browser.urlbar.contextualTip.set({
         icon: {
           defaultIcon: "icons/default.png",
           themeIcons: [
             {
               light: "icons/light.png",
               dark: "icons/dark.png",
@@ -686,23 +716,16 @@ const RESOLUTION_PREF = "layout.css.devP
 add_task(async function test_themeIcons_size_16() {
   let win = await BrowserTestUtils.openNewBrowserWindow();
 
   let ext = ExtensionTestUtils.loadExtension({
     isPrivileged: true,
     manifest: {
       permissions: ["urlbar"],
     },
-    files: {
-      "icons/default.png": imageBuffer,
-      "icons/light-16.png": imageBuffer,
-      "icons/dark-16.png": imageBuffer,
-      "icons/light-32.png": imageBuffer,
-      "icons/dark-32.png": imageBuffer,
-    },
     background() {
       browser.urlbar.contextualTip.set({
         icon: {
           defaultIcon: "icons/default.png",
           themeIcons: [
             {
               light: "icons/light-16.png",
               dark: "icons/dark-16.png",
@@ -803,23 +826,16 @@ add_task(async function test_themeIcons_
 add_task(async function test_themeIcons_size_32() {
   let win = await BrowserTestUtils.openNewBrowserWindow();
 
   let ext = ExtensionTestUtils.loadExtension({
     isPrivileged: true,
     manifest: {
       permissions: ["urlbar"],
     },
-    files: {
-      "icons/default.png": imageBuffer,
-      "icons/light-16.png": imageBuffer,
-      "icons/dark-16.png": imageBuffer,
-      "icons/light-32.png": imageBuffer,
-      "icons/dark-32.png": imageBuffer,
-    },
     background() {
       browser.urlbar.contextualTip.set({
         icon: {
           defaultIcon: "icons/default.png",
           themeIcons: [
             {
               light: "icons/light-16.png",
               dark: "icons/dark-16.png",