mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1644992 - Report an error for non-window topic observed by JSWindowActorProtocol, r=kmag
Differential Revision: https://phabricator.services.mozilla.com/D88652
This commit is contained in:
parent
434ac213b9
commit
c965e9c886
@ -205,7 +205,17 @@ NS_IMETHODIMP JSWindowActorProtocol::Observe(nsISupports* aSubject,
|
||||
|
||||
if (!inner) {
|
||||
nsCOMPtr<nsPIDOMWindowOuter> outer = do_QueryInterface(aSubject);
|
||||
if (NS_WARN_IF(!outer) || NS_WARN_IF(!outer->GetCurrentInnerWindow())) {
|
||||
if (NS_WARN_IF(!outer)) {
|
||||
nsContentUtils::LogSimpleConsoleError(
|
||||
NS_ConvertUTF8toUTF16(nsPrintfCString(
|
||||
"JSWindowActor %s: expected window subject for topic '%s'.",
|
||||
mName.get(), aTopic)),
|
||||
"JSActor",
|
||||
/* aFromPrivateWindow */ false,
|
||||
/* aFromChromeContext */ true);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (NS_WARN_IF(!outer->GetCurrentInnerWindow())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
wgc = outer->GetCurrentInnerWindow()->GetWindowGlobalChild();
|
||||
|
@ -49,6 +49,25 @@ declTest("test observers with null data", {
|
||||
|
||||
declTest("observers don't notify with wrong window", {
|
||||
async test(browser) {
|
||||
const MSG_RE = /JSWindowActor TestWindow: expected window subject for topic 'test-js-window-actor-child-observer'/;
|
||||
let expectMessage = new Promise(resolve => {
|
||||
Services.console.registerListener(function consoleListener(msg) {
|
||||
// Run everything async in order to avoid logging messages from the
|
||||
// console listener.
|
||||
Cu.dispatch(() => {
|
||||
if (!MSG_RE.test(msg.message)) {
|
||||
info("ignoring non-matching console message: " + msg.message);
|
||||
return;
|
||||
}
|
||||
info("received console message: " + msg.message);
|
||||
is(msg.logLevel, Ci.nsIConsoleMessage.error, "should be an error");
|
||||
|
||||
Services.console.unregisterListener(consoleListener);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await SpecialPowers.spawn(browser, [], async function() {
|
||||
const TOPIC = "test-js-window-actor-child-observer";
|
||||
Services.obs.notifyObservers(null, TOPIC);
|
||||
@ -61,6 +80,8 @@ declTest("observers don't notify with wrong window", {
|
||||
"Should not receive wrong window's observer notification!"
|
||||
);
|
||||
});
|
||||
|
||||
await expectMessage;
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user