1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_addonrepository_performance.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Tests that the metadata request includes startup time measurements 1.9 + 1.10 +let tmp = {}; 1.11 +Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", tmp); 1.12 +let AddonRepository = tmp.AddonRepository; 1.13 + 1.14 +var gTelemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); 1.15 +var gManagerWindow; 1.16 +var gProvider; 1.17 + 1.18 +function parseParams(aQuery) { 1.19 + let params = {}; 1.20 + 1.21 + for (let param of aQuery.split("&")) { 1.22 + let [key, value] = param.split("="); 1.23 + params[key] = value; 1.24 + } 1.25 + 1.26 + return params; 1.27 +} 1.28 + 1.29 +function test() { 1.30 + waitForExplicitFinish(); 1.31 + 1.32 + var gSeenRequest = false; 1.33 + 1.34 + gProvider = new MockProvider(); 1.35 + gProvider.createAddons([{ 1.36 + id: "test1@tests.mozilla.org", 1.37 + name: "Test add-on" 1.38 + }]); 1.39 + 1.40 + function observe(aSubject, aTopic, aData) { 1.41 + aSubject.QueryInterface(Ci.nsIChannel); 1.42 + let url = aSubject.URI.QueryInterface(Ci.nsIURL); 1.43 + if (url.filePath != "/extensions-dummy/metadata") { 1.44 + return; 1.45 + } 1.46 + info(url.query); 1.47 + 1.48 + // Check if we encountered telemetry errors and turn the tests for which 1.49 + // we don't have valid data into known failures. 1.50 + let snapshot = gTelemetry.getHistogramById("STARTUP_MEASUREMENT_ERRORS") 1.51 + .snapshot(); 1.52 + 1.53 + let tProcessValid = (snapshot.counts[0] == 0); 1.54 + let tMainValid = tProcessValid && (snapshot.counts[2] == 0); 1.55 + let tFirstPaintValid = tProcessValid && (snapshot.counts[5] == 0); 1.56 + let tSessionRestoredValid = tProcessValid && (snapshot.counts[6] == 0); 1.57 + 1.58 + let params = parseParams(url.query); 1.59 + 1.60 + is(params.appOS, Services.appinfo.OS, "OS should be correct"); 1.61 + is(params.appVersion, Services.appinfo.version, "Version should be correct"); 1.62 + 1.63 + if (tMainValid) { 1.64 + ok(params.tMain >= 0, "Should be a sensible tMain"); 1.65 + } else { 1.66 + todo(false, "An error occurred while recording the startup timestamps, skipping this test"); 1.67 + } 1.68 + 1.69 + if (tFirstPaintValid) { 1.70 + ok(params.tFirstPaint >= 0, "Should be a sensible tFirstPaint"); 1.71 + } else { 1.72 + todo(false, "An error occurred while recording the startup timestamps, skipping this test"); 1.73 + } 1.74 + 1.75 + if (tSessionRestoredValid) { 1.76 + ok(params.tSessionRestored >= 0, "Should be a sensible tSessionRestored"); 1.77 + } else { 1.78 + todo(false, "An error occurred while recording the startup timestamps, skipping this test"); 1.79 + } 1.80 + 1.81 + gSeenRequest = true; 1.82 + } 1.83 + 1.84 + const PREF = "extensions.getAddons.getWithPerformance.url"; 1.85 + 1.86 + // Watch HTTP requests 1.87 + Services.obs.addObserver(observe, "http-on-modify-request", false); 1.88 + Services.prefs.setCharPref(PREF, 1.89 + "http://127.0.0.1:8888/extensions-dummy/metadata?appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%"); 1.90 + 1.91 + registerCleanupFunction(function() { 1.92 + Services.obs.removeObserver(observe, "http-on-modify-request"); 1.93 + }); 1.94 + 1.95 + AddonRepository._beginGetAddons(["test1@tests.mozilla.org"], { 1.96 + searchFailed: function() { 1.97 + ok(gSeenRequest, "Should have seen metadata request"); 1.98 + finish(); 1.99 + } 1.100 + }, true); 1.101 +} 1.102 +