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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial