summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/headers/headers-combine.html
blob: a0c15b0fed7590489f1e1681ac09c91a2e41c6c3 (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
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Headers nameshake</title>
    <meta name="help" href="https://fetch.spec.whatwg.org/#headers">
    <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>
      var headerSeqCombine = [["single", "singleValue"],
                              ["double", "doubleValue1"],
                              ["double", "doubleValue2"],
                              ["triple", "tripleValue1"],
                              ["triple", "tripleValue2"],
                              ["triple", "tripleValue3"]
      ];
      var expectedDict = {"single": "singleValue",
                          "double": "doubleValue1,doubleValue2",
                          "triple": "tripleValue1,tripleValue2,tripleValue3"
      };

      test(function() {
        var headers = new Headers(headerSeqCombine);
        for (name in expectedDict)
          assert_equals(headers.get(name), expectedDict[name],
              "name: " + name + " has value: " + expectedDict[name]);
      }, "Create headers using same name for different values");

      test(function() {
        var headers = new Headers(headerSeqCombine);
        for (name in expectedDict) {
          assert_true(headers.has(name), "name: " + name + " has value(s)");
          headers.delete(name);
          assert_false(headers.has(name), "name: " + name + " has no value(s) anymore");
        }
      }, "Check delete and has methods when using same name for different values");

      test(function() {
        var headers = new Headers(headerSeqCombine);
        for (name in expectedDict) {
          headers.set(name,"newSingleValue");
          assert_equals(headers.get(name), "newSingleValue", "name: " + name + " has value: newSingleValue");
        }
      }, "Check set methods when called with already used name");

      test(function() {
        var headers = new Headers(headerSeqCombine);
        for (name in expectedDict) {
          var value = headers.get(name);
          headers.append(name,"newSingleValue");
          assert_equals(headers.get(name), (value + "," + "newSingleValue"),
            "name: " + name + " has value: " + headers.get(name));
        }
      }, "Check append methods when called with already used name");
    </script>
  </body>
</html>