Bug 1470466 - Use a different telemetry histogram key for the userScripts injection. r=janerik,mixedpuppy

This patch adds a new telemetry histogram for the userScripts injection time and adds an additional test case to verify that the expected telemetry histograms are being updated.

This phabricator revision depends on the following bugs and their related mozreview requests:

- [Bug 1437861](https://bugzilla.mozilla.org/1437861) Implement userScripts.register and execute userScripts js code in isolated sandboxes (https://reviewboard.mozilla.org/r/219856/)
- [Bug 1437864](https://bugzilla.mozilla.org/1437866) Implement userScripts API methods to allow an extension to inject custom APIs in the isolated userScripts sandboxes (https://reviewboard.mozilla.org/r/220630/)

Differential Revision: https://phabricator.services.mozilla.com/D3893

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2018-09-12 16:58:55 +00:00
Родитель 6056022481
Коммит 0f496e199e
5 изменённых файлов: 150 добавлений и 2 удалений

Просмотреть файл

@ -585,7 +585,7 @@ class UserScript extends Script {
// The evaluations below may throw, in which case the promise will be
// automatically rejected.
ExtensionTelemetry.contentScriptInjection.stopwatchStart(extension, context);
ExtensionTelemetry.userScriptInjection.stopwatchStart(extension, context);
try {
let userScriptSandbox = this.sandboxes.get(context);
@ -607,7 +607,7 @@ class UserScript extends Script {
script.executeInGlobal(userScriptSandbox);
}
} finally {
ExtensionTelemetry.contentScriptInjection.stopwatchFinish(extension, context);
ExtensionTelemetry.userScriptInjection.stopwatchFinish(extension, context);
}
}

Просмотреть файл

@ -24,6 +24,7 @@ const histograms = {
"storageLocalSetJSON": "WEBEXT_STORAGE_LOCAL_SET_MS",
"storageLocalGetIDB": "WEBEXT_STORAGE_LOCAL_IDB_GET_MS",
"storageLocalSetIDB": "WEBEXT_STORAGE_LOCAL_IDB_SET_MS",
"userScriptInjection": "WEBEXT_USER_SCRIPT_INJECTION_MS",
};
/**

Просмотреть файл

@ -0,0 +1,123 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const HISTOGRAM = "WEBEXT_USER_SCRIPT_INJECTION_MS";
const HISTOGRAM_KEYED = "WEBEXT_USER_SCRIPT_INJECTION_MS_BY_ADDONID";
const server = createHttpServer();
server.registerDirectory("/data/", do_get_file("data"));
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
add_task(async function test_userScripts_telemetry() {
function apiScript() {
browser.userScripts.setScriptAPIs({
US_test_sendMessage([msg, data], scriptMetadata, scriptGlobal) {
browser.test.sendMessage(msg, {data, scriptMetadata});
},
});
}
async function background() {
const code = `
US_test_sendMessage("userScript-run", {location: window.location.href});
`;
await browser.userScripts.register({
js: [{code}],
matches: ["http://*/*/file_sample.html"],
runAt: "document_end",
scriptMetadata: {
name: "test-user-script-telemetry",
},
});
browser.test.sendMessage("userScript-registered");
}
let testExtensionDef = {
manifest: {
permissions: [
"http://*/*/file_sample.html",
],
userScripts: {
apiScript: "api-script.js",
},
},
background,
files: {
"api-script.js": apiScript,
},
};
let extension = ExtensionTestUtils.loadExtension(testExtensionDef);
let extension2 = ExtensionTestUtils.loadExtension(testExtensionDef);
let contentPage = await ExtensionTestUtils.loadContentPage("about:blank");
clearHistograms();
let process = IS_OOP ? "content" : "parent";
ok(!(HISTOGRAM in getSnapshots(process)), `No data recorded for histogram: ${HISTOGRAM}.`);
ok(!(HISTOGRAM_KEYED in getKeyedSnapshots(process)),
`No data recorded for keyed histogram: ${HISTOGRAM_KEYED}.`);
await extension.startup();
await extension.awaitMessage("userScript-registered");
let extensionId = extension.extension.id;
ok(!(HISTOGRAM in getSnapshots(process)),
`No data recorded for histogram after startup: ${HISTOGRAM}.`);
ok(!(HISTOGRAM_KEYED in getKeyedSnapshots(process)),
`No data recorded for keyed histogram: ${HISTOGRAM_KEYED}.`);
let url = `${BASE_URL}/file_sample.html`;
contentPage.loadURL(url);
const res = await extension.awaitMessage("userScript-run");
Assert.deepEqual(res, {
data: {location: url},
scriptMetadata: {name: "test-user-script-telemetry"},
}, "The userScript has been executed on the content page as expected");
await promiseTelemetryRecorded(HISTOGRAM, process, 1);
await promiseKeyedTelemetryRecorded(HISTOGRAM_KEYED, process, extensionId, 1);
equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1,
`Data recorded for histogram: ${HISTOGRAM}.`);
equal(arraySum(getKeyedSnapshots(process)[HISTOGRAM_KEYED][extensionId].counts), 1,
`Data recorded for histogram: ${HISTOGRAM_KEYED} with key ${extensionId}.`);
await contentPage.close();
await extension.unload();
await extension2.startup();
await extension2.awaitMessage("userScript-registered");
let extensionId2 = extension2.extension.id;
equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 1,
`No data recorded for histogram after startup: ${HISTOGRAM}.`);
equal(arraySum(getKeyedSnapshots(process)[HISTOGRAM_KEYED][extensionId].counts), 1,
`No new data recorded for histogram after extension2 startup: ${HISTOGRAM_KEYED} with key ${extensionId}.`);
ok(!(extensionId2 in getKeyedSnapshots(process)[HISTOGRAM_KEYED]),
`No data recorded for histogram after startup: ${HISTOGRAM_KEYED} with key ${extensionId2}.`);
contentPage = await ExtensionTestUtils.loadContentPage(url);
const res2 = await extension2.awaitMessage("userScript-run");
Assert.deepEqual(res2, {
data: {location: url},
scriptMetadata: {name: "test-user-script-telemetry"},
}, "The userScript has been executed on the content page as expected");
await promiseTelemetryRecorded(HISTOGRAM, process, 2);
await promiseKeyedTelemetryRecorded(HISTOGRAM_KEYED, process, extensionId2, 1);
equal(arraySum(getSnapshots(process)[HISTOGRAM].counts), 2,
`Data recorded for histogram: ${HISTOGRAM}.`);
equal(arraySum(getKeyedSnapshots(process)[HISTOGRAM_KEYED][extensionId].counts), 1,
`No new data recorded for histogram: ${HISTOGRAM_KEYED} with key ${extensionId}.`);
equal(arraySum(getKeyedSnapshots(process)[HISTOGRAM_KEYED][extensionId2].counts), 1,
`Data recorded for histogram: ${HISTOGRAM_KEYED} with key ${extensionId2}.`);
await contentPage.close();
await extension2.unload();
});

