File: match.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (113 lines) | stat: -rw-r--r-- 3,538 bytes parent folder | download | duplicates (18)
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
113
<!doctype html>
<html>
<head>
  <meta charset=utf-8>
  <title>tests for matching cookie paths</title>
  <meta name="timeout" content="long">
  <meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">

  <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/testharness-helpers.js"></script>
</head>
<body>
<div id=log></div>

<script>
var body = document.getElementsByTagName('body')[0];
var createIframeThen = function (callback) {
  var iframe = document.createElement('iframe');
  iframe.src = "/cookies/resources/echo-cookie.html";
  body.appendChild(iframe);
  iframe.onload = callback;
  return iframe;
};
var testCookiePathFromDOM = function (testCase, test) {
  var iframe = createIframeThen(test.step_func(function () {
    iframe.contentWindow.setCookie('dom-' + testCase.name, testCase.path);
    var cookieSet = iframe.contentWindow.isCookieSet('dom-' + testCase.name, testCase.path);
    if (testCase.match === false) {
      assert_equals(cookieSet, null);
    } else {
      assert_not_equals(cookieSet, null, "Cookie path from DOM should not be `null`");
    }
    iframe.contentWindow.expireCookies().then(() => test.done());
  }));
};
var testCookiePathFromHeader = function (testCase, test) {
  var iframe = createIframeThen(test.step_func(function () {
    iframe.contentWindow.fetchCookieThen('header-' + testCase.name, testCase.path).then(test.step_func(function (response) {
      assert_true(response.ok);
      var cookieSet = iframe.contentWindow.isCookieSet('header-' + testCase.name, testCase.path);
      iframe.contentWindow.expireCookies().then(test.step_func(function () {
        if (testCase.match === false) {
          assert_equals(cookieSet, null);
        } else {
          assert_not_equals(cookieSet, null, "Cookie path from header should not be `null`");
        }
        test.done();
      }));
    })).catch(test.unreached_func());
  }));
};

var tests = [{
  "name": "match-slash",
  "path": "/",
}, {
  "name": "match-page",
  "path": "match.html",
}, {
  "name": "match-prefix",
  "path": "cookies",
}, {
  "name": "match-slash-prefix",
  "path": "/cookies",
}, {
  "name": "match-slash-prefix-slash",
  "path": "/cookies/",
}, {
  "name": "match-exact-page",
  "path": "/cookies/resources/echo-cookie.html",
}, {
  "name": "no-match",
  "path": "/cook",
  "match": false
}, {
  "name": "no-match-subpath",
  "path": "/w/",
  "match": false
}];

var domTests = tests.map(function (testCase) {
  var testName = "`document.cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
  if (testCase.match === false) {
    testName = "`document.cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
  }
  return [
    testName,
    function () {
      testCookiePathFromDOM(testCase, this);
    }
  ];
});

var headerTests = tests.map(function (testCase) {
  var testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
  if (testCase.match === false) {
    testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
  }
  return [
    testName,
    function () {
      testCookiePathFromHeader(testCase, this);
    }
  ];
});

executeTestsSerially(domTests.concat(headerTests));
</script>
</body>
</html>