michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that the metadata request includes startup time measurements michael@0: michael@0: let tmp = {}; michael@0: Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", tmp); michael@0: let AddonRepository = tmp.AddonRepository; michael@0: michael@0: var gTelemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); michael@0: var gManagerWindow; michael@0: var gProvider; michael@0: michael@0: function parseParams(aQuery) { michael@0: let params = {}; michael@0: michael@0: for (let param of aQuery.split("&")) { michael@0: let [key, value] = param.split("="); michael@0: params[key] = value; michael@0: } michael@0: michael@0: return params; michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: var gSeenRequest = false; michael@0: michael@0: gProvider = new MockProvider(); michael@0: gProvider.createAddons([{ michael@0: id: "test1@tests.mozilla.org", michael@0: name: "Test add-on" michael@0: }]); michael@0: michael@0: function observe(aSubject, aTopic, aData) { michael@0: aSubject.QueryInterface(Ci.nsIChannel); michael@0: let url = aSubject.URI.QueryInterface(Ci.nsIURL); michael@0: if (url.filePath != "/extensions-dummy/metadata") { michael@0: return; michael@0: } michael@0: info(url.query); michael@0: michael@0: // Check if we encountered telemetry errors and turn the tests for which michael@0: // we don't have valid data into known failures. michael@0: let snapshot = gTelemetry.getHistogramById("STARTUP_MEASUREMENT_ERRORS") michael@0: .snapshot(); michael@0: michael@0: let tProcessValid = (snapshot.counts[0] == 0); michael@0: let tMainValid = tProcessValid && (snapshot.counts[2] == 0); michael@0: let tFirstPaintValid = tProcessValid && (snapshot.counts[5] == 0); michael@0: let tSessionRestoredValid = tProcessValid && (snapshot.counts[6] == 0); michael@0: michael@0: let params = parseParams(url.query); michael@0: michael@0: is(params.appOS, Services.appinfo.OS, "OS should be correct"); michael@0: is(params.appVersion, Services.appinfo.version, "Version should be correct"); michael@0: michael@0: if (tMainValid) { michael@0: ok(params.tMain >= 0, "Should be a sensible tMain"); michael@0: } else { michael@0: todo(false, "An error occurred while recording the startup timestamps, skipping this test"); michael@0: } michael@0: michael@0: if (tFirstPaintValid) { michael@0: ok(params.tFirstPaint >= 0, "Should be a sensible tFirstPaint"); michael@0: } else { michael@0: todo(false, "An error occurred while recording the startup timestamps, skipping this test"); michael@0: } michael@0: michael@0: if (tSessionRestoredValid) { michael@0: ok(params.tSessionRestored >= 0, "Should be a sensible tSessionRestored"); michael@0: } else { michael@0: todo(false, "An error occurred while recording the startup timestamps, skipping this test"); michael@0: } michael@0: michael@0: gSeenRequest = true; michael@0: } michael@0: michael@0: const PREF = "extensions.getAddons.getWithPerformance.url"; michael@0: michael@0: // Watch HTTP requests michael@0: Services.obs.addObserver(observe, "http-on-modify-request", false); michael@0: Services.prefs.setCharPref(PREF, michael@0: "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: michael@0: registerCleanupFunction(function() { michael@0: Services.obs.removeObserver(observe, "http-on-modify-request"); michael@0: }); michael@0: michael@0: AddonRepository._beginGetAddons(["test1@tests.mozilla.org"], { michael@0: searchFailed: function() { michael@0: ok(gSeenRequest, "Should have seen metadata request"); michael@0: finish(); michael@0: } michael@0: }, true); michael@0: } michael@0: