Skip to content

Commit

Permalink
HTML/events/beforeunload - respect preventDefault().
Browse files Browse the repository at this point in the history
An existing web-platform-test was enhanced to make sure
the preventDefault only (or combined) cases work.

Added many layout tests (due to the lack of
web-platform-tests APIs for handling beforeunload alert)
for most of the intricacies of beforeunload.

Bug: 866818
Change-Id: I35c27cee1f71a4e4d10331d3451e0a36b9db684d
  • Loading branch information
phistuck authored and Chrome-bot committed Oct 1, 2018
1 parent f95086e commit 68f85b6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ <h1>If this goes away, it navigated</h1>
<script>
"use strict";

window.runTest = (t, { valueToReturn, expectCancelation, setReturnValue, expectedReturnValue }) => {
window.runTest = (t, { valueToReturn, expectCancelation, setReturnValue, expectedReturnValue, cancel }) => {
window.onbeforeunload = t.step_func(e => {
if (cancel) {
e.preventDefault();
}

if (setReturnValue !== undefined) {
e.returnValue = setReturnValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@
expectCancelation: true,
setReturnValue: "foo",
expectedReturnValue: "foo"
},
{
expectCancelation: true,
cancel: true,
expectedReturnValue: ""
},
{
setReturnValue: "foo",
expectCancelation: true,
expectedReturnValue: "foo",
cancel: true
},
{
valueToReturn: "foo",
expectedReturnValue: "foo",
expectCancelation: true,
cancel: true
},
{
valueToReturn: "foo",
setReturnValue: "foo",
expectedReturnValue: "foo",
expectCancelation: true,
cancel: true
},
{
valueToReturn: true,
setReturnValue: "",
expectedReturnValue: "true",
expectCancelation: true,
cancel: true
}
];

Expand All @@ -164,6 +195,11 @@
const labelAboutReturnValue = testCase.setReturnValue === undefined ? "" :
`; setting returnValue to ${testCase.setReturnValue}`;

const labelAboutCancel = testCase.cancel === undefined ? "" :
"; calling preventDefault()";

const suffixLabels = labelAboutReturnValue + labelAboutCancel;

async_test(t => {
const iframe = document.createElement("iframe");
iframe.onload = t.step_func(() => {
Expand All @@ -174,7 +210,7 @@

iframe.src = "beforeunload-canceling-1.html";
document.body.appendChild(iframe);
}, `Returning ${testCase.valueToReturn} with a real iframe unloading${labelAboutReturnValue}`);
}, `Returning ${testCase.valueToReturn} with a real iframe unloading${suffixLabels}`);
}

runNextTest();
Expand Down

0 comments on commit 68f85b6

Please sign in to comment.