summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/request/request-init-001.sub.html
blob: cc495a66527d7b2ab3729bf58c0dc31f8d1088e1 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Request init: simple cases</title>
    <meta name="help" href="https://fetch.spec.whatwg.org/#request">
    <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <script>
      // https://fetch.spec.whatwg.org/#concept-method-normalize
      var methods = {
        "givenValues" : [
          "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
          "get", "head", "post", "put", "delete", "options",
          "Get", "hEad", "poSt", "Put", "deleTe", "optionS",
          "PATCH", "patch", "patCh"
        ],
        "expectedValues" : [
          "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
          "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
          "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
          "PATCH", "patch", "patCh"
        ]
      };
      var referrers = {"givenValues" : ["/relative/ressource",
                                        "http://{{host}}:{{ports[http][0]}}/relative/ressource?query=true#fragment",
                                        "http://{{host}}:{{ports[http][0]}}/",
                                        "http://test.url",
                                        "about:client",
                                        ""
                                       ],
                       "expectedValues" : ["http://{{host}}:{{ports[http][0]}}/relative/ressource",
                                           "http://{{host}}:{{ports[http][0]}}/relative/ressource?query=true#fragment",
                                           "http://{{host}}:{{ports[http][0]}}/",
                                           "about:client",
                                           "about:client",
                                           ""
                                          ]
      };
      var referrerPolicies = {"givenValues" : [ "",
                                                "no-referrer",
                                                "no-referrer-when-downgrade",
                                                "origin",
                                                "origin-when-cross-origin",
                                                "unsafe-url",
                                                "same-origin",
                                                "strict-origin",
                                                "strict-origin-when-cross-origin"
                                              ],
                              "expectedValues" : ["",
                                                  "no-referrer",
                                                  "no-referrer-when-downgrade",
                                                  "origin",
                                                  "origin-when-cross-origin",
                                                  "unsafe-url",
                                                  "same-origin",
                                                  "strict-origin",
                                                  "strict-origin-when-cross-origin"
                                                  ]
      };
      var modes = {"givenValues" : ["same-origin", "no-cors", "cors"],
                   "expectedValues" : ["same-origin", "no-cors", "cors"]
      };
      var credentials = {"givenValues" : ["omit", "same-origin", "include"],
                          "expectedValues" : ["omit", "same-origin", "include"]
      };
      var caches = {"givenValues" : [ "default", "no-store", "reload", "no-cache", "force-cache"],
                    "expectedValues" : [ "default", "no-store", "reload", "no-cache", "force-cache"]
      };
      var redirects = {"givenValues" : ["follow", "error", "manual"],
                       "expectedValues" : ["follow", "error", "manual"]
      };
      var integrities = {"givenValues" : ["", "AZERTYUIOP1234567890" ],
                         "expectedValues" : ["", "AZERTYUIOP1234567890"]
      };

      //there is no getter for window, init's window might be null
      var windows = {"givenValues" : [ null ],
                     "expectedValues" : [undefined]
      };

      var initValuesDict = { "method" : methods,
                             "referrer" : referrers,
                             "referrerPolicy" : referrerPolicies,
                             "mode" : modes,
                             "credentials" : credentials,
                             "cache" : caches,
                             "redirect" : redirects,
                             "integrity" : integrities,
                             "window" : windows
      };

      for (var attributeName in initValuesDict) {
        var valuesToTest = initValuesDict[attributeName];
        for (var valueIdx in valuesToTest["givenValues"]) {
          var givenValue = valuesToTest["givenValues"][valueIdx];
          var expectedValue = valuesToTest["expectedValues"][valueIdx];
          test(function() {
            var requestInit = {};
            requestInit[attributeName] = givenValue
            var request = new Request("", requestInit);
            assert_equals(request[attributeName], expectedValue,
              "Expect request's " + attributeName + " is " + expectedValue + " when initialized with " + givenValue);
          }, "Check " + attributeName + " init value of " + givenValue + " and associated getter");
        }
      }
    </script>
  </body>
</html>