From 7f0d7c58d0056788ad989f5a08355f3ef5d600c0 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Thu, 20 Jan 2011 13:45:10 -0800 Subject: [PATCH] Bug 623950: Send startup time measurements along with the metadata requests. r=Unfocused, a=sdwilsh --- browser/app/profile/firefox.js | 2 +- .../mozapps/extensions/AddonRepository.jsm | 23 ++++++- .../extensions/test/browser/Makefile.in | 1 + .../test/browser/browser_bug623950.js | 68 +++++++++++++++++++ .../extensions/test/xpcshell/head_addons.js | 3 - 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 toolkit/mozapps/extensions/test/browser/browser_bug623950.js diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index e552225b4a8..4abe75e7938 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -59,7 +59,7 @@ pref("extensions.logging.enabled", false); // Preferences for AMO integration pref("extensions.getAddons.cache.enabled", true); pref("extensions.getAddons.maxResults", 15); -pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/guid:%IDS%?src=firefox"); +pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/guid:%IDS%?src=firefox&appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%"); pref("extensions.getAddons.search.browseURL", "https://addons.mozilla.org/%LOCALE%/%APP%/search?q=%TERMS%"); pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%?src=firefox"); pref("extensions.webservice.discoverURL", "https://services.addons.mozilla.org/%LOCALE%/%APP%/discovery/%VERSION%/%OS%"); diff --git a/toolkit/mozapps/extensions/AddonRepository.jsm b/toolkit/mozapps/extensions/AddonRepository.jsm index 04b750294bc..e22403f9e45 100644 --- a/toolkit/mozapps/extensions/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/AddonRepository.jsm @@ -701,11 +701,28 @@ var AddonRepository = { * The callback to pass results to */ getAddonsByIDs: function(aIDs, aCallback) { + let startupInfo = Cc["@mozilla.org/toolkit/app-startup;1"]. + getService(Ci.nsIAppStartup_MOZILLA_2_0). + getStartupInfo(); + let ids = aIDs.slice(0); - let url = this._formatURLPref(PREF_GETADDONS_BYIDS, { + + let params = { API_VERSION : API_VERSION, IDS : ids.map(encodeURIComponent).join(',') - }); + }; + + if (startupInfo.process) { + if (startupInfo.main) + params.TIME_MAIN = startupInfo.main - startupInfo.process; + if (startupInfo.firstPaint) + params.TIME_FIRST_PAINT = startupInfo.firstPaint - startupInfo.process; + if (startupInfo.sessionRestored) + params.TIME_SESSION_RESTORED = startupInfo.sessionRestored - + startupInfo.process; + }; + + let url = this._formatURLPref(PREF_GETADDONS_BYIDS, params); let self = this; function handleResults(aElements, aTotalResults) { @@ -1124,6 +1141,8 @@ var AddonRepository = { this._callback = aCallback; this._maxResults = aMaxResults; + LOG("Requesting " + aURI); + this._request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. createInstance(Ci.nsIXMLHttpRequest); this._request.open("GET", aURI, true); diff --git a/toolkit/mozapps/extensions/test/browser/Makefile.in b/toolkit/mozapps/extensions/test/browser/Makefile.in index 6096cda3887..084d75e4882 100644 --- a/toolkit/mozapps/extensions/test/browser/Makefile.in +++ b/toolkit/mozapps/extensions/test/browser/Makefile.in @@ -87,6 +87,7 @@ _TEST_FILES = \ head.js \ browser_bug557956.js \ browser_bug616841.js \ + browser_bug623950.js \ browser_updatessl.js \ browser_installssl.js \ $(NULL) diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug623950.js b/toolkit/mozapps/extensions/test/browser/browser_bug623950.js new file mode 100644 index 00000000000..ccb9db1b980 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_bug623950.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests that the metadata request includes startup time measurements + +Components.utils.import("resource://gre/modules/AddonRepository.jsm"); + +var gManagerWindow; +var gProvider; + +function parseParams(aQuery) { + let params = {}; + + aQuery.split("&").forEach(function(aParam) { + let [key, value] = aParam.split("="); + params[key] = value; + }); + + return params; +} + +function test() { + waitForExplicitFinish(); + + var gSeenRequest = false; + + gProvider = new MockProvider(); + gProvider.createAddons([{ + id: "test1@tests.mozilla.org", + name: "Test add-on" + }]); + + function observe(aSubject, aTopic, aData) { + aSubject.QueryInterface(Ci.nsIChannel); + let url = aSubject.URI.QueryInterface(Ci.nsIURL); + if (url.filePath != "/extensions-dummy/metadata") + return; + info(url.query); + + let params = parseParams(url.query); + + is(params.appOS, Services.appinfo.OS, "OS should be correct"); + is(params.appVersion, Services.appinfo.version, "Version should be correct"); + ok(params.tMain >= 0, "Should be a sensible tMain"); + ok(params.tFirstPaint >= 0, "Should be a sensible tFirstPaint"); + ok(params.tSessionRestored >= 0, "Should be a sensible tSessionRestored"); + + gSeenRequest = true; + } + + // Watch HTTP requests + Services.obs.addObserver(observe, "http-on-modify-request", false); + Services.prefs.setCharPref("extensions.getAddons.get.url", + "http://127.0.0.1:8888/extensions-dummy/metadata?appOS=%OS%&appVersion=%VERSION%&tMain=%TIME_MAIN%&tFirstPaint=%TIME_FIRST_PAINT%&tSessionRestored=%TIME_SESSION_RESTORED%"); + + registerCleanupFunction(function() { + Services.obs.removeObserver(observe, "http-on-modify-request"); + Services.prefs.clearUserPref("extensions.getAddons.get.url"); + }); + + AddonRepository.getAddonsByIDs(["test1@tests.mozilla.org"], { + searchFailed: function() { + ok(gSeenRequest, "Should have seen metadata request"); + finish(); + } + }); +} diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index 37801a8685e..64f7fffa02f 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -1049,9 +1049,6 @@ Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false); // Disable the compatibility updates window by default Services.prefs.setBoolPref("extensions.showMismatchUI", false); -// By default, don't cache add-ons in AddonRepository.jsm -Services.prefs.setBoolPref("extensions.getAddons.cache.enabled", false); - // Point update checks to the local machine for fast failures Services.prefs.setCharPref("extensions.update.url", "http://127.0.0.1/updateURL"); Services.prefs.setCharPref("extensions.blocklist.url", "http://127.0.0.1/blocklistURL");