Просмотреть файл

@ -130,6 +130,7 @@ skip-if = os == "android"
[test_ext_unload_frame.js]
skip-if = true # Too frequent intermittent failures
[test_ext_userScripts.js]
[test_ext_userScripts_telemetry.js]
[test_ext_webRequest_auth.js]
skip-if = os == "android" && debug
[test_ext_webRequest_filterResponseData.js]

Просмотреть файл

@ -13718,6 +13718,29 @@
"releaseChannelCollection": "opt-out",
"description": "The number of times a storage.local backend data migration has been completed and results in one of the categories."
},
"WEBEXT_USER_SCRIPT_INJECTION_MS": {
"record_in_processes": ["main", "content"],
"alert_emails": ["addons-dev-internal@mozilla.com", "lgreco@mozilla.com"],
"bug_numbers": [1470466],
"expires_in_version": "67",
"kind": "exponential",
"releaseChannelCollection": "opt-out",
"high": 50000,
"n_buckets": 100,
"description": "The amount of time it takes for userScripts from a WebExtension to be injected into a window."
},
"WEBEXT_USER_SCRIPT_INJECTION_MS_BY_ADDONID": {
"record_in_processes": ["main", "content"],
"alert_emails": ["addons-dev-internal@mozilla.com", "lgreco@mozilla.com"],
"bug_numbers": [1470466],
"expires_in_version": "67",
"kind": "exponential",
"releaseChannelCollection": "opt-out",
"high": 50000,
"n_buckets": 100,
"description": "The amount of time it takes for userScripts from a WebExtension to be injected into a window, keyed by addon id.",
"keyed": true
},
"EXTENSION_UPDATE_TYPE": {
"record_in_processes": ["main"],
"alert_emails": ["addons-dev-internal@mozilla.com"],