Bug 1053937 - Visiting localhost prevents later tiles from being shown [r=adw a=sylvestre]
authorEd Lee <edilee@mozilla.com>
Thu, 14 Aug 2014 17:03:46 -0700
changeset 217672 cd0f797c10cae0bc6504b3df158c855c65473f0d
parent 217671 24b8334087d662ba45ddcb89706864d9ff1f9c2f
child 217673 0b918191c65ab4656397cf498adca06fecd1c717
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sylvestre
bugs1053937
milestone33.0a2
Bug 1053937 - Visiting localhost prevents later tiles from being shown [r=adw a=sylvestre] Fallback to asciiHost when IP/insufficient levels. Update tests to localhost to trigger failure codepath.
browser/base/content/test/newtab/browser_newtab_reportLinkAction.js
toolkit/modules/DirectoryLinksProvider.jsm
toolkit/modules/tests/xpcshell/test_DirectoryLinksProvider.js
--- a/browser/base/content/test/newtab/browser_newtab_reportLinkAction.js
+++ b/browser/base/content/test/newtab/browser_newtab_reportLinkAction.js
@@ -1,19 +1,19 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const PRELOAD_PREF = "browser.newtab.preload";
 
 gDirectorySource = "data:application/json," + JSON.stringify({
   "en-US": [{
-    url: "http://organic.localhost/",
+    url: "http://example.com/organic",
     type: "organic"
   }, {
-    url: "http://sponsored.localhost/",
+    url: "http://localhost/sponsored",
     type: "sponsored"
   }]
 });
 
 function runTests() {
   Services.prefs.setBoolPref(PRELOAD_PREF, false);
   yield addNewTabPageTab();
 
--- a/toolkit/modules/DirectoryLinksProvider.jsm
+++ b/toolkit/modules/DirectoryLinksProvider.jsm
@@ -151,17 +151,21 @@ let DirectoryLinksProvider = {
     }
   },
 
   /**
    * Get the eTLD+1 / base domain from a url spec
    */
   _extractSite: function DirectoryLinksProvider_extractSite(url) {
     let linkURI = Services.io.newURI(url, null, null);
-    return Services.eTLD.getBaseDomain(linkURI);
+    try {
+      return Services.eTLD.getBaseDomain(linkURI);
+    }
+    catch(ex) {}
+    return linkURI.asciiHost;
   },
 
   _fetchAndCacheLinks: function DirectoryLinksProvider_fetchAndCacheLinks(uri) {
     let deferred = Promise.defer();
     let xmlHttp = new XMLHttpRequest();
     xmlHttp.overrideMimeType("application/json");
 
     let self = this;
--- a/toolkit/modules/tests/xpcshell/test_DirectoryLinksProvider.js
+++ b/toolkit/modules/tests/xpcshell/test_DirectoryLinksProvider.js
@@ -228,17 +228,17 @@ add_task(function test_fetchAndCacheLink
   // File should be empty.
   let data = yield readJsonFile();
   isIdentical(data, "");
 });
 
 add_task(function test_fetchAndCacheLinks_unknownHost() {
   yield DirectoryLinksProvider.init();
   yield cleanJsonFile();
-  let nonExistentServer = "http://nosuchhost.localhost";
+  let nonExistentServer = "http://localhost:56789/";
   try {
     yield DirectoryLinksProvider._fetchAndCacheLinks(nonExistentServer);
     do_throw("BAD URIs should fail");
   } catch (e) {
     do_check_true(e.startsWith("Fetching " + nonExistentServer + " results in error code: "))
   }
 
   // File should be empty.
@@ -309,17 +309,17 @@ add_task(function test_DirectoryLinksPro
   let links = yield fetchData();
   do_check_eq(links.length, 1);
   let expectedData =  [{url: "http://example.com", title: "LocalSource", frecency: DIRECTORY_FRECENCY, lastVisitDate: 1, directoryIndex: 0}];
   isIdentical(links, expectedData);
 
   // tests these 2 things:
   // 1. _linksURL is properly set after the pref change
   // 2. invalid source url is correctly handled
-  let exampleUrl = 'http://nosuchhost.localhost/bad';
+  let exampleUrl = 'http://localhost:56789/bad';
   yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, exampleUrl);
   do_check_eq(DirectoryLinksProvider._linksURL, exampleUrl);
 
   // since the download fail, the directory file must remain the same
   let newLinks = yield fetchData();
   isIdentical(newLinks, expectedData);
 
   // now remove the file, and re-download
@@ -498,16 +498,18 @@ add_task(function test_DirectoryLinksPro
     url: "http://example.com/echo",
     enhancedImageURI: "echo",
   });
   do_check_eq(inline.enhancedImageURI, "echo");
   do_check_eq(inline.url, "http://example.com/echo");
 
   // Undefined for not enhanced
   checkEnhanced("http://example.org", undefined);
+  checkEnhanced("http://localhost", undefined);
+  checkEnhanced("http://127.0.0.1", undefined);
 
   // Make sure old data is not cached
   data = {"en-US": [
     {url: "http://example.com", enhancedImageURI: "fresh"},
   ]};
   dataURI = 'data:application/json,' + JSON.stringify(data);
   yield promiseSetupDirectoryLinksProvider({linksURL: dataURI});
   links = yield fetchData();