summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/navigation-api/navigate-event/navigate-form-requestSubmit.html
blob: 38dd9c7eee649f3f7d8e54e446ceb83fc48d3a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<form id="form" method="post" action="">
<input type="submit" id="submit1">
<input type="image" id="submit2">
<button type="submit" id="submit3">
</form>
<script>
promise_test(async () => {
  await new Promise(r => window.onload = r);

  let sourceElement;
  navigation.onnavigate = e => {
    e.preventDefault();
    sourceElement = e.sourceElement;
  };

  form.requestSubmit(submit1);
  await new Promise(r => navigation.onnavigateerror = r);
  assert_equals(sourceElement, submit1);

  form.requestSubmit(submit2);
  await new Promise(r => navigation.onnavigateerror = r);
  assert_equals(sourceElement, submit2);

  form.requestSubmit(submit3);
  await new Promise(r => navigation.onnavigateerror = r);
  assert_equals(sourceElement, submit3);

  form.requestSubmit();
  await new Promise(r => navigation.onnavigateerror = r);
  assert_equals(sourceElement, form);
}, "<form> requestSubmit() sets sourceElement");
</script>