Bug 1449255: Part 17 - Rename test_bug620837 to test_blocklist_url_ping_count.js and modernize. r?aswan
MozReview-Commit-ID: K9m1vDfLP5X
rename from toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js
rename to toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_ping_count.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_ping_count.js
@@ -5,141 +5,110 @@
ChromeUtils.import("resource://testing-common/httpd.js");
const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer";
const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
const SECONDS_IN_DAY = 60 * 60 * 24;
-var gExpectedQueryString = null;
-var gNextTest = null;
-var gTestserver = null;
+var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+
+let resolveQuery;
+gTestserver.registerPathHandler("/", function pathHandler(metadata, response) {
+ resolveQuery(metadata.queryString);
+});
-function notify_blocklist() {
- var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
- getService(Ci.nsITimerCallback);
- blocklist.notify(null);
+async function checkQuery(expected) {
+ let promise = new Promise(resolve => {
+ resolveQuery = resolve;
+ });
+
+ Services.blocklist.QueryInterface(Ci.nsITimerCallback).notify(null);
+
+ equal(await promise, expected, "Got expected blocklist query string");
}
-function pathHandler(metadata, response) {
- Assert.equal(metadata.queryString, gExpectedQueryString);
- gNextTest();
-}
-
-function run_test() {
+add_task(async function setup() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
gTestserver = new HttpServer();
- gTestserver.registerPathHandler("/", pathHandler);
gTestserver.start(-1);
gPort = gTestserver.identity.primaryPort;
Services.prefs.setCharPref("extensions.blocklist.url",
- "http://localhost:" + gPort +
- "/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%");
-
- do_test_pending();
- test1();
-}
+ "http://example.com/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%");
+});
function getNowInSeconds() {
return Math.round(Date.now() / 1000);
}
-function test1() {
- gNextTest = test2;
- gExpectedQueryString = "1&1&new";
- notify_blocklist();
-}
+add_task(async function test1() {
+ await checkQuery("1&1&new");
+});
-function test2() {
- gNextTest = test3;
- gExpectedQueryString = "invalid&invalid&invalid";
- notify_blocklist();
-}
+add_task(async function test2() {
+ await checkQuery("invalid&invalid&invalid");
+});
-function test3() {
+add_task(async function test3() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - SECONDS_IN_DAY));
- gNextTest = test4;
- gExpectedQueryString = "2&2&1";
- notify_blocklist();
-}
+ await checkQuery("2&2&1");
+});
-function test4() {
+add_task(async function test4() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 2)));
- gNextTest = test5;
- gExpectedQueryString = "1&3&2";
- notify_blocklist();
-}
+ await checkQuery("1&3&2");
+});
-function test5() {
+add_task(async function test5() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds());
- gNextTest = test6;
- gExpectedQueryString = "invalid&invalid&0";
- notify_blocklist();
-}
+ await checkQuery("invalid&invalid&0");
+});
-function test6() {
+add_task(async function test6() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 3)));
- gNextTest = test7;
- gExpectedQueryString = "2&4&3";
- notify_blocklist();
-}
+ await checkQuery("2&4&3");
+});
-function test7() {
+add_task(async function test7() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 2147483647);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 4)));
- gNextTest = test8;
- gExpectedQueryString = "2147483647&5&4";
- notify_blocklist();
-}
+ await checkQuery("2147483647&5&4");
+});
-function test8() {
+add_task(async function test8() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 5)));
- gNextTest = test9;
- gExpectedQueryString = "1&6&5";
- notify_blocklist();
-}
+ await checkQuery("1&6&5");
+});
-function test9() {
+add_task(async function test9() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 2147483647);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 6)));
- gNextTest = test10;
- gExpectedQueryString = "2&2147483647&6";
- notify_blocklist();
-}
+ await checkQuery("2&2147483647&6");
+});
-function test10() {
+add_task(async function test10() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 7)));
- gNextTest = test11;
- gExpectedQueryString = "3&1&7";
- notify_blocklist();
-}
+ await checkQuery("3&1&7");
+});
-function test11() {
+add_task(async function test11() {
Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1);
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 8)));
- gNextTest = test12;
- gExpectedQueryString = "1&2&8";
- notify_blocklist();
-}
+ await checkQuery("1&2&8");
+});
-function test12() {
+add_task(async function test12() {
Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
(getNowInSeconds() - (SECONDS_IN_DAY * 9)));
- gNextTest = finish;
- gExpectedQueryString = "2&3&9";
- notify_blocklist();
-}
-
-function finish() {
- gTestserver.stop(do_test_finished);
-}
+ await checkQuery("2&3&9");
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -56,16 +56,18 @@ tags = blocklist
[test_blocklist_severities.js]
# Bug 676992: test consistently hangs on Android
skip-if = os == "android"
tags = blocklist
[test_blocklist_url_parameters.js]
# Bug 676992: test consistently hangs on Android
skip-if = os == "android"
tags = blocklist
+[test_blocklist_url_ping_count.js]
+tags = blocklist
[test_blocklistchange.js]
# Times out during parallel runs on desktop
requesttimeoutfactor = 2
tags = blocklist
[test_bootstrap.js]
skip-if = true # Bug 1358846 Bug 1365021 Bug 676992
[test_bootstrap_const.js]
[test_bootstrap_globals.js]
@@ -85,18 +87,16 @@ tags = blocklist
skip-if = os == "win" # Bug 1358846
[test_bug595081.js]
[test_bug596607.js]
[test_bug616841.js]
# Bug 676992: test consistently fails on Android
fail-if = os == "android"
[test_bug619730.js]
tags = blocklist
-[test_bug620837.js]
-tags = blocklist
[test_cache_certdb.js]
run-if = addon_signing
[test_cacheflush.js]
[test_childprocess.js]
[test_compatoverrides.js]
[test_corrupt.js]
[test_corruptfile.js]
[test_crash_annotation_quoting.js]