Bug 1270707 - make LaterRun.jsm use nsIURLFormatter to format its URLs, r=jaws

MozReview-Commit-ID: 7OL1M8bfBRh

--HG--
extra : rebase_source : 9999f65355373b5141483f5672fa818c181f3034
This commit is contained in:
Gijs Kruitbosch 2016-05-06 09:40:10 +01:00
Родитель 2aa43a166a
Коммит 255a265c85
2 изменённых файлов: 12 добавлений и 3 удалений

Просмотреть файл

@ -133,9 +133,11 @@ let LaterRun = {
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.");

Просмотреть файл

@ -9,9 +9,11 @@ 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);
@ -25,7 +27,12 @@ add_task(function* test_page_applies() {
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.");