tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

match.html (3538B)


      1 <!doctype html>
      2 <html>
      3 <head>
      4  <meta charset=utf-8>
      5  <title>tests for matching cookie paths</title>
      6  <meta name="timeout" content="long">
      7  <meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
      8 
      9  <script src="/resources/testharness.js"></script>
     10  <script src="/resources/testharnessreport.js"></script>
     11  <script src="/resources/testdriver.js"></script>
     12  <script src="/resources/testdriver-vendor.js"></script>
     13  <script src="/cookies/resources/testharness-helpers.js"></script>
     14 </head>
     15 <body>
     16 <div id=log></div>
     17 
     18 <script>
     19 var body = document.getElementsByTagName('body')[0];
     20 var createIframeThen = function (callback) {
     21  var iframe = document.createElement('iframe');
     22  iframe.src = "/cookies/resources/echo-cookie.html";
     23  body.appendChild(iframe);
     24  iframe.onload = callback;
     25  return iframe;
     26 };
     27 var testCookiePathFromDOM = function (testCase, test) {
     28  var iframe = createIframeThen(test.step_func(function () {
     29    iframe.contentWindow.setCookie('dom-' + testCase.name, testCase.path);
     30    var cookieSet = iframe.contentWindow.isCookieSet('dom-' + testCase.name, testCase.path);
     31    if (testCase.match === false) {
     32      assert_equals(cookieSet, null);
     33    } else {
     34      assert_not_equals(cookieSet, null, "Cookie path from DOM should not be `null`");
     35    }
     36    iframe.contentWindow.expireCookies().then(() => test.done());
     37  }));
     38 };
     39 var testCookiePathFromHeader = function (testCase, test) {
     40  var iframe = createIframeThen(test.step_func(function () {
     41    iframe.contentWindow.fetchCookieThen('header-' + testCase.name, testCase.path).then(test.step_func(function (response) {
     42      assert_true(response.ok);
     43      var cookieSet = iframe.contentWindow.isCookieSet('header-' + testCase.name, testCase.path);
     44      iframe.contentWindow.expireCookies().then(test.step_func(function () {
     45        if (testCase.match === false) {
     46          assert_equals(cookieSet, null);
     47        } else {
     48          assert_not_equals(cookieSet, null, "Cookie path from header should not be `null`");
     49        }
     50        test.done();
     51      }));
     52    })).catch(test.unreached_func());
     53  }));
     54 };
     55 
     56 var tests = [{
     57  "name": "match-slash",
     58  "path": "/",
     59 }, {
     60  "name": "match-page",
     61  "path": "match.html",
     62 }, {
     63  "name": "match-prefix",
     64  "path": "cookies",
     65 }, {
     66  "name": "match-slash-prefix",
     67  "path": "/cookies",
     68 }, {
     69  "name": "match-slash-prefix-slash",
     70  "path": "/cookies/",
     71 }, {
     72  "name": "match-exact-page",
     73  "path": "/cookies/resources/echo-cookie.html",
     74 }, {
     75  "name": "no-match",
     76  "path": "/cook",
     77  "match": false
     78 }, {
     79  "name": "no-match-subpath",
     80  "path": "/w/",
     81  "match": false
     82 }];
     83 
     84 var domTests = tests.map(function (testCase) {
     85  var testName = "`document.cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
     86  if (testCase.match === false) {
     87    testName = "`document.cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
     88  }
     89  return [
     90    testName,
     91    function () {
     92      testCookiePathFromDOM(testCase, this);
     93    }
     94  ];
     95 });
     96 
     97 var headerTests = tests.map(function (testCase) {
     98  var testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html sets cookie with path: " + testCase.path;
     99  if (testCase.match === false) {
    100    testName = "`Set-Cookie` on /cookies/resources/echo-cookie.html DOES NOT set cookie for path: " + testCase.path;
    101  }
    102  return [
    103    testName,
    104    function () {
    105      testCookiePathFromHeader(testCase, this);
    106    }
    107  ];
    108 });
    109 
    110 executeTestsSerially(domTests.concat(headerTests));
    111 </script>
    112 </body>
    113 </html>