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.
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 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | const {interfaces: Ci, results: Cr, utils: Cu} = Components; |
michael@0 | 7 | |
michael@0 | 8 | Cu.import("resource://gre/modules/Metrics.jsm"); |
michael@0 | 9 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/services/healthreport/providers.jsm"); |
michael@0 | 12 | Cu.import("resource://testing-common/services/healthreport/utils.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | |
michael@0 | 15 | function run_test() { |
michael@0 | 16 | run_next_test(); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | add_test(function test_constructor() { |
michael@0 | 20 | let provider = new AppInfoProvider(); |
michael@0 | 21 | |
michael@0 | 22 | run_next_test(); |
michael@0 | 23 | }); |
michael@0 | 24 | |
michael@0 | 25 | add_task(function test_collect_smoketest() { |
michael@0 | 26 | let storage = yield Metrics.Storage("collect_smoketest"); |
michael@0 | 27 | let provider = new AppInfoProvider(); |
michael@0 | 28 | yield provider.init(storage); |
michael@0 | 29 | |
michael@0 | 30 | let now = new Date(); |
michael@0 | 31 | yield provider.collectConstantData(); |
michael@0 | 32 | |
michael@0 | 33 | let m = provider.getMeasurement("appinfo", 2); |
michael@0 | 34 | let data = yield storage.getMeasurementValues(m.id); |
michael@0 | 35 | let serializer = m.serializer(m.SERIALIZE_JSON); |
michael@0 | 36 | let d = serializer.singular(data.singular); |
michael@0 | 37 | |
michael@0 | 38 | do_check_eq(d._v, 2); |
michael@0 | 39 | do_check_eq(d.vendor, "Mozilla"); |
michael@0 | 40 | do_check_eq(d.name, "xpcshell"); |
michael@0 | 41 | do_check_eq(d.id, "xpcshell@tests.mozilla.org"); |
michael@0 | 42 | do_check_eq(d.version, "1"); |
michael@0 | 43 | do_check_eq(d.appBuildID, "20121107"); |
michael@0 | 44 | do_check_eq(d.platformVersion, "p-ver"); |
michael@0 | 45 | do_check_eq(d.platformBuildID, "20121106"); |
michael@0 | 46 | do_check_eq(d.os, "XPCShell"); |
michael@0 | 47 | do_check_eq(d.xpcomabi, "noarch-spidermonkey"); |
michael@0 | 48 | |
michael@0 | 49 | do_check_eq(data.days.size, 1); |
michael@0 | 50 | do_check_true(data.days.hasDay(now)); |
michael@0 | 51 | let day = data.days.getDay(now); |
michael@0 | 52 | do_check_eq(day.size, 3); |
michael@0 | 53 | do_check_true(day.has("isDefaultBrowser")); |
michael@0 | 54 | do_check_true(day.has("isTelemetryEnabled")); |
michael@0 | 55 | do_check_true(day.has("isBlocklistEnabled")); |
michael@0 | 56 | |
michael@0 | 57 | // TODO Bug 827189 Actually test this properly. On some local builds, this |
michael@0 | 58 | // is always -1 (the service throws). On buildbot, it seems to always be 0. |
michael@0 | 59 | do_check_neq(day.get("isDefaultBrowser"), 1); |
michael@0 | 60 | |
michael@0 | 61 | yield provider.shutdown(); |
michael@0 | 62 | yield storage.close(); |
michael@0 | 63 | }); |
michael@0 | 64 | |
michael@0 | 65 | add_task(function test_record_version() { |
michael@0 | 66 | let storage = yield Metrics.Storage("record_version"); |
michael@0 | 67 | |
michael@0 | 68 | let provider = new AppInfoProvider(); |
michael@0 | 69 | let now = new Date(); |
michael@0 | 70 | yield provider.init(storage); |
michael@0 | 71 | |
michael@0 | 72 | // The provider records information on startup. |
michael@0 | 73 | let m = provider.getMeasurement("versions", 2); |
michael@0 | 74 | let data = yield m.getValues(); |
michael@0 | 75 | |
michael@0 | 76 | do_check_true(data.days.hasDay(now)); |
michael@0 | 77 | let day = data.days.getDay(now); |
michael@0 | 78 | do_check_eq(day.size, 4); |
michael@0 | 79 | do_check_true(day.has("appVersion")); |
michael@0 | 80 | do_check_true(day.has("platformVersion")); |
michael@0 | 81 | do_check_true(day.has("appBuildID")); |
michael@0 | 82 | do_check_true(day.has("platformBuildID")); |
michael@0 | 83 | |
michael@0 | 84 | let value = day.get("appVersion"); |
michael@0 | 85 | do_check_true(Array.isArray(value)); |
michael@0 | 86 | do_check_eq(value.length, 1); |
michael@0 | 87 | let ai = getAppInfo(); |
michael@0 | 88 | do_check_eq(value[0], ai.version); |
michael@0 | 89 | |
michael@0 | 90 | value = day.get("platformVersion"); |
michael@0 | 91 | do_check_true(Array.isArray(value)); |
michael@0 | 92 | do_check_eq(value.length, 1); |
michael@0 | 93 | do_check_eq(value[0], ai.platformVersion); |
michael@0 | 94 | |
michael@0 | 95 | value = day.get("appBuildID"); |
michael@0 | 96 | do_check_true(Array.isArray(value)); |
michael@0 | 97 | do_check_eq(value.length, 1); |
michael@0 | 98 | do_check_eq(value[0], ai.appBuildID); |
michael@0 | 99 | |
michael@0 | 100 | value = day.get("platformBuildID"); |
michael@0 | 101 | do_check_true(Array.isArray(value)); |
michael@0 | 102 | do_check_eq(value.length, 1); |
michael@0 | 103 | do_check_eq(value[0], ai.platformBuildID); |
michael@0 | 104 | |
michael@0 | 105 | yield provider.shutdown(); |
michael@0 | 106 | yield storage.close(); |
michael@0 | 107 | }); |
michael@0 | 108 | |
michael@0 | 109 | add_task(function test_record_version_change() { |
michael@0 | 110 | let storage = yield Metrics.Storage("record_version_change"); |
michael@0 | 111 | |
michael@0 | 112 | let provider = new AppInfoProvider(); |
michael@0 | 113 | let now = new Date(); |
michael@0 | 114 | yield provider.init(storage); |
michael@0 | 115 | yield provider.shutdown(); |
michael@0 | 116 | |
michael@0 | 117 | let ai = getAppInfo(); |
michael@0 | 118 | ai.version = "new app version"; |
michael@0 | 119 | ai.platformVersion = "new platform version"; |
michael@0 | 120 | ai.appBuildID = "new app id"; |
michael@0 | 121 | ai.platformBuildID = "new platform id"; |
michael@0 | 122 | updateAppInfo(ai); |
michael@0 | 123 | |
michael@0 | 124 | provider = new AppInfoProvider(); |
michael@0 | 125 | yield provider.init(storage); |
michael@0 | 126 | |
michael@0 | 127 | // There should be 2 records in the versions history. |
michael@0 | 128 | let m = provider.getMeasurement("versions", 2); |
michael@0 | 129 | let data = yield m.getValues(); |
michael@0 | 130 | do_check_true(data.days.hasDay(now)); |
michael@0 | 131 | let day = data.days.getDay(now); |
michael@0 | 132 | |
michael@0 | 133 | let value = day.get("appVersion"); |
michael@0 | 134 | do_check_true(Array.isArray(value)); |
michael@0 | 135 | do_check_eq(value.length, 2); |
michael@0 | 136 | do_check_eq(value[1], "new app version"); |
michael@0 | 137 | |
michael@0 | 138 | value = day.get("platformVersion"); |
michael@0 | 139 | do_check_true(Array.isArray(value)); |
michael@0 | 140 | do_check_eq(value.length, 2); |
michael@0 | 141 | do_check_eq(value[1], "new platform version"); |
michael@0 | 142 | |
michael@0 | 143 | // There should be 2 records in the buildID history. |
michael@0 | 144 | value = day.get("appBuildID"); |
michael@0 | 145 | do_check_true(Array.isArray(value)); |
michael@0 | 146 | do_check_eq(value.length, 2); |
michael@0 | 147 | do_check_eq(value[1], "new app id"); |
michael@0 | 148 | |
michael@0 | 149 | value = day.get("platformBuildID"); |
michael@0 | 150 | do_check_true(Array.isArray(value)); |
michael@0 | 151 | do_check_eq(value.length, 2); |
michael@0 | 152 | do_check_eq(value[1], "new platform id"); |
michael@0 | 153 | |
michael@0 | 154 | yield provider.shutdown(); |
michael@0 | 155 | yield storage.close(); |
michael@0 | 156 | }); |
michael@0 | 157 | |
michael@0 | 158 | add_task(function test_record_telemetry() { |
michael@0 | 159 | let storage = yield Metrics.Storage("record_telemetry"); |
michael@0 | 160 | let provider; |
michael@0 | 161 | |
michael@0 | 162 | let now = new Date(); |
michael@0 | 163 | |
michael@0 | 164 | Services.prefs.setBoolPref("toolkit.telemetry.enabled", true); |
michael@0 | 165 | provider = new AppInfoProvider(); |
michael@0 | 166 | yield provider.init(storage); |
michael@0 | 167 | yield provider.collectConstantData(); |
michael@0 | 168 | |
michael@0 | 169 | let m = provider.getMeasurement("appinfo", 2); |
michael@0 | 170 | let data = yield m.getValues(); |
michael@0 | 171 | let d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 172 | do_check_eq(1, d.isTelemetryEnabled); |
michael@0 | 173 | yield provider.shutdown(); |
michael@0 | 174 | |
michael@0 | 175 | Services.prefs.setBoolPref("toolkit.telemetry.enabled", false); |
michael@0 | 176 | provider = new AppInfoProvider(); |
michael@0 | 177 | yield provider.init(storage); |
michael@0 | 178 | yield provider.collectConstantData(); |
michael@0 | 179 | |
michael@0 | 180 | m = provider.getMeasurement("appinfo", 2); |
michael@0 | 181 | data = yield m.getValues(); |
michael@0 | 182 | d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 183 | do_check_eq(0, d.isTelemetryEnabled); |
michael@0 | 184 | yield provider.shutdown(); |
michael@0 | 185 | |
michael@0 | 186 | yield storage.close(); |
michael@0 | 187 | }); |
michael@0 | 188 | |
michael@0 | 189 | add_task(function test_record_blocklist() { |
michael@0 | 190 | let storage = yield Metrics.Storage("record_blocklist"); |
michael@0 | 191 | |
michael@0 | 192 | let now = new Date(); |
michael@0 | 193 | |
michael@0 | 194 | Services.prefs.setBoolPref("extensions.blocklist.enabled", true); |
michael@0 | 195 | let provider = new AppInfoProvider(); |
michael@0 | 196 | yield provider.init(storage); |
michael@0 | 197 | yield provider.collectConstantData(); |
michael@0 | 198 | |
michael@0 | 199 | let m = provider.getMeasurement("appinfo", 2); |
michael@0 | 200 | let data = yield m.getValues(); |
michael@0 | 201 | let d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 202 | do_check_eq(d.isBlocklistEnabled, 1); |
michael@0 | 203 | yield provider.shutdown(); |
michael@0 | 204 | |
michael@0 | 205 | Services.prefs.setBoolPref("extensions.blocklist.enabled", false); |
michael@0 | 206 | provider = new AppInfoProvider(); |
michael@0 | 207 | yield provider.init(storage); |
michael@0 | 208 | yield provider.collectConstantData(); |
michael@0 | 209 | |
michael@0 | 210 | m = provider.getMeasurement("appinfo", 2); |
michael@0 | 211 | data = yield m.getValues(); |
michael@0 | 212 | d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 213 | do_check_eq(d.isBlocklistEnabled, 0); |
michael@0 | 214 | yield provider.shutdown(); |
michael@0 | 215 | |
michael@0 | 216 | yield storage.close(); |
michael@0 | 217 | }); |
michael@0 | 218 | |
michael@0 | 219 | add_task(function test_record_app_update () { |
michael@0 | 220 | let storage = yield Metrics.Storage("record_update"); |
michael@0 | 221 | |
michael@0 | 222 | Services.prefs.setBoolPref("app.update.enabled", true); |
michael@0 | 223 | Services.prefs.setBoolPref("app.update.auto", true); |
michael@0 | 224 | let provider = new AppInfoProvider(); |
michael@0 | 225 | yield provider.init(storage); |
michael@0 | 226 | let now = new Date(); |
michael@0 | 227 | yield provider.collectDailyData(); |
michael@0 | 228 | |
michael@0 | 229 | let m = provider.getMeasurement("update", 1); |
michael@0 | 230 | let data = yield m.getValues(); |
michael@0 | 231 | let d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 232 | do_check_eq(d.enabled, 1); |
michael@0 | 233 | do_check_eq(d.autoDownload, 1); |
michael@0 | 234 | |
michael@0 | 235 | Services.prefs.setBoolPref("app.update.enabled", false); |
michael@0 | 236 | Services.prefs.setBoolPref("app.update.auto", false); |
michael@0 | 237 | |
michael@0 | 238 | yield provider.collectDailyData(); |
michael@0 | 239 | data = yield m.getValues(); |
michael@0 | 240 | d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now)); |
michael@0 | 241 | do_check_eq(d.enabled, 0); |
michael@0 | 242 | do_check_eq(d.autoDownload, 0); |
michael@0 | 243 | |
michael@0 | 244 | yield provider.shutdown(); |
michael@0 | 245 | yield storage.close(); |
michael@0 | 246 | }); |
michael@0 | 247 | |
michael@0 | 248 | add_task(function test_healthreporter_integration () { |
michael@0 | 249 | let reporter = getHealthReporter("healthreporter_integration"); |
michael@0 | 250 | yield reporter.init(); |
michael@0 | 251 | |
michael@0 | 252 | try { |
michael@0 | 253 | yield reporter._providerManager.registerProviderFromType(AppInfoProvider); |
michael@0 | 254 | yield reporter.collectMeasurements(); |
michael@0 | 255 | |
michael@0 | 256 | let payload = yield reporter.getJSONPayload(true); |
michael@0 | 257 | let days = payload['data']['days']; |
michael@0 | 258 | |
michael@0 | 259 | for (let [day, measurements] in Iterator(days)) { |
michael@0 | 260 | do_check_eq(Object.keys(measurements).length, 3); |
michael@0 | 261 | do_check_true("org.mozilla.appInfo.appinfo" in measurements); |
michael@0 | 262 | do_check_true("org.mozilla.appInfo.update" in measurements); |
michael@0 | 263 | do_check_true("org.mozilla.appInfo.versions" in measurements); |
michael@0 | 264 | } |
michael@0 | 265 | } finally { |
michael@0 | 266 | reporter._shutdown(); |
michael@0 | 267 | } |
michael@0 | 268 | }); |