summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookies/attributes/max-age.html
blob: 7b7ff6ed4c4baaa327b457a4fe6f9f647e1d4a54 (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
<!doctype html>
<html>
  <head>
    <meta charset=utf-8>
    <title>Test max-age attribute parsing</title>
    <meta name=help href="https://tools.ietf.org/html/rfc6265#section-5.3.2">
    <meta name="timeout" content="long">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/resources/testdriver.js"></script>
    <script src="/resources/testdriver-vendor.js"></script>
    <script src="/cookies/resources/cookie-test.js"></script>
  </head>
  <body>
    <div id=log></div>
    <script>
      // TODO: there is more to test here, these tests capture the old
      // ported http-state tests. Feel free to delete this comment when more
      // are added.
      const maxAgeTests = [
        {
          cookie: "test=1; Max-Age=50,399",
          expected: "test=1",
          name: "Ignore max-age attribute with invalid non-zero-digit (containing a comma)",
        },
        {
          cookie: "test=2; max-age=10000",
          expected: "test=2",
          name: "Set cookie with age",
        },
        {
          cookie: "test=3; max-age=0",
          expected: "",
          name: "Set no cookie with max-age=0",
        },
        {
          cookie: "test=4; max-age=-1",
          expected: "",
          name: "Set no cookie with max-age=-1",
        },
        {
          cookie: "test=5; max-age=-20",
          expected: "",
          name: "Set no cookie with max-age=-20",
        },
        {
          cookie: ["testA=6; max-age=60", "testB=6; max-age=60"],
          expected: "testA=6; testB=6",
          name: "Set multiple cookies with max-age attribute",
        },
        {
          cookie: ["testA=7; max-age=60", "testB=7; max-age=60", "testA=differentvalue; max-age=0"],
          expected: "testB=7",
          name: "Expire later cookie with same name and max-age=0",
        },
        {
          cookie: ["testA=8; max-age=60", "testB=8; max-age=60", "testA=differentvalue; max-age=0", "testC=8; max-age=0"],
          expected: "testB=8",
          name: "Expire later cookie with same name and max-age=0, and don't set cookie with max-age=0",
        },
        {
          cookie: ['test="9! = foo;bar\";" parser; max-age=6', "test9; max-age=2.63,"],
          expected: 'test="9! = foo; test9',
          name: "Set mulitiple cookies with valid max-age values",
        },
        {
          cookie: ["test=10; max-age=0", "test10; max-age=0"],
          expected: "",
          name: "Don't set multiple cookies with max-age=0",
        },
      ];

      for (const test of maxAgeTests) {
        httpCookieTest(test.cookie, test.expected, test.name);
      }
    </script>
  </body>
</html>