summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html
blob: 4510807c2c66ce2c61f6a33dda863ba4f03e4ae7 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>HTML Test: formAction_document_address</title>
    <link rel="author" title="Intel" href="http://www.intel.com/">
    <link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-fs-formaction">
    <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-document's-address">
    <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-button-element">
    <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-input-element">
    <meta name="assert" content="On getting the formAction IDL attribute, when the content attribute is missing or its value is the empty string, the document's address must be returned instead.">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <div id="log"></div>

    <div id="missing" style="display:none">
      <button type="submit">Submit</button>
      <input type="submit">
    </div>

    <div id="empty_string" style="display:none">
      <button type="submit" formaction="">Submit</button>
      <input type="submit" formaction="">
    </div>

    <div id="no_assigned_value" style="display:none">
      <button type="submit" formaction>Submit</button>
      <input type="submit" formaction>
    </div>

    <script>
      // formaction content attribute is missing
      test(function() {
        var formAction = document.querySelector('#missing button').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if button.formAction is the document's address when formaction content attribute is missing");

      test(function() {
        var formAction = document.querySelector('#missing input').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if input.formAction is the document's address when formaction content attribute is missing");

      // formaction content attribute value is empty string
      test(function() {
        var formAction = document.querySelector('#empty_string button').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if button.formAction is the document's address when formaction content attribute value is empty string");

      test(function() {
        var formAction = document.querySelector('#empty_string input').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if input.formAction is the document's address when formaction content attribute value is empty string");

      // formaction content attribute value is not assigned, just for comparison with empty string above
      test(function() {
        var formAction = document.querySelector('#no_assigned_value button').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if button.formAction is the document's address when formaction content attribute value is not assigned");

      test(function() {
        var formAction = document.querySelector('#no_assigned_value input').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if input.formAction is the document's address when formaction content attribute value is not assigned");

      var newUrl = location.href.replace(/\/[^\/]*$/,'\/dummy.html');
      history.pushState('','','dummy.html');

      test(function() {
        assert_equals(document.location.href, newUrl);

        var formAction = document.querySelector('#missing button').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if button.formAction is the document's new address when formaction content attribute is missing and pushState has been used");

      test(function() {
        assert_equals(document.location.href, newUrl);

        var formAction = document.querySelector('#missing input').formAction;
        var address = document.location.href;
        assert_equals(formAction, address);
      }, "Check if input.formAction is the document's new address when formaction content attribute is missing and pushState has been used");
    </script>
  </body>
</html>