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

mercurial