Bug 291653, make window level listeners work consistently with other listeners, r=jst

This commit is contained in:
Olli Pettay 2011-10-26 14:49:37 +03:00
parent 647fb4ba20
commit 36bfe69f46
4 changed files with 88 additions and 3 deletions

View File

@ -7462,9 +7462,18 @@ nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
nsIScriptContext*
nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv)
{
nsIScriptContext* scx = GetContext();
*aRv = scx ? NS_OK : NS_ERROR_UNEXPECTED;
*aRv = NS_ERROR_UNEXPECTED;
if (IsInnerWindow()) {
nsPIDOMWindow* outer = GetOuterWindow();
NS_ENSURE_TRUE(outer && outer->GetCurrentInnerWindow() == this, nsnull);
}
nsIScriptContext* scx;
if ((scx = GetContext())) {
*aRv = NS_OK;
return scx;
}
return nsnull;
}
//*****************************************************************************

View File

@ -52,6 +52,8 @@ _TEST_FILES = \
test_bug159849.html \
test_bug265203.html \
test_bug291377.html \
file_bug291653.html \
test_bug291653.html \
test_bug308856.html \
test_bug317448.html \
test_bug327891.html \

View File

@ -0,0 +1,28 @@
<html>
<head>
<script>
<!--
function listener1() {
window.showModalDialog("data:text/html,<script>var maintest = opener.opener; opener.location = 'data:text/html,test'; maintest.end(); window.close();</script>");
}
function listener2() {
opener.secondListenerDidRun = true;
}
window.addEventListener("foo", listener1);
window.addEventListener("foo", listener2);
function fireFoo() {
var e = document.createEvent("Events");
e.initEvent("foo", true, true);
window.dispatchEvent(e);
}
//-->
</script>
</head>
<body onload="setTimeout(fireFoo, 0)">
Test for bug 291653
</body>
</html>

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=291653
-->
<head>
<title>Test for Bug 291653</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291653">Mozilla Bug 291653</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 291653 **/
SimpleTest.waitForExplicitFinish();
var secondListenerDidRun = false;
var w = window.open("file_bug291653.html", "foo", "width=300,height=300");
function closeTest() {
w.setTimeout("close()", 0);
setTimeout("finish()", 500);
}
function finish() {
ok(!secondListenerDidRun, "Shouldn't have run second listener!");
SimpleTest.finish();
}
function end() {
setTimeout("closeTest()", 500);
}
</script>
</pre>
</body>
</html>