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 // Tests that the metadata request includes startup time measurements
7 let tmp = {};
8 Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", tmp);
9 let AddonRepository = tmp.AddonRepository;
11 var gTelemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
12 var gManagerWindow;
13 var gProvider;
15 function parseParams(aQuery) {
16 let params = {};
18 for (let param of aQuery.split("&")) {
19 let [key, value] = param.split("=");
20 params[key] = value;
21 }
23 return params;
24 }
26 function test() {
27 waitForExplicitFinish();
29 var gSeenRequest = false;
31 gProvider = new MockProvider();
32 gProvider.createAddons([{
33 id: "test1@tests.mozilla.org",
34 name: "Test add-on"
35 }]);
37 function observe(aSubject, aTopic, aData) {
38 aSubject.QueryInterface(Ci.nsIChannel);
39 let url = aSubject.URI.QueryInterface(Ci.nsIURL);
40 if (url.filePath != "/extensions-dummy/metadata") {
41 return;
42 }
43 info(url.query);
45 // Check if we encountered telemetry errors and turn the tests for which
46 // we don't have valid data into known failures.
47 let snapshot = gTelemetry.getHistogramById("STARTUP_MEASUREMENT_ERRORS")
48 .snapshot();
50 let tProcessValid = (snapshot.counts[0] == 0);
51 let tMainValid = tProcessValid && (snapshot.counts[2] == 0);
52 let tFirstPaintValid = tProcessValid && (snapshot.counts[5] == 0);
53 let tSessionRestoredValid = tProcessValid && (snapshot.counts[6] == 0);
55 let params = parseParams(url.query);
57 is(params.appOS, Services.appinfo.OS, "OS should be correct");
58 is(params.appVersion, Services.appinfo.version, "Version should be correct");
60 if (tMainValid) {
61 ok(params.tMain >= 0, "Should be a sensible tMain");
62 } else {
63 todo(false, "An error occurred while recording the startup timestamps, skipping this test");
64 }
66 if (tFirstPaintValid) {
67 ok(params.tFirstPaint >= 0, "Should be a sensible tFirstPaint");
68 } else {
69 todo(false, "An error occurred while recording the startup timestamps, skipping this test");
70 }
72 if (tSessionRestoredValid) {
73 ok(params.tSessionRestored >= 0, "Should be a sensible tSessionRestored");
74 } else {
75 todo(false, "An error occurred while recording the startup timestamps, skipping this test");
76 }
78 gSeenRequest = true;
79 }
81 const PREF = "extensions.getAddons.getWithPerformance.url";
83 // Watch HTTP requests
84 Services.obs.addObserver(observe, "http-on-modify-request", false);
85 Services.prefs.setCharPref(PREF,
86 "http://127.0.0.1:8888/extensions-dummy/metadata?appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%");
88 registerCleanupFunction(function() {
89 Services.obs.removeObserver(observe, "http-on-modify-request");
90 });
92 AddonRepository._beginGetAddons(["test1@tests.mozilla.org"], {
93 searchFailed: function() {
94 ok(gSeenRequest, "Should have seen metadata request");
95 finish();
96 }
97 }, true);
98 }