summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/form-submission-0/form-double-submit-to-different-origin-frame.html
blob: 00a46bfd4326fc2d35d50bfc4a2f68890a5594bb (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:masonf@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>

<!-- The onclick submit() should get superseded by the default
     action submit(), which isn't preventDefaulted by onclick here.
     This is per the Form Submission Algorithm [1], step 22.3, which
     says that new planned navigations replace old planned navigations.
    [1] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm
  -->

<label for=frame1 style="display:block">This frame should stay blank</label>
<iframe name=frame1 id=frame1></iframe>
<label for=frame2 style="display:block">This frame should navigate (to 404)</label>
<iframe name=frame2 id=frame2></iframe>
<form id="form1" target="frame1" action="nonexistent.html">
  <input type=hidden name=navigated value=1>
  <input id=submitbutton type=submit>
</form>

<script>
promise_test(async () => {
  function getLoadPromise(frame) {
    return new Promise(resolve => {
      frame.addEventListener('load', resolve);
    });
  }

  const frame1 = document.getElementById('frame1');
  const frame2 = document.getElementById('frame2');
  await getLoadPromise(window);

  const frame1LoadPromise = getLoadPromise(frame1);
  let frame2LoadPromise = getLoadPromise(frame2);
  const subframeUrl = get_host_info().REMOTE_ORIGIN;
  frame1.src = subframeUrl;
  frame2.src = subframeUrl;
  await frame1LoadPromise;
  await frame2LoadPromise;
  assert_false(!!frame1.contentDocument, 'frame1 should have a different origin.');
  assert_false(!!frame2.contentDocument, 'frame2 should have a different origin.');

  window.frame1Navigated = false;
  frame1.addEventListener('load', () => {
    window.frame1Navigated = true;
  });
  frame2LoadPromise = getLoadPromise(frame2);

  form1.addEventListener('click', () => {
    form1.submit();
    form1.target = 'frame2';
  });
  submitbutton.click();
  await frame2LoadPromise;

  assert_false(window.frame1Navigated, 'frame1 should not be navigated by the form submission.');
}, 'default submit action should supersede onclick submit() for cross-origin iframes');

</script>