mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 14:20:14 +02:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
109 lines
4.1 KiB
JavaScript
109 lines
4.1 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
// This tests basic end-to-end functionality of the untrusted modules
|
|
// telemetry ping. We force the ping to fire, capture the result, and test for:
|
|
// - Basic payload structure validity.
|
|
// - Expected results for a few specific DLLs
|
|
|
|
"use strict";
|
|
|
|
const {Preferences} = ChromeUtils.import("resource://gre/modules/Preferences.jsm");
|
|
const {ctypes} = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
|
|
|
|
const kDllName = "modules-test.dll";
|
|
|
|
let gDllHandle;
|
|
|
|
add_task(async function setup() {
|
|
do_get_profile();
|
|
|
|
// Dynamically load a DLL which we have hard-coded as untrusted; this should
|
|
// appear in the payload.
|
|
gDllHandle = ctypes.open(do_get_file(kDllName).path);
|
|
|
|
// Force the timer to fire (using a small interval).
|
|
Cc["@mozilla.org/updates/timer-manager;1"]
|
|
.getService(Ci.nsIObserver).observe(null, "utm-test-init", "");
|
|
Preferences.set("toolkit.telemetry.untrustedModulesPing.frequency", 0);
|
|
Preferences.set("app.update.url", "http://localhost");
|
|
|
|
// Start the local ping server and setup Telemetry to use it during the tests.
|
|
PingServer.start();
|
|
Preferences.set(TelemetryUtils.Preferences.Server,
|
|
"http://localhost:" + PingServer.port);
|
|
|
|
return TelemetryController.testSetup();
|
|
});
|
|
|
|
registerCleanupFunction(function() {
|
|
if (gDllHandle) {
|
|
gDllHandle.close();
|
|
gDllHandle = null;
|
|
}
|
|
return PingServer.stop();
|
|
});
|
|
|
|
add_task(async function test_send_ping() {
|
|
let expectedModules = [
|
|
// This checks that a DLL loaded during runtime is evaluated properly.
|
|
// This is hard-coded as untrusted in ModuleEvaluator for testing.
|
|
{ nameMatch: new RegExp(kDllName, "i"), expectedTrusted: false,
|
|
isStartup: false, wasFound: false },
|
|
|
|
// These check that a DLL loaded at startup is evaluated properly.
|
|
// This is hard-coded as untrusted in ModuleEvaluator for testing.
|
|
{ nameMatch: /untrusted-startup-test-dll.dll/i, expectedTrusted: false,
|
|
isStartup: true, wasFound: false },
|
|
{ nameMatch: /kernelbase.dll/i, expectedTrusted: true,
|
|
isStartup: true, wasFound: false },
|
|
];
|
|
|
|
// There is a tiny chance some other ping is being sent legitimately before
|
|
// the one we care about. Spin until we find the correct ping type.
|
|
let found;
|
|
while (true) {
|
|
found = await PingServer.promiseNextPing();
|
|
if (found.type == "untrustedModules") {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Test the ping payload's validity.
|
|
Assert.ok(found, "Untrusted modules ping submitted");
|
|
Assert.ok(found.environment, "Ping has an environment");
|
|
Assert.ok(typeof(found.clientId) != "undefined", "Ping has a client ID");
|
|
|
|
Assert.equal(found.payload.structVersion, 1, "Version is correct");
|
|
Assert.ok(found.payload.combinedStacks, "'combinedStacks' array exists");
|
|
Assert.ok(found.payload.events, "'events' array exists");
|
|
Assert.equal(found.payload.combinedStacks.stacks.length,
|
|
found.payload.events.length,
|
|
"combinedStacks.length == events.length");
|
|
|
|
for (let event of found.payload.events) {
|
|
Assert.ok(event.modules, "'modules' array exists");
|
|
for (let mod of event.modules) {
|
|
Assert.ok(typeof(mod.moduleName) != "undefined",
|
|
`Module contains moduleName: ${mod.moduleName}`);
|
|
Assert.ok(typeof(mod.moduleTrustFlags) != "undefined",
|
|
`Module contains moduleTrustFlags: ${mod.moduleTrustFlags}`);
|
|
Assert.ok(typeof(mod.baseAddress) != "undefined",
|
|
"Module contains baseAddress");
|
|
Assert.ok(typeof(mod.loaderName) != "undefined",
|
|
"Module contains loaderName");
|
|
for (let x of expectedModules) {
|
|
if (x.nameMatch.test(mod.moduleName)) {
|
|
x.wasFound = true;
|
|
Assert.equal(x.isStartup, event.isStartup,
|
|
`isStartup == expected for module: ${x.nameMatch.source}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let x of expectedModules) {
|
|
Assert.equal(!x.wasFound, x.expectedTrusted,
|
|
`Trustworthiness == expected for module: ${x.nameMatch.source}`);
|
|
}
|
|
});
|