toolkit/mozapps/extensions/test/xpcshell/test_bug620837.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e628c23b5019
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 Components.utils.import("resource://testing-common/httpd.js");
6
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";
10
11 const SECONDS_IN_DAY = 60 * 60 * 24;
12
13 var gExpectedQueryString = null;
14 var gNextTest = null;
15 var gTestserver = null;
16
17 function notify_blocklist() {
18 var blocklist = AM_Cc["@mozilla.org/extensions/blocklist;1"].
19 getService(AM_Ci.nsITimerCallback);
20 blocklist.notify(null);
21 }
22
23 function pathHandler(metadata, response) {
24 do_check_eq(metadata.queryString, gExpectedQueryString);
25 gNextTest();
26 }
27
28 function run_test() {
29 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
30
31 gTestserver = new HttpServer();
32 gTestserver.registerPathHandler("/", pathHandler);
33 gTestserver.start(-1);
34 gPort = gTestserver.identity.primaryPort;
35
36 Services.prefs.setCharPref("extensions.blocklist.url",
37 "http://localhost:" + gPort +
38 "/?%PING_COUNT%&%TOTAL_PING_COUNT%&%DAYS_SINCE_LAST_PING%");
39
40 do_test_pending();
41 test1();
42 }
43
44 function getNowInSeconds() {
45 return Math.round(Date.now() / 1000);
46 }
47
48 function test1() {
49 gNextTest = test2;
50 gExpectedQueryString = "1&1&new";
51 notify_blocklist();
52 }
53
54 function test2() {
55 gNextTest = test3;
56 gExpectedQueryString = "invalid&invalid&invalid";
57 notify_blocklist();
58 }
59
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 }
67
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 }
76
77 function test5() {
78 Services.prefs.setIntPref(PREF_BLOCKLIST_LASTUPDATETIME, getNowInSeconds());
79 gNextTest = test6;
80 gExpectedQueryString = "invalid&invalid&0";
81 notify_blocklist();
82 }
83
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 }
91
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 }
100
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 }
108
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 }
117
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 }
125
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 }
134
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 }
142
143 function finish() {
144 gTestserver.stop(do_test_finished);
145 }

mercurial