tor-browser

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

freshness.any.js (5177B)


      1 // META: global=window,worker
      2 // META: title=HTTP Cache - Freshness
      3 // META: timeout=long
      4 // META: script=/common/utils.js
      5 // META: script=/common/get-host-info.sub.js
      6 // META: script=http-cache.js
      7 
      8 var tests = [
      9  // response directives
     10  {
     11    name: "HTTP cache reuses a response with a future Expires",
     12    requests: [
     13      {
     14        response_headers: [
     15          ["Expires", (30 * 24 * 60 * 60)]
     16        ]
     17      },
     18      {
     19        expected_type: "cached"
     20      }
     21    ]
     22  },
     23  {
     24    name: "HTTP cache does not reuse a response with a past Expires",
     25    requests: [
     26      {
     27        response_headers: [
     28          ["Expires", (-30 * 24 * 60 * 60)]
     29        ]
     30      },
     31      {
     32        expected_type: "not_cached"
     33      }
     34    ]
     35  },
     36  {
     37    name: "HTTP cache does not reuse a response with a present Expires",
     38    requests: [
     39      {
     40        response_headers: [
     41          ["Expires", 0]
     42        ]
     43      },
     44      {
     45        expected_type: "not_cached"
     46      }
     47    ]
     48  },
     49  {
     50    name: "HTTP cache does not reuse a response with an invalid Expires",
     51    requests: [
     52      {
     53        response_headers: [
     54          ["Expires", "0"]
     55        ]
     56      },
     57      {
     58        expected_type: "not_cached"
     59      }
     60    ]
     61  },
     62  {
     63    name: "HTTP cache does not reuse a response with an invalid Expires with Last-Modified now",
     64    requests: [
     65      {
     66        response_headers: [
     67          ["Expires", "0"],
     68          ['Last-Modified', 0]
     69        ]
     70      },
     71      {
     72        expected_type: "not_cached"
     73      }
     74    ]
     75  },
     76  {
     77    name: "HTTP cache does not reuse a response with an invalid Expires with past Last-Modified",
     78    requests: [
     79      {
     80        response_headers: [
     81          ["Expires", "0"],
     82          ['Last-Modified', -100000]
     83        ]
     84      },
     85      {
     86        expected_type: "not_cached"
     87      }
     88    ]
     89  },
     90  {
     91    name: "HTTP cache reuses a response with positive Cache-Control: max-age",
     92    requests: [
     93      {
     94        response_headers: [
     95          ["Cache-Control", "max-age=3600"]
     96        ]
     97      },
     98      {
     99        expected_type: "cached"
    100      }
    101    ]
    102  },
    103  {
    104    name: "HTTP cache does not reuse a response with Cache-Control: max-age=0",
    105    requests: [
    106      {
    107        response_headers: [
    108          ["Cache-Control", "max-age=0"]
    109        ]
    110      },
    111      {
    112        expected_type: "not_cached"
    113      }
    114    ]
    115  },
    116  {
    117    name: "HTTP cache reuses a response with positive Cache-Control: max-age and a past Expires",
    118    requests: [
    119      {
    120        response_headers: [
    121          ["Cache-Control", "max-age=3600"],
    122          ["Expires", -10000]
    123        ]
    124      },
    125      {
    126        expected_type: "cached"
    127      }
    128    ]
    129  },
    130  {
    131    name: "HTTP cache reuses a response with positive Cache-Control: max-age and an invalid Expires",
    132    requests: [
    133      {
    134        response_headers: [
    135          ["Cache-Control", "max-age=3600"],
    136          ["Expires", "0"]
    137        ]
    138      },
    139      {
    140        expected_type: "cached"
    141      }
    142    ]
    143  },
    144  {
    145    name: "HTTP cache does not reuse a response with Cache-Control: max-age=0 and a future Expires",
    146    requests: [
    147      {
    148        response_headers: [
    149          ["Cache-Control", "max-age=0"],
    150          ["Expires", 10000]
    151        ]
    152      },
    153      {
    154        expected_type: "not_cached"
    155      }
    156    ]
    157  },
    158  {
    159    name: "HTTP cache does not prefer Cache-Control: s-maxage over Cache-Control: max-age",
    160    requests: [
    161      {
    162        response_headers: [
    163          ["Cache-Control", "max-age=1, s-maxage=3600"]
    164        ],
    165        pause_after: true,
    166      },
    167      {
    168        expected_type: "not_cached"
    169      }
    170    ]
    171  },
    172  {
    173    name: "HTTP cache does not reuse a response when the Age header is greater than its freshness lifetime",
    174    requests: [
    175      {
    176        response_headers: [
    177          ["Cache-Control", "max-age=3600"],
    178          ["Age", "12000"]
    179        ],
    180      },
    181      {
    182        expected_type: "not_cached"
    183      }
    184    ]
    185  },
    186  {
    187    name: "HTTP cache does not store a response with Cache-Control: no-store",
    188    requests: [
    189      {
    190        response_headers: [
    191          ["Cache-Control", "no-store"]
    192        ]
    193      },
    194      {
    195        expected_type: "not_cached"
    196      }
    197    ]
    198  },
    199  {
    200    name: "HTTP cache does not store a response with Cache-Control: no-store, even with max-age and Expires",
    201    requests: [
    202      {
    203        response_headers: [
    204          ["Cache-Control", "max-age=10000, no-store"],
    205          ["Expires", 10000]
    206        ]
    207      },
    208      {
    209        expected_type: "not_cached"
    210      }
    211    ]
    212  },
    213  {
    214    name: "HTTP cache stores a response with Cache-Control: no-cache, but revalidates upon use",
    215    requests: [
    216      {
    217        response_headers: [
    218          ["Cache-Control", "no-cache"],
    219          ["ETag", "abcd"]
    220        ]
    221      },
    222      {
    223        expected_type: "etag_validated"
    224      }
    225    ]
    226  },
    227  {
    228    name: "HTTP cache stores a response with Cache-Control: no-cache, but revalidates upon use, even with max-age and Expires",
    229    requests: [
    230      {
    231        response_headers: [
    232          ["Cache-Control", "max-age=10000, no-cache"],
    233          ["Expires", 10000],
    234          ["ETag", "abcd"]
    235        ]
    236      },
    237      {
    238        expected_type: "etag_validated"
    239      }
    240    ]
    241  },
    242 ];
    243 run_tests(tests);