Bug 1233982 - Do not fetch autofill icons from the network. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 07 Jan 2016 17:25:09 +0100
changeset 280141 c8a36bbbde08b22dd8c5ca02d996a03e51200c1e
parent 280140 6cb4eea487ad8eb1e1c620dd8650762da012b1f0
child 280142 3424598d23bd0d036282693a3e7af9bec70b127c
push id17041
push usermak77@bonardo.net
push dateFri, 15 Jan 2016 13:33:36 +0000
treeherderfx-team@c8a36bbbde08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1233982
milestone46.0a1
Bug 1233982 - Do not fetch autofill icons from the network. r=adw
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
toolkit/components/places/tests/unifiedcomplete/test_typed.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -1242,16 +1242,19 @@ Search.prototype = {
       // is a string URL)
       if (!icon) {
         try {
           let favicon = yield PlacesUtils.promiseFaviconLinkUrl(url);
           if (favicon) {
             icon = favicon.spec;
           }
         } catch (ex) {} // no favicon for this URL.
+      } else {
+        icon = PlacesUtils.favicons
+                          .getFaviconLinkForIcon(NetUtil.newURI(icon)).spec;
       }
 
       let match = {
         // We include the deviceName in the action URL so we can render it in
         // the URLBar.
         value: makeActionURL("remotetab", { url, deviceName }),
         comment: title || url,
         style: "action",
@@ -1463,17 +1466,20 @@ Search.prototype = {
         !untrimmedHost.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       untrimmedHost = null;
     }
 
     match.value = this._strippedPrefix + trimmedHost;
     // Remove the trailing slash.
     match.comment = stripHttpAndTrim(trimmedHost);
     match.finalCompleteValue = untrimmedHost;
-    match.icon = faviconUrl;
+    if (faviconUrl) {
+      match.icon = PlacesUtils.favicons
+                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
+    }
     // Although this has a frecency, this query is executed before any other
     // queries that would result in frecency matches.
     match.frecency = frecency;
     match.style = "autofill";
     return match;
   },
 
   _processUrlRow: function (row) {
@@ -1502,17 +1508,20 @@ Search.prototype = {
     if (untrimmedURL &&
         !untrimmedURL.toLowerCase().includes(this._trimmedOriginalSearchString.toLowerCase())) {
       untrimmedURL = null;
      }
 
     match.value = this._strippedPrefix + url;
     match.comment = url;
     match.finalCompleteValue = untrimmedURL;
-    match.icon = faviconUrl;
+    if (faviconUrl) {
+      match.icon = PlacesUtils.favicons
+                              .getFaviconLinkForIcon(NetUtil.newURI(faviconUrl)).spec;
+    }
     // Although this has a frecency, this query is executed before any other
     // queries that would result in frecency matches.
     match.frecency = frecency;
     match.style = "autofill";
     return match;
   },
 
   _processRow: function (row) {
--- a/toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
@@ -110,17 +110,17 @@ add_task(function* test_maximal() {
   });
 
   yield check_autocomplete({
     search: "ex",
     searchParam: "enable-actions",
     matches: [ makeSearchMatch("ex", { heuristic: true }),
                makeRemoteTabMatch("http://example.com/", "My Phone",
                                   { title: "An Example",
-                                    icon: "http://favicon"
+                                    icon: "moz-anno:favicon:http://favicon"
                                   }),
              ],
   });
 });
 
 add_task(function* test_matches_title() {
   // URL doesn't match search expression, should still match the title.
   configureEngine({
--- a/toolkit/components/places/tests/unifiedcomplete/test_typed.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_typed.js
@@ -1,35 +1,41 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // First do searches with typed behavior forced to false, so later tests will
 // ensure autocomplete is able to dinamically switch behavior.
 
+const FAVICON_HREF = NetUtil.newURI(do_get_file("../favicons/favicon-normal16.png")).spec;
+
 add_task(function* test_domain() {
   do_print("Searching for domain should autoFill it");
   Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
   yield PlacesTestUtils.addVisits(NetUtil.newURI("http://mozilla.org/link/"));
+  yield setFaviconForHref("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "moz",
     autofilled: "mozilla.org/",
-    completed:  "mozilla.org/"
+    completed: "mozilla.org/",
+    icon: "moz-anno:favicon:" + FAVICON_HREF
   });
   yield cleanup();
 });
 
 add_task(function* test_url() {
   do_print("Searching for url should autoFill it");
   Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
   yield PlacesTestUtils.addVisits(NetUtil.newURI("http://mozilla.org/link/"));
+  yield setFaviconForHref("http://mozilla.org/link/", FAVICON_HREF);
   yield check_autocomplete({
     search: "mozilla.org/li",
     autofilled: "mozilla.org/link/",
-    completed: "http://mozilla.org/link/"
+    completed: "http://mozilla.org/link/",
+    icon: "moz-anno:favicon:" + FAVICON_HREF
   });
   yield cleanup();
 });
 
 // Now do searches with typed behavior forced to true.
 
 add_task(function* test_untyped_domain() {
   do_print("Searching for non-typed domain should not autoFill it");