Bug 931746 - Make sure all mozbrowser mm are in the target chain. r=smaug

---
 dom/base/nsGlobalWindow.cpp                        |    8 ++
 dom/base/test/file_empty.html                      |    1 +
 dom/base/test/mochitest.ini                        |    2 +
 dom/base/test/test_messagemanager_targetchain.html |  129 ++++++++++++++++++++
 4 files changed, 140 insertions(+)
 create mode 100644 dom/base/test/file_empty.html
 create mode 100644 dom/base/test/test_messagemanager_targetchain.html
This commit is contained in:
"Kan-Ru Chen (陳侃如)" 2013-11-17 01:07:24 +08:00
Родитель 7733fae85f
Коммит c84cf40ea7
4 изменённых файлов: 140 добавлений и 0 удалений

Просмотреть файл

@ -2850,6 +2850,14 @@ nsGlobalWindow::UpdateParentTarget()
nsCOMPtr<EventTarget> eventTarget =
TryGetTabChildGlobalAsEventTarget(frameElement);
if (!eventTarget) {
nsGlobalWindow* topWin = GetScriptableTop();
if (topWin) {
frameElement = topWin->GetFrameElementInternal();
eventTarget = TryGetTabChildGlobalAsEventTarget(frameElement);
}
}
if (!eventTarget) {
eventTarget = TryGetTabChildGlobalAsEventTarget(mChromeEventHandler);
}

Просмотреть файл

@ -0,0 +1 @@
<!DOCTYPE html><html><body></body></html>

Просмотреть файл

@ -3,6 +3,7 @@ support-files =
iframe_messageChannel_cloning.html
iframe_messageChannel_pingpong.html
iframe_messageChannel_post.html
file_empty.html
[test_Image_constructor.html]
[test_bug913761.html]
@ -37,3 +38,4 @@ support-files =
[test_writable-replaceable.html]
[test_urlExceptions.html]
[test_openDialogChromeOnly.html]
[test_messagemanager_targetchain.html]

Просмотреть файл

@ -0,0 +1,129 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for EventTarget chain of MessageManagers</title>
<script type="application/javascript"
src="/tests/SimpleTest/SimpleTest.js">
</script>
<script type="application/javascript"
src="/tests/SimpleTest/EventUtils.js">
</script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7">
"use strict";
SimpleTest.waitForExplicitFinish();
const browserFrameURL = "file_empty.html";
const contentFrameURL =
"data:text/html,<!DOCTYPE HTML><html><body><button id=\"target\">target</button></body></html>";
function frameScript() {
"use strict";
addEventListener("test-event", function (e) {
sendSyncMessage("test-event");
}, true);
}
function runTests() {
// messageIndex is incremented for each message/event received
let messageIndex = 0;
let iframe = document.createElement("iframe");
iframe.setAttribute("mozbrowser", true);
iframe.setAttribute("src", browserFrameURL);
iframe.addEventListener("mozbrowserloadend", function () {
info("First iframe loaded");
// First message manager
let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
mm.addMessageListener("test-event", function onEvent(message) {
is(messageIndex, 0,
"first mm should be the first one to receive the test event");
messageIndex++;
});
mm.loadFrameScript("data:,(" + frameScript.toString() + ")();", false);
// Document in the middle
let doc1 = SpecialPowers.wrap(iframe).contentDocument;
doc1.addEventListener("test-event", function (e) {
ok(false, "content document shouldn't receive test event from child");
}, true);
let iframe2 = doc1.createElement("iframe");
iframe2.setAttribute("mozbrowser", true);
iframe2.setAttribute("src", browserFrameURL);
iframe2.addEventListener("mozbrowserloadend", function () {
info("Second iframe loaded");
// Second message manager
let mm2 = SpecialPowers.getBrowserFrameMessageManager(iframe2);
mm2.addMessageListener("test-event", function onEvent(message) {
is(messageIndex, 1,
"second mm should be the second one to receive the test event");
messageIndex++;
});
mm2.loadFrameScript("data:,(" + frameScript.toString() +")();", false);
// Third is the regular iframe
let doc2 = SpecialPowers.wrap(iframe2).contentDocument;
let iframe3 = doc2.createElement("iframe");
iframe3.setAttribute("src", contentFrameURL);
iframe3.addEventListener("load", function (e) {
info("Third iframe loaded");
let doc3 = SpecialPowers.wrap(iframe3).contentDocument;
let target = doc3.getElementById("target");
target.addEventListener("test-event", function onEvent(e) {
is(messageIndex, 2,
"target should be the last one to receive the test event");
messageIndex++;
SimpleTest.finish();
});
// Fire test event after load
SimpleTest.executeSoon(function () {
var event = new Event("test-event");
SpecialPowers.dispatchEvent(iframe3.contentWindow, target, event);
});
});
doc2.body.appendChild(iframe3);
});
doc1.body.appendChild(iframe2);
});
document.addEventListener("test-event", function (e) {
ok(false, "top document shouldn't receive test event from child");
}, true);
document.body.appendChild(iframe);
}
addEventListener("load", function() {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: false });
SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
SpecialPowers.pushPrefEnv({
"set": [
["dom.mozBrowserFramesEnabled", true],
["dom.ipc.browser_frames.oop_by_default", false],
]
}, runTests);
});
SimpleTest.registerCleanupFunction(function () {
var principal = SpecialPowers.wrap(document).nodePrincipal;
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: false });
SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
appId: principal.appId,
isInBrowserElement: true });
});
</script>
</body>
</html>