1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +Components.utils.import("resource://testing-common/httpd.js"); 1.9 + 1.10 +const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer"; 1.11 +const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal"; 1.12 +const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion"; 1.13 + 1.14 +const SECONDS_IN_DAY = 60 * 60 * 24; 1.15 + 1.16 +var gExpectedQueryString = null; 1.17 +var gNextTest = null; 1.18 +var gTestserver = null; 1.19 + 1.20 +function notify_blocklist() { 1.21 + var blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"]. 1.22 + getService(AM_Ci.nsITimerCallback); 1.23 + blocklist.notify(null); 1.24 +} 1.25 + 1.26 +function pathHandler(metadata, response) { 1.27 + do_check_eq(metadata.queryString, gExpectedQueryString); 1.28 + gNextTest(); 1.29 +} 1.30 + 1.31 +function run_test() { 1.32 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); 1.33 + 1.34 + gTestserver = new HttpServer(); 1.35 + gTestserver.registerPathHandler("/", pathHandler); 1.36 + gTestserver.start(-1); 1.37 + gPort = gTestserver.identity.primaryPort; 1.38 + 1.39 + Services.prefs.setCharPref("extensions.blocklist.url", 1.40 + "http://localhost:" + gPort + 1.41 + "/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%"); 1.42 + 1.43 + do_test_pending(); 1.44 + test1(); 1.45 +} 1.46 + 1.47 +function getNowInSeconds() { 1.48 + return Math.round(Date.now() / 1000); 1.49 +} 1.50 + 1.51 +function test1() { 1.52 + gNextTest = test2; 1.53 + gExpectedQueryString = "1&1&new"; 1.54 + notify_blocklist(); 1.55 +} 1.56 + 1.57 +function test2() { 1.58 + gNextTest = test3; 1.59 + gExpectedQueryString = "invalid&invalid&invalid"; 1.60 + notify_blocklist(); 1.61 +} 1.62 + 1.63 +function test3() { 1.64 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.65 + (getNowInSeconds() - SECONDS_IN_DAY)); 1.66 + gNextTest = test4; 1.67 + gExpectedQueryString = "2&2&1"; 1.68 + notify_blocklist(); 1.69 +} 1.70 + 1.71 +function test4() { 1.72 + Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1); 1.73 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.74 + (getNowInSeconds() - (SECONDS_IN_DAY * 2))); 1.75 + gNextTest = test5; 1.76 + gExpectedQueryString = "1&3&2"; 1.77 + notify_blocklist(); 1.78 +} 1.79 + 1.80 +function test5() { 1.81 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds()); 1.82 + gNextTest = test6; 1.83 + gExpectedQueryString = "invalid&invalid&0"; 1.84 + notify_blocklist(); 1.85 +} 1.86 + 1.87 +function test6() { 1.88 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.89 + (getNowInSeconds() - (SECONDS_IN_DAY * 3))); 1.90 + gNextTest = test7; 1.91 + gExpectedQueryString = "2&4&3"; 1.92 + notify_blocklist(); 1.93 +} 1.94 + 1.95 +function test7() { 1.96 + Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 2147483647); 1.97 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.98 + (getNowInSeconds() - (SECONDS_IN_DAY * 4))); 1.99 + gNextTest = test8; 1.100 + gExpectedQueryString = "2147483647&5&4"; 1.101 + notify_blocklist(); 1.102 +} 1.103 + 1.104 +function test8() { 1.105 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.106 + (getNowInSeconds() - (SECONDS_IN_DAY * 5))); 1.107 + gNextTest = test9; 1.108 + gExpectedQueryString = "1&6&5"; 1.109 + notify_blocklist(); 1.110 +} 1.111 + 1.112 +function test9() { 1.113 + Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 2147483647); 1.114 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.115 + (getNowInSeconds() - (SECONDS_IN_DAY * 6))); 1.116 + gNextTest = test10; 1.117 + gExpectedQueryString = "2&2147483647&6"; 1.118 + notify_blocklist(); 1.119 +} 1.120 + 1.121 +function test10() { 1.122 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.123 + (getNowInSeconds() - (SECONDS_IN_DAY * 7))); 1.124 + gNextTest = test11; 1.125 + gExpectedQueryString = "3&1&7"; 1.126 + notify_blocklist(); 1.127 +} 1.128 + 1.129 +function test11() { 1.130 + Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1); 1.131 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.132 + (getNowInSeconds() - (SECONDS_IN_DAY * 8))); 1.133 + gNextTest = test12; 1.134 + gExpectedQueryString = "1&2&8"; 1.135 + notify_blocklist(); 1.136 +} 1.137 + 1.138 +function test12() { 1.139 + Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, 1.140 + (getNowInSeconds() - (SECONDS_IN_DAY * 9))); 1.141 + gNextTest = finish; 1.142 + gExpectedQueryString = "2&3&9"; 1.143 + notify_blocklist(); 1.144 +} 1.145 + 1.146 +function finish() { 1.147 + gTestserver.stop(do_test_finished); 1.148 +}