Bug 1270707 - make LaterRun.jsm use nsIURLFormatter to format its URLs, r=jaws a=ritu CLOSED TREE
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 06 May 2016 09:40:10 +0100
changeset 332818 1dd42a351054c5b697873d647169019d4d77d762
parent 332817 1bb8e2207e8eeced7cdae427f7766831c3141795
child 332819 9a64ae897313031dbca1cf58d4ff6aff64eb3009
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, ritu
bugs1270707
milestone48.0a2
Bug 1270707 - make LaterRun.jsm use nsIURLFormatter to format its URLs, r=jaws a=ritu CLOSED TREE MozReview-Commit-ID: 7OL1M8bfBRh
browser/modules/LaterRun.jsm
browser/modules/test/xpcshell/test_LaterRun.js
--- a/browser/modules/LaterRun.jsm
+++ b/browser/modules/LaterRun.jsm
@@ -128,19 +128,21 @@ let LaterRun = {
       }
       pageDataStore.get(slug)[prop] = Preferences.get(pref, defaultPrefValue);
     }
     let rv = [];
     for (let [, pageData] of pageDataStore) {
       if (pageData.url) {
         let uri = null;
         try {
-          uri = Services.io.newURI(pageData.url.trim(), null, null);
+          let urlString = Services.urlFormatter.formatURL(pageData.url.trim());
+          uri = Services.io.newURI(urlString, null, null);
         } catch (ex) {
           Cu.reportError("Invalid LaterRun page URL " + pageData.url + " ignored.");
+          continue;
         }
         if (!uri.schemeIs("https")) {
           Cu.reportError("Insecure LaterRun page URL " + uri.spec + " ignored.");
         } else {
           pageData.url = uri.spec;
           rv.push(new Page(pageData));
         }
       }
--- a/browser/modules/test/xpcshell/test_LaterRun.js
+++ b/browser/modules/test/xpcshell/test_LaterRun.js
@@ -4,33 +4,40 @@ const kEnabledPref = "browser.laterrun.e
 const kPagePrefRoot = "browser.laterrun.pages.";
 const kSessionCountPref = "browser.laterrun.bookkeeping.sessionCount";
 const kProfileCreationTime = "browser.laterrun.bookkeeping.profileCreationTime";
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource:///modules/LaterRun.jsm");
 
 Services.prefs.setBoolPref(kEnabledPref, true);
+Components.utils.import("resource://testing-common/AppInfo.jsm");
+updateAppInfo();
 
 add_task(function* test_page_applies() {
-  Services.prefs.setCharPref(kPagePrefRoot + "test_LaterRun_unittest.url", "https://www.mozilla.org/");
+  Services.prefs.setCharPref(kPagePrefRoot + "test_LaterRun_unittest.url", "https://www.mozilla.org/%VENDOR%/%NAME%/%ID%/%VERSION%/");
   Services.prefs.setIntPref(kPagePrefRoot + "test_LaterRun_unittest.minimumHoursSinceInstall", 10);
   Services.prefs.setIntPref(kPagePrefRoot + "test_LaterRun_unittest.minimumSessionCount", 3);
 
   let pages = LaterRun.readPages();
   // We have to filter the pages because it's possible Firefox ships with other URLs
   // that get included in this test.
   pages = pages.filter(page => page.pref == kPagePrefRoot + "test_LaterRun_unittest.");
   Assert.equal(pages.length, 1, "Got 1 page");
   let page = pages[0];
   Assert.equal(page.pref, kPagePrefRoot + "test_LaterRun_unittest.", "Should know its own pref");
   Assert.equal(page.minimumHoursSinceInstall, 10, "Needs to have 10 hours since install");
   Assert.equal(page.minimumSessionCount, 3, "Needs to have 3 sessions");
   Assert.equal(page.requireBoth, false, "Either requirement is enough");
-  Assert.equal(page.url, "https://www.mozilla.org/", "URL is stored correctly");
+  let expectedURL = "https://www.mozilla.org/" +
+    Services.appinfo.vendor + "/" +
+    Services.appinfo.name + "/" +
+    Services.appinfo.ID + "/" +
+    Services.appinfo.version + "/";
+  Assert.equal(page.url, expectedURL, "URL is stored correctly");
 
   Assert.ok(page.applies({hoursSinceInstall: 1, sessionCount: 3}),
             "Applies when session count has been met.");
   Assert.ok(page.applies({hoursSinceInstall: 1, sessionCount: 4}),
             "Applies when session count has been exceeded.");
   Assert.ok(page.applies({hoursSinceInstall: 10, sessionCount: 2}),
             "Applies when total session time has been met.");
   Assert.ok(page.applies({hoursSinceInstall: 20, sessionCount: 2}),