|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that the metadata request includes startup time measurements |
|
6 |
|
7 let tmp = {}; |
|
8 Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", tmp); |
|
9 let AddonRepository = tmp.AddonRepository; |
|
10 |
|
11 var gTelemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); |
|
12 var gManagerWindow; |
|
13 var gProvider; |
|
14 |
|
15 function parseParams(aQuery) { |
|
16 let params = {}; |
|
17 |
|
18 for (let param of aQuery.split("&")) { |
|
19 let [key, value] = param.split("="); |
|
20 params[key] = value; |
|
21 } |
|
22 |
|
23 return params; |
|
24 } |
|
25 |
|
26 function test() { |
|
27 waitForExplicitFinish(); |
|
28 |
|
29 var gSeenRequest = false; |
|
30 |
|
31 gProvider = new MockProvider(); |
|
32 gProvider.createAddons([{ |
|
33 id: "test1@tests.mozilla.org", |
|
34 name: "Test add-on" |
|
35 }]); |
|
36 |
|
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); |
|
44 |
|
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(); |
|
49 |
|
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); |
|
54 |
|
55 let params = parseParams(url.query); |
|
56 |
|
57 is(params.appOS, Services.appinfo.OS, "OS should be correct"); |
|
58 is(params.appVersion, Services.appinfo.version, "Version should be correct"); |
|
59 |
|
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 } |
|
65 |
|
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 } |
|
71 |
|
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 } |
|
77 |
|
78 gSeenRequest = true; |
|
79 } |
|
80 |
|
81 const PREF = "extensions.getAddons.getWithPerformance.url"; |
|
82 |
|
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%"); |
|
87 |
|
88 registerCleanupFunction(function() { |
|
89 Services.obs.removeObserver(observe, "http-on-modify-request"); |
|
90 }); |
|
91 |
|
92 AddonRepository._beginGetAddons(["test1@tests.mozilla.org"], { |
|
93 searchFailed: function() { |
|
94 ok(gSeenRequest, "Should have seen metadata request"); |
|
95 finish(); |
|
96 } |
|
97 }, true); |
|
98 } |
|
99 |