Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/the-selectlist-element/selectlist-form-state-restore.tentative.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html lang="en">
<title>HTMLSelectListElement Test: form state restore</title>
<link rel="author" title="Ionel Popescu" href="mailto:iopopesc@microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<input id="emptyOnFirstVisit">
<form action="support/back.html" id="form0">
<selectlist id="selectlist0">
<option>one</option>
<option>two</option>
<option>three</option>
</selectlist>
</form>
<script>
async_test(t => {
window.onload = () => t.step_timeout(() => {
let state = document.getElementById('emptyOnFirstVisit');
let selectList = document.getElementById("selectlist0");
if (!state.value) {
// First visit.
t.step_timeout(() => {
state.value = 'visited';
assert_equals(selectList.value, "one");
selectList.value = "two";
// The form is submitted in a timeout to make sure that a new back/forward list item is created.
document.getElementById('form0').submit();
}, 0);
} else {
// Went back to this page again, and the form state should be restored.
assert_equals(selectList.value, "two");
t.done();
}
}, 1);
}, "Test restoring state after form submission");
</script>