Backed out changeset 03cae7800b41 (bug 1678330) for mochitest plain failures on test_window_open_discarded_bc.html. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2021-03-02 20:18:21 +02:00
parent 1c9566c96e
commit b2eb620ed0
35 changed files with 56 additions and 194 deletions

View File

@ -754,10 +754,7 @@ var MigrationUtils = Object.seal({
done = true;
});
Services.tm.spinEventLoopUntil(
"MigrationUtils.jsm:MU_spinResolve",
() => done || gForceExitSpinResolve
);
Services.tm.spinEventLoopUntil(() => done || gForceExitSpinResolve);
if (!done) {
throw new Error("Forcefully exited event loop.");
} else if (error) {

View File

@ -507,12 +507,9 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
// up; no reason to continue executing the slow script.
const utils = window.windowUtils;
utils.enterModalState();
Services.tm.spinEventLoopUntil(
"devtools-browser.js:debugService.activationHandler",
() => {
return setupFinished;
}
);
Services.tm.spinEventLoopUntil(() => {
return setupFinished;
});
utils.leaveModalState();
};

View File

@ -121,10 +121,7 @@ function force_microtask_checkpoint() {
Services.tm.dispatchToMainThread(() => {
ran = true;
});
Services.tm.spinEventLoopUntil(
"Test(test_promises_run_to_completion.js:force_microtask_checkpoint)",
() => ran
);
Services.tm.spinEventLoopUntil(() => ran);
}
add_test(test_promises_run_to_completion);

View File

@ -1082,7 +1082,7 @@ DevToolsStartup.prototype = {
if (pauseOnStartup) {
// Spin the event loop until the debugger connects.
const tm = Cc["@mozilla.org/thread-manager;1"].getService();
tm.spinEventLoopUntil("DevToolsStartup.jsm:handleDebuggerFlag", () => {
tm.spinEventLoopUntil(() => {
return devtoolsThreadResumed;
});
}

View File

@ -26,12 +26,9 @@ async function setTestPluginEnabledState(newEnabledState, pluginName) {
var plugin = getTestPlugin(pluginName);
// Run a nested event loop to wait for the preference change to
// propagate to the child. Yuck!
SpecialPowers.Services.tm.spinEventLoopUntil(
"Test(plugin.js->setTestPluginEnabledState)",
() => {
return plugin.enabledState == newEnabledState;
}
);
SpecialPowers.Services.tm.spinEventLoopUntil(() => {
return plugin.enabledState == newEnabledState;
});
SimpleTest.registerCleanupFunction(function() {
return SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
});

View File

@ -201,23 +201,20 @@ BrowserElementChild.prototype = {
let origModalDepth = win.modalDepth;
debug("Nested event loop - begin");
Services.tm.spinEventLoopUntil(
"BrowserElementChildPreload.js:_waitForResult",
() => {
// Bail out of the loop if the inner window changed; that means the
// window navigated. Bail out when we're shutting down because otherwise
// we'll leak our window.
if (this._tryGetInnerWindowID(win) !== innerWindowID) {
debug(
"_waitForResult: Inner window ID changed " +
"while in nested event loop."
);
return true;
}
return win.modalDepth !== origModalDepth || this._shuttingDown;
Services.tm.spinEventLoopUntil(() => {
// Bail out of the loop if the inner window changed; that means the
// window navigated. Bail out when we're shutting down because otherwise
// we'll leak our window.
if (this._tryGetInnerWindowID(win) !== innerWindowID) {
debug(
"_waitForResult: Inner window ID changed " +
"while in nested event loop."
);
return true;
}
);
return win.modalDepth !== origModalDepth || this._shuttingDown;
});
debug("Nested event loop - finish");
if (win.modalDepth == 0) {

View File

@ -37,10 +37,7 @@ function* testSteps() {
transaction2 = db.transaction("foo");
});
tm.spinEventLoopUntil(
"Test(test_transaction_lifetimes_nested.js:testSteps)",
() => eventHasRun
);
tm.spinEventLoopUntil(() => eventHasRun);
ok(transaction2, "Non-null transaction2");

View File

@ -124,10 +124,7 @@ function setTestPluginEnabledState(aState, aPluginName) {
SpecialPowers.setTestPluginEnabledState(aState, name).then(() => {
resolved = true;
});
SpecialPowers.Services.tm.spinEventLoopUntil(
"Test(head.js:setTestPluginEnabledState)",
() => resolved
);
SpecialPowers.Services.tm.spinEventLoopUntil(() => resolved);
}
/**

View File

@ -42,12 +42,9 @@ function setTestPluginEnabledState(newEnabledState, pluginName) {
var plugin = getTestPlugin(pluginName);
// Run a nested event loop to wait for the preference change to
// propagate to the child. Yuck!
SpecialPowers.Services.tm.spinEventLoopUntil(
"Test(plugin-utils.js:setTestPluginEnabledState",
() => {
return plugin.enabledState == newEnabledState;
}
);
SpecialPowers.Services.tm.spinEventLoopUntil(() => {
return plugin.enabledState == newEnabledState;
});
SimpleTest.registerCleanupFunction(async function() {
return SpecialPowers.setTestPluginEnabledState(
await oldEnabledState,

View File

@ -86,7 +86,6 @@ class GeckoViewPrompter {
// Spin this thread while we wait for a result
Services.tm.spinEventLoopUntil(
"GeckoViewPrompter.jsm:showPrompt",
() => this._domWin.closed || result !== undefined
);
} finally {

View File

@ -363,7 +363,6 @@ class GeckoViewNavigation extends GeckoViewModule {
// Wait indefinitely for app to respond with a browser or null
Services.tm.spinEventLoopUntil(
"GeckoViewNavigation.jsm:handleNewSession",
() => this.window.closed || browser !== undefined
);
return browser || null;

View File

@ -52,7 +52,6 @@ const LoadURIDelegate = {
}
);
Services.tm.spinEventLoopUntil(
"LoadURIDelegate.jsm:load",
() => aWindow.closed || handled !== undefined
);
@ -93,7 +92,6 @@ const LoadURIDelegate = {
}
);
Services.tm.spinEventLoopUntil(
"LoadURIDelegate.jsm:handleLoadError",
() => aWindow.closed || errorPageURI !== undefined
);

View File

@ -52,10 +52,7 @@ function promiseSpinningly(promise) {
let tm = Cc["@mozilla.org/thread-manager;1"].getService();
// Keep waiting until the promise resolves.
tm.spinEventLoopUntil(
"Test(test_bookmark_tracker.js:promiseSpinningly)",
() => resolved
);
tm.spinEventLoopUntil(() => resolved);
if (rerror) {
throw rerror;
}

View File

@ -94,7 +94,7 @@ function asyncCleanup() {
});
let tm = Cc["@mozilla.org/thread-manager;1"].getService();
tm.spinEventLoopUntil("Test(head_storage.js:asyncCleanup)", () => closed);
tm.spinEventLoopUntil(() => closed);
// we need to null out the database variable to get a new connection the next
// time getOpenedDatabase is called

View File

@ -168,10 +168,7 @@ function execAsync(aStmt, aOptions, aResults) {
pending.cancel();
}
Services.tm.spinEventLoopUntil(
"Test(test_statement_executeAsync.js:execAsync)",
() => completed || _quit
);
Services.tm.spinEventLoopUntil(() => completed || _quit);
return pending;
}

View File

@ -297,10 +297,7 @@ function spinResolve(promise) {
done = true;
});
Services.tm.spinEventLoopUntil(
"getHSTSPreloadList.js:spinResolve",
() => done
);
Services.tm.spinEventLoopUntil(() => done);
if (error) {
throw error;
} else {

View File

@ -236,7 +236,7 @@ function _do_main() {
var tm = Cc["@mozilla.org/thread-manager;1"].getService();
tm.spinEventLoopUntil("Test(xpcshell/head.js:_do_main)", () => _quit);
tm.spinEventLoopUntil(() => _quit);
tm.spinEventLoopUntilEmpty();
}
@ -489,7 +489,7 @@ function _initDebugging(port) {
// spin an event loop until the debugger connects.
const tm = Cc["@mozilla.org/thread-manager;1"].getService();
tm.spinEventLoopUntil("Test(xpcshell/head.js:_initDebugging)", () => {
tm.spinEventLoopUntil(() => {
if (initialized) {
return true;
}
@ -640,10 +640,7 @@ function _execute_test() {
})()
.catch(reportCleanupError)
.then(() => (complete = true));
_Services.tm.spinEventLoopUntil(
"Test(xpcshel/head.js:_execute_test)",
() => complete
);
_Services.tm.spinEventLoopUntil(() => complete);
if (cleanupStartTime) {
ChromeUtils.addProfilerMarker(
"xpcshell-test",
@ -1719,10 +1716,7 @@ try {
);
complete = true;
});
_Services.tm.spinEventLoopUntil(
"Test(xpcshell/head.js:run_next-Test)",
() => complete
);
_Services.tm.spinEventLoopUntil(() => complete);
}
} catch (e) {
do_throw(e);

View File

@ -1062,10 +1062,7 @@ class ModalPrompter {
.finally(() => {
closed = true;
});
Services.tm.spinEventLoopUntilOrShutdown(
"prompts/Prompter.jsm:openPromptSync",
() => closed
);
Services.tm.spinEventLoopUntilOrShutdown(() => closed);
}
async openPrompt(args) {

View File

@ -402,10 +402,7 @@ function PrompterProxy(chromeScript) {
.then(val => {
result = val;
});
SpecialPowers.Services.tm.spinEventLoopUntil(
"Test(prompt_common.js:get)",
() => result
);
SpecialPowers.Services.tm.spinEventLoopUntil(() => result);
for (let outParam of outParams) {
// Copy the out or inout param value over the original

View File

@ -165,12 +165,9 @@ async function setTestPluginEnabledState(newEnabledState, pluginName) {
var plugin = getTestPlugin(pluginName);
// Run a nested event loop to wait for the preference change to
// propagate to the child. Yuck!
SpecialPowers.Services.tm.spinEventLoopUntil(
"Test(browser/head.js:setTestPluginEnabledState)",
() => {
return plugin.enabledState == newEnabledState;
}
);
SpecialPowers.Services.tm.spinEventLoopUntil(() => {
return plugin.enabledState == newEnabledState;
});
SimpleTest.registerCleanupFunction(function() {
return SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
});

View File

@ -1714,7 +1714,6 @@
// callbacks after the browser window the promise lives in has closed,
// so we have to check for that case explicitly.
Services.tm.spinEventLoopUntilOrShutdown(
"browser-custom-element.js:permitUnload",
() => window.closed || success !== undefined
);
if (success) {

View File

@ -977,10 +977,3 @@ Winsock_LSP:
description: >
Information on winsock LSPs injected in our networking stack.
type: string
XPCOMSpinEventLoopStack:
description: >
If we crash while some code is spinning manually the event
loop, we will see the stack of nested annotations here.
type: string

View File

@ -10,10 +10,7 @@ if (shouldDelay) {
},
});
Services.tm.spinEventLoopUntil(
"Test(crasher_subprocess_tail.js:shouldDelay)",
() => shouldCrashNow
);
Services.tm.spinEventLoopUntil(() => shouldCrashNow);
}
// now actually crash

View File

@ -27,10 +27,7 @@ function setup_crash() {
terminator.observe(null, "terminator-test-xpcom-will-shutdown", null);
dump("Waiting (actively) for the crash\n");
Services.tm.spinEventLoopUntil(
"Test(test_crash_terminator.js:setup_crash())",
() => false
);
Services.tm.spinEventLoopUntil(() => false);
}
function after_crash(mdump, extra) {

View File

@ -56,7 +56,7 @@ var FirstStartup = {
);
this.elapsed = 0;
Services.tm.spinEventLoopUntil("FirstStartup.jsm:init", () => {
Services.tm.spinEventLoopUntil(() => {
this.elapsed = Date.now() - startingTime;
if (this.elapsed >= timeout) {
this._state = this.TIMED_OUT;

View File

@ -128,10 +128,7 @@ var PromiseTestUtils = {
PromiseDebugging.addUncaughtRejectionObserver(observer);
Promise.reject(this._ensureDOMPromiseRejectionsProcessedReason);
Services.tm.spinEventLoopUntil(
"Test(PromiseTestUtils.jsm:ensureDOMPromiseRejectionsProcessed)",
() => observed
);
Services.tm.spinEventLoopUntil(() => observed);
PromiseDebugging.removeUncaughtRejectionObserver(observer);
},
_ensureDOMPromiseRejectionsProcessedReason: {},

View File

@ -982,10 +982,7 @@ tests.push(
let shouldExitNestedEventLoop = false;
function event_loop() {
Services.tm.spinEventLoopUntil(
"Test(test_Promise.js:make_promise_test)",
() => shouldExitNestedEventLoop
);
Services.tm.spinEventLoopUntil(() => shouldExitNestedEventLoop);
}
// I wish there was a way to cancel xpcshell do_timeout()s

View File

@ -212,10 +212,7 @@ function awaitPromise(promise) {
}
);
Services.tm.spinEventLoopUntil(
"XPIProvider.jsm:awaitPromise",
() => success !== undefined
);
Services.tm.spinEventLoopUntil(() => success !== undefined);
if (!success) {
throw result;

View File

@ -56,10 +56,7 @@ function awaitPromise(promise) {
ret = v;
complete = true;
});
Services.tm.spinEventLoopUntil(
"PerTestCoverageUtils.jsm:awaitPromise",
() => complete
);
Services.tm.spinEventLoopUntil(() => complete);
if (error) {
throw new Error(error);
}

View File

@ -2,11 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate nsstring;
use cstr::cstr;
use nserror::{nsresult, NS_ERROR_SERVICE_NOT_AVAILABLE, NS_OK};
use nsstring::*;
use std::cell::UnsafeCell;
use xpcom::{interfaces::nsIThreadManager, xpcom, xpcom_method};
@ -48,11 +45,5 @@ where
xpcom::get_service::<nsIThreadManager>(cstr!("@mozilla.org/thread-manager;1"))
.ok_or(NS_ERROR_SERVICE_NOT_AVAILABLE)?;
// XXX: Pass in aVeryGoodReason from caller
thread_manager
.SpinEventLoopUntil(
&*nsCStr::from("event_loop.rs: Rust is spinning the event loop."),
cond.coerce(),
)
.to_result()
thread_manager.SpinEventLoopUntil(cond.coerce()).to_result()
}

View File

@ -45,9 +45,7 @@ class SpinRunnable final : public Runnable {
NS_IMETHODIMP Run() {
nsCOMPtr<nsIThreadManager> threadMan =
do_GetService("@mozilla.org/thread-manager;1");
mResult = threadMan->SpinEventLoopUntil(
"gtest TestThreadManager.cpp: SpinRunnable->Run()"_ns, mCondition);
mResult = threadMan->SpinEventLoopUntil(mCondition);
return NS_OK;
}

View File

@ -22,8 +22,5 @@ function run_test() {
};
Services.tm.dispatchToMainThread(runnable);
Services.tm.spinEventLoopUntil(
"Test(test_bug1434856.js:run_test)",
() => complete
);
Services.tm.spinEventLoopUntil(() => complete);
}

View File

@ -130,7 +130,7 @@ interface nsIThreadManager : nsISupports
* C++ code should not use this function, instead preferring
* mozilla::SpinEventLoopUntil.
*/
void spinEventLoopUntil(in ACString aVeryGoodReasonToDoThis, in nsINestedEventLoopCondition condition);
void spinEventLoopUntil(in nsINestedEventLoopCondition condition);
/**
* Similar to the previous method, but the spinning of the event loop
@ -139,7 +139,7 @@ interface nsIThreadManager : nsISupports
* C++ code should not use this function, instead preferring
* mozilla::SpinEventLoopUntil.
*/
void spinEventLoopUntilOrShutdown(in ACString aVeryGoodReasonToDoThis, in nsINestedEventLoopCondition condition);
void spinEventLoopUntilOrShutdown(in nsINestedEventLoopCondition condition);
/**
* Spin the current thread's event loop until there are no more pending

View File

@ -705,63 +705,18 @@ nsThreadManager::GetCurrentThread(nsIThread** aResult) {
}
NS_IMETHODIMP
nsThreadManager::SpinEventLoopUntil(const nsACString& aVeryGoodReasonToDoThis,
nsINestedEventLoopCondition* aCondition) {
return SpinEventLoopUntilInternal(aVeryGoodReasonToDoThis, aCondition, false);
nsThreadManager::SpinEventLoopUntil(nsINestedEventLoopCondition* aCondition) {
return SpinEventLoopUntilInternal(aCondition, false);
}
NS_IMETHODIMP
nsThreadManager::SpinEventLoopUntilOrShutdown(
const nsACString& aVeryGoodReasonToDoThis,
nsINestedEventLoopCondition* aCondition) {
return SpinEventLoopUntilInternal(aVeryGoodReasonToDoThis, aCondition, true);
return SpinEventLoopUntilInternal(aCondition, true);
}
struct MOZ_STACK_CLASS AutoNestedEventLoopAnnotation {
explicit AutoNestedEventLoopAnnotation(const nsACString& aEntry)
: mPrev(sCurrent) {
sCurrent = this;
if (mPrev) {
mStack = mPrev->mStack + "|"_ns + aEntry;
} else {
mStack = aEntry;
}
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::XPCOMSpinEventLoopStack, mStack);
}
~AutoNestedEventLoopAnnotation() {
MOZ_ASSERT(sCurrent == this);
sCurrent = mPrev;
if (mPrev) {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::XPCOMSpinEventLoopStack, mPrev->mStack);
} else {
CrashReporter::RemoveCrashReportAnnotation(
CrashReporter::Annotation::XPCOMSpinEventLoopStack);
}
}
private:
AutoNestedEventLoopAnnotation(const AutoNestedEventLoopAnnotation&) = delete;
AutoNestedEventLoopAnnotation& operator=(
const AutoNestedEventLoopAnnotation&) = delete;
static AutoNestedEventLoopAnnotation* sCurrent;
AutoNestedEventLoopAnnotation* mPrev;
nsCString mStack;
};
AutoNestedEventLoopAnnotation* AutoNestedEventLoopAnnotation::sCurrent =
nullptr;
nsresult nsThreadManager::SpinEventLoopUntilInternal(
const nsACString& aVeryGoodReasonToDoThis,
nsINestedEventLoopCondition* aCondition, bool aCheckingShutdown) {
AutoNestedEventLoopAnnotation annotation(aVeryGoodReasonToDoThis);
// XXX: We would want to AssertIsOnMainThread(); but that breaks some GTest.
nsCOMPtr<nsINestedEventLoopCondition> condition(aCondition);
nsresult rv = NS_OK;

View File

@ -82,8 +82,7 @@ class nsThreadManager : public nsIThreadManager {
private:
nsThreadManager();
nsresult SpinEventLoopUntilInternal(const nsACString& aVeryGoodReasonToDoThis,
nsINestedEventLoopCondition* aCondition,
nsresult SpinEventLoopUntilInternal(nsINestedEventLoopCondition* aCondition,
bool aCheckingShutdown);
static void ReleaseThread(void* aData);