Skip to content

Commit

Permalink
Portals: Add a WindowEventHandler to the PortalActivateEvent.
Browse files Browse the repository at this point in the history
Bug: 914122
Change-Id: Ie1817a21216d86f59a708accea43e1d1ef316d6c
Reviewed-on: https://chromium-review.googlesource.com/c/1412794
Commit-Queue: Lucas Gadani <[email protected]>
Reviewed-by: Jeremy Roman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#623445}
  • Loading branch information
lucasgadani authored and chromium-wpt-export-bot committed Jan 17, 2019
1 parent 584bdfa commit 2ade7dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
22 changes: 20 additions & 2 deletions portals/portal-activate-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var bc = new BroadcastChannel("test");
var bc = new BroadcastChannel("test-eventlistener");
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html");
window.open("resources/portal-activate-event-window.html?test=eventlistener");
}, "Tests that the PortalActivateEvent is dispatched when a portal is activated.");

async_test(function(t) {
var bc = new BroadcastChannel("test-eventhandler");
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html?test=eventhandler");
}, "Tests that the portalactivate event handler is dispatched when a portal is activated.");

async_test(function(t) {
var bc = new BroadcastChannel("test-bodyeventhandler");
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html?test=bodyeventhandler");
}, "Tests that the HTMLBodyElement has the portalactivate event handler.");
</script>
18 changes: 14 additions & 4 deletions portals/resources/portal-activate-event-portal.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<!DOCTYPE html>
<title>Tests that the PortalActivateEvent is dispatched when a portal is activated</title>
<script>
window.addEventListener("portalactivate", function(e) {
var bc = new BroadcastChannel("test");
var test = (new URL(location)).searchParams.get("test");

function portalActivate(e) {
var bc = new BroadcastChannel("test-" + test);
bc.postMessage("passed");
bc.close();
});
}

if (test == "bodyeventhandler") {
document.write('<body onportalactivate="portalActivate()"></body>');
} else if (test == "eventhandler") {
window.onportalactivate = portalActivate;
} else if (test == "eventlistener") {
window.addEventListener("portalactivate", portalActivate);
}

var bc = new BroadcastChannel("portal");
var bc = new BroadcastChannel("portal-" + test);
bc.postMessage("loaded");
bc.close();
</script>
16 changes: 11 additions & 5 deletions portals/resources/portal-activate-event-window.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<!DOCTYPE html>
<script>
var bc = new BroadcastChannel("portal");
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
window.onload = function(e) {
var test = (new URL(location)).searchParams.get("test");
var portal = document.createElement("portal");
portal.src = "portal-activate-event-portal.html" + location.search;
document.body.appendChild(portal);

var bc = new BroadcastChannel("portal-" + test);
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
}
}
</script>
<body>
<portal src="portal-activate-event-portal.html"></portal>
</body>

0 comments on commit 2ade7dc

Please sign in to comment.