Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 Components.utils.import("resource://testing-common/httpd.js");
7 const PREF_BLOCKLIST_LASTUPDATETIME = "app.update.lastUpdateTime.blocklist-background-update-timer";
8 const PREF_BLOCKLIST_PINGCOUNTTOTAL = "extensions.blocklist.pingCountTotal";
9 const PREF_BLOCKLIST_PINGCOUNTVERSION = "extensions.blocklist.pingCountVersion";
11 const SECONDS_IN_DAY = 60 * 60 * 24;
13 var gExpectedQueryString = null;
14 var gNextTest = null;
15 var gTestserver = null;
17 function notify_blocklist() {
18 var blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"].
19 getService(AM_Ci.nsITimerCallback);
20 blocklist.notify(null);
21 }
23 function pathHandler(metadata, response) {
24 do_check_eq(metadata.queryString, gExpectedQueryString);
25 gNextTest();
26 }
28 function run_test() {
29 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
31 gTestserver = new HttpServer();
32 gTestserver.registerPathHandler("/", pathHandler);
33 gTestserver.start(-1);
34 gPort = gTestserver.identity.primaryPort;
36 Services.prefs.setCharPref("extensions.blocklist.url",
37 "http://localhost:" + gPort +
38 "/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%");
40 do_test_pending();
41 test1();
42 }
44 function getNowInSeconds() {
45 return Math.round(Date.now() / 1000);
46 }
48 function test1() {
49 gNextTest = test2;
50 gExpectedQueryString = "1&1&new";
51 notify_blocklist();
52 }
54 function test2() {
55 gNextTest = test3;
56 gExpectedQueryString = "invalid&invalid&invalid";
57 notify_blocklist();
58 }
60 function test3() {
61 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
62 (getNowInSeconds() - SECONDS_IN_DAY));
63 gNextTest = test4;
64 gExpectedQueryString = "2&2&1";
65 notify_blocklist();
66 }
68 function test4() {
69 Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1);
70 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
71 (getNowInSeconds() - (SECONDS_IN_DAY * 2)));
72 gNextTest = test5;
73 gExpectedQueryString = "1&3&2";
74 notify_blocklist();
75 }
77 function test5() {
78 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds());
79 gNextTest = test6;
80 gExpectedQueryString = "invalid&invalid&0";
81 notify_blocklist();
82 }
84 function test6() {
85 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
86 (getNowInSeconds() - (SECONDS_IN_DAY * 3)));
87 gNextTest = test7;
88 gExpectedQueryString = "2&4&3";
89 notify_blocklist();
90 }
92 function test7() {
93 Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, 2147483647);
94 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
95 (getNowInSeconds() - (SECONDS_IN_DAY * 4)));
96 gNextTest = test8;
97 gExpectedQueryString = "2147483647&5&4";
98 notify_blocklist();
99 }
101 function test8() {
102 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
103 (getNowInSeconds() - (SECONDS_IN_DAY * 5)));
104 gNextTest = test9;
105 gExpectedQueryString = "1&6&5";
106 notify_blocklist();
107 }
109 function test9() {
110 Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTTOTAL, 2147483647);
111 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
112 (getNowInSeconds() - (SECONDS_IN_DAY * 6)));
113 gNextTest = test10;
114 gExpectedQueryString = "2&2147483647&6";
115 notify_blocklist();
116 }
118 function test10() {
119 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
120 (getNowInSeconds() - (SECONDS_IN_DAY * 7)));
121 gNextTest = test11;
122 gExpectedQueryString = "3&1&7";
123 notify_blocklist();
124 }
126 function test11() {
127 Services.prefs.setIntPref(PREF_BLOCKLIST_PINGCOUNTVERSION, -1);
128 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
129 (getNowInSeconds() - (SECONDS_IN_DAY * 8)));
130 gNextTest = test12;
131 gExpectedQueryString = "1&2&8";
132 notify_blocklist();
133 }
135 function test12() {
136 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME,
137 (getNowInSeconds() - (SECONDS_IN_DAY * 9)));
138 gNextTest = finish;
139 gExpectedQueryString = "2&3&9";
140 notify_blocklist();
141 }
143 function finish() {
144 gTestserver.stop(do_test_finished);
145 }