forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App history: fix event.formData to be POST-only, plus tests
* event.formData is only supposed to be populated for POST form submissions. Fix that and update tests accordingly. * A number of tests were using e.preventDefault() after all the asserts. This was subpar because if the asserts failed the event would not be prevented, i.e. we would leave the test page. Put the e.preventDefault() first. * Test that event.formData does not appear for "traverse" or "reload" navigations even if the session history entry contains form data Fixed: 1233710 Bug: 1183545 Change-Id: Ibc6307a9a8629df769c2eeae19b2d332af77843b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3076282 Commit-Queue: Domenic Denicola <[email protected]> Reviewed-by: Nate Chapin <[email protected]> Reviewed-by: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/master@{#909507}
- Loading branch information
1 parent
59d525c
commit bd68e11
Showing
6 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<form id="form" action=""></form> | ||
<script> | ||
async_test(t => { | ||
appHistory.onnavigate = t.step_func_done(e => { | ||
e.preventDefault(); | ||
|
||
assert_equals(e.navigationType, "replace"); | ||
assert_true(e.cancelable); | ||
assert_true(e.canRespond); | ||
assert_false(e.userInitiated); | ||
assert_false(e.hashChange); | ||
assert_equals(e.destination.url, location.href + "?"); | ||
assert_false(e.destination.sameDocument); | ||
assert_equals(e.destination.key, null); | ||
assert_equals(e.destination.id, null); | ||
assert_equals(e.destination.index, -1); | ||
|
||
// Because it's a GET, not a POST | ||
assert_equals(e.formData, null); | ||
}); | ||
window.onload = t.step_func(() => form.submit()); | ||
}, "<form> submission with GET method fires navigate event but with formData null"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<iframe id="iframe" name="i" src="/common/blank.html"></iframe> | ||
<form id="form" action="/common/blank.html?1" method="post" target="i"></form> | ||
<script> | ||
async_test(t => { | ||
window.onload = t.step_func(() => { | ||
appHistory.onnavigate = t.step_func_done(() => { | ||
assert_unreached("onnavigate should not have fired in source window"); | ||
}); | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func(e => { | ||
assert_equals(e.navigationType, "push"); | ||
assert_not_equals(e.formData, null); | ||
|
||
iframe.onload = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "reload"); | ||
assert_equals(e.formData, null); | ||
}); | ||
|
||
iframe.contentWindow.location.reload(); | ||
}); | ||
}); | ||
form.submit(); | ||
}); | ||
}, "reloading a page created from form submission results in formData of null, not the original form data"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<iframe id="iframe" name="i" src="/common/blank.html"></iframe> | ||
<form id="form" action="/common/blank.html?1" method="post" target="i"></form> | ||
<script> | ||
async_test(t => { | ||
window.onload = t.step_func(() => { | ||
appHistory.onnavigate = t.step_func_done(() => { | ||
assert_unreached("onnavigate should not have fired in source window"); | ||
}); | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func(e => { | ||
assert_equals(e.navigationType, "push"); | ||
assert_not_equals(e.formData, null); | ||
|
||
iframe.onload = t.step_func(() => { | ||
// Avoid the replace behavior that occurs if you navigate during the load handler | ||
t.step_timeout(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func(e => { | ||
assert_equals(e.navigationType, "push"); | ||
assert_equals(e.formData, null); | ||
}); | ||
|
||
iframe.contentWindow.onhashchange = t.step_func(() => { | ||
iframe.contentWindow.appHistory.onnavigate = t.step_func_done(e => { | ||
assert_equals(e.navigationType, "traverse"); | ||
assert_equals(e.formData, null); | ||
}); | ||
|
||
// 3: go back | ||
iframe.contentWindow.history.back(); | ||
}); | ||
|
||
// 2: navigate from /common/blank.html?1-with-form-data to /common/blank.html?1#1-with-form-data | ||
iframe.contentWindow.location.hash = "#1"; | ||
}, 0); | ||
}); | ||
}); | ||
|
||
// 1: submit the form, navigating from /common/blank.html to /common/blank.html?1-with-form-data | ||
form.submit(); | ||
}); | ||
}, "reloading a page created from form submission results in formData of null, not the original form data"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters