michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: michael@0: const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer"; michael@0: const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal"; michael@0: const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion"; michael@0: michael@0: const SECONDS_IN_DAY = 60 * 60 * 24; michael@0: michael@0: var gExpectedQueryString = null; michael@0: var gNextTest = null; michael@0: var gTestserver = null; michael@0: michael@0: function notify_blocklist() { michael@0: var blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"]. michael@0: getService(AM_Ci.nsITimerCallback); michael@0: blocklist.notify(null); michael@0: } michael@0: michael@0: function pathHandler(metadata, response) { michael@0: do_check_eq(metadata.queryString, gExpectedQueryString); michael@0: gNextTest(); michael@0: } michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: michael@0: gTestserver = new HttpServer(); michael@0: gTestserver.registerPathHandler("/", pathHandler); michael@0: gTestserver.start(-1); michael@0: gPort = gTestserver.identity.primaryPort; michael@0: michael@0: Services.prefs.setCharPref("extensions.blocklist.url", michael@0: "http://localhost:" + gPort + michael@0: "/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%"); michael@0: michael@0: do_test_pending(); michael@0: test1(); michael@0: } michael@0: michael@0: function getNowInSeconds() { michael@0: return Math.round(Date.now() / 1000); michael@0: } michael@0: michael@0: function test1() { michael@0: gNextTest = test2; michael@0: gExpectedQueryString = "1&1&new"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test2() { michael@0: gNextTest = test3; michael@0: gExpectedQueryString = "invalid&invalid&invalid"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test3() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - SECONDS_IN_DAY)); michael@0: gNextTest = test4; michael@0: gExpectedQueryString = "2&2&1"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test4() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1); michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 2))); michael@0: gNextTest = test5; michael@0: gExpectedQueryString = "1&3&2"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test5() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds()); michael@0: gNextTest = test6; michael@0: gExpectedQueryString = "invalid&invalid&0"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test6() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 3))); michael@0: gNextTest = test7; michael@0: gExpectedQueryString = "2&4&3"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test7() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 2147483647); michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 4))); michael@0: gNextTest = test8; michael@0: gExpectedQueryString = "2147483647&5&4"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test8() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 5))); michael@0: gNextTest = test9; michael@0: gExpectedQueryString = "1&6&5"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test9() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 2147483647); michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 6))); michael@0: gNextTest = test10; michael@0: gExpectedQueryString = "2&2147483647&6"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test10() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 7))); michael@0: gNextTest = test11; michael@0: gExpectedQueryString = "3&1&7"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test11() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1); michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 8))); michael@0: gNextTest = test12; michael@0: gExpectedQueryString = "1&2&8"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function test12() { michael@0: Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, michael@0: (getNowInSeconds() - (SECONDS_IN_DAY * 9))); michael@0: gNextTest = finish; michael@0: gExpectedQueryString = "2&3&9"; michael@0: notify_blocklist(); michael@0: } michael@0: michael@0: function finish() { michael@0: gTestserver.stop(do_test_finished); michael@0: }