summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-submit-cross-frame-crossorigin.sub.html
blob: a2ea20bf7f77eaf08cb6c7420ed818f83576eb8b (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
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/helpers.js"></script>

<form target="the-frame">
  <input type="hidden" name="pushed">
</form>

<script>
"use strict";
promise_test(async t => {
  const startingHistoryLength = history.length;

  const form = document.querySelector("form");
  const frameEndingURL = changeURLHost(
    absoluteURL("resources/slow-message-source-with-history-and-location.html?pushed="),
    "{{hosts[][www]}}"
  );
  form.action = frameEndingURL;

  const frameStartingCode = `
    parent.postMessage({ historyLength: history.length, locationHref: location.href }, "*");
  `;

  const frameStartingURL = codeInjectorURL(frameStartingCode);
  const frame = insertIframe(t, frameStartingURL, "the-frame");
  t.add_cleanup(() => frame.remove()); // helps avoid waiting for the slow load to finish the tests
  assert_equals(history.length, startingHistoryLength, "Inserting frame must not change history.length");

  const frameBeforeLoadedMessage = await waitForMessage();
  assert_equals(frameBeforeLoadedMessage.historyLength, startingHistoryLength, "frame's starting history.length");
  assert_equals(frameBeforeLoadedMessage.locationHref, frame.src, "frame's starting location.href");

  form.submit();

  const frameAfterFormSubmitMessage = await waitForMessage();
  assert_equals(frameAfterFormSubmitMessage.historyLength, startingHistoryLength + 1, "frame's after-submit history.length");
  assert_equals(frameAfterFormSubmitMessage.locationHref, frameEndingURL, "frame's after-submit location.href");
}, "No replace before load, triggered by cross-iframe formElement.submit() [iframe is cross-origin]");
</script>