summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-form-element/form-action-submission.html
blob: 54ca7b5ff538dd9e040610d1ddeddecd588f3c64 (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>form action="" attribute effect on submission</title>
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
"use strict";

// promise_test instead of async_test because all tests use window.success, and so can't run at the same time.

promise_test(t => {
  return new Promise(resolve => {
    window.success = t.step_func(locationLoaded => {
      const expected = (new URL("resources/target/form-action-url-target.html?name=value", location.href)).href;
      assert_equals(locationLoaded, expected);
      resolve();
    });

    const iframe = document.createElement("iframe");
    iframe.src = "resources/form-with-action.sub.html?action=target/form-action-url-target.html";
    document.body.appendChild(iframe);
  });
}, "An action URL should be resolved relative to the document's base URL (= document's URL in this case)");

promise_test(t => {
  return new Promise(resolve => {
    window.success = t.step_func(locationLoaded => {
      const expected = (new URL("resources/form-with-action.sub.html?name=value", location.href)).href;
      assert_equals(locationLoaded, expected);
      resolve();
    });

    const iframe = document.createElement("iframe");
    iframe.src = "resources/form-with-action.sub.html?action=";
    document.body.appendChild(iframe);
  });
}, "An empty-string action should submit the form to the document's URL (= document's base URL in this case)");

promise_test(t => {
  return new Promise(resolve => {
    window.success = t.step_func(locationLoaded => {
      const expected = (new URL("resources/form-no-action.html?name=value", location.href)).href;
      assert_equals(locationLoaded, expected);
      resolve();
    });

    const iframe = document.createElement("iframe");
    iframe.src = "resources/form-no-action.html";
    document.body.appendChild(iframe);
  });
}, "A missing action should submit the form to the document's URL (= document's base URL in this case)");
</script>