mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-26 21:50:42 -10:00
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
// Test that TelemetryController sends close to shutdown don't lead
|
|
// to AsyncShutdown timeouts.
|
|
|
|
"use strict";
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm", this);
|
|
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
|
Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
|
|
Cu.import("resource://gre/modules/Timer.jsm", this);
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
|
Cu.import("resource://gre/modules/AsyncShutdown.jsm", this);
|
|
Cu.import("resource://testing-common/httpd.js", this);
|
|
|
|
const PREF_BRANCH = "toolkit.telemetry.";
|
|
const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
|
|
|
|
function contentHandler(metadata, response)
|
|
{
|
|
dump("contentHandler called for path: " + metadata._path + "\n");
|
|
// We intentionally don't finish writing the response here to let the
|
|
// client time out.
|
|
response.processAsync();
|
|
response.setHeader("Content-Type", "text/plain");
|
|
}
|
|
|
|
function run_test() {
|
|
// Addon manager needs a profile directory
|
|
do_get_profile();
|
|
loadAddonManager("[email protected]", "XPCShell", "1", "1.9.2");
|
|
|
|
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
|
Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
|
|
|
|
run_next_test();
|
|
}
|
|
|
|
add_task(function* test_sendTimeout() {
|
|
const TIMEOUT = 100;
|
|
// Enable testing mode for AsyncShutdown, otherwise some testing-only functionality
|
|
// is not available.
|
|
Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
|
|
Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", TIMEOUT);
|
|
|
|
let httpServer = new HttpServer();
|
|
httpServer.registerPrefixHandler("/", contentHandler);
|
|
httpServer.start(-1);
|
|
|
|
yield TelemetryController.setup();
|
|
TelemetrySend.setServer("http://localhost:" + httpServer.identity.primaryPort);
|
|
let submissionPromise = TelemetryController.submitExternalPing("test-ping-type", {});
|
|
|
|
// Trigger the AsyncShutdown phase TelemetryController hangs off.
|
|
AsyncShutdown.profileBeforeChange._trigger();
|
|
AsyncShutdown.sendTelemetry._trigger();
|
|
// Now wait for the ping submission.
|
|
yield submissionPromise;
|
|
|
|
// If we get here, we didn't time out in the shutdown routines.
|
|
Assert.ok(true, "Didn't time out on shutdown.");
|
|
});
|