tor-browser

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

partial.any.js (5148B)


      1 // META: global=window,worker
      2 // META: title=HTTP Cache - Partial Content
      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  {
     10    name: "HTTP cache stores partial content and reuses it",
     11    requests: [
     12      {
     13        request_headers: [
     14          ['Range', "bytes=-5"]
     15        ],
     16        response_status: [206, "Partial Content"],
     17        response_headers: [
     18          ["Cache-Control", "max-age=3600"],
     19          ["Content-Range", "bytes 4-9/10"]
     20        ],
     21        response_body: "01234",
     22        expected_request_headers: [
     23          ["Range", "bytes=-5"]
     24        ]
     25      },
     26      {
     27        request_headers: [
     28          ["Range", "bytes=-5"]
     29        ],
     30        expected_type: "cached",
     31        expected_status: 206,
     32        expected_response_text: "01234"
     33      }
     34    ]
     35  },
     36  {
     37    name: "HTTP cache stores complete response and serves smaller ranges from it (byte-range-spec)",
     38    requests: [
     39      {
     40        response_headers: [
     41          ["Cache-Control", "max-age=3600"]
     42        ],
     43        response_body: "01234567890"
     44      },
     45      {
     46        request_headers: [
     47          ['Range', "bytes=0-1"]
     48        ],
     49        expected_type: "cached",
     50        expected_status: 206,
     51        expected_response_text: "01"
     52      },
     53    ]
     54  },
     55  {
     56    name: "HTTP cache stores complete response and serves smaller ranges from it (absent last-byte-pos)",
     57    requests: [
     58      {
     59        response_headers: [
     60          ["Cache-Control", "max-age=3600"],
     61        ],
     62        response_body: "01234567890"
     63      },
     64      {
     65        request_headers: [
     66          ['Range', "bytes=1-"]
     67        ],
     68        expected_type: "cached",
     69        expected_status: 206,
     70        expected_response_text: "1234567890"
     71      }
     72    ]
     73  },
     74  {
     75    name: "HTTP cache stores complete response and serves smaller ranges from it (suffix-byte-range-spec)",
     76    requests: [
     77      {
     78        response_headers: [
     79          ["Cache-Control", "max-age=3600"],
     80        ],
     81        response_body: "0123456789A"
     82      },
     83      {
     84        request_headers: [
     85          ['Range', "bytes=-1"]
     86        ],
     87        expected_type: "cached",
     88        expected_status: 206,
     89        expected_response_text: "A"
     90      }
     91    ]
     92  },
     93  {
     94    name: "HTTP cache stores complete response and serves smaller ranges from it with only-if-cached",
     95    requests: [
     96      {
     97        response_headers: [
     98          ["Cache-Control", "max-age=3600"]
     99        ],
    100        response_body: "01234567890"
    101      },
    102      {
    103        request_headers: [
    104          ['Range', "bytes=0-1"]
    105        ],
    106        mode: "same-origin",
    107        cache: "only-if-cached",
    108        expected_type: "cached",
    109        expected_status: 206,
    110        expected_response_text: "01"
    111      },
    112    ]
    113  },
    114  {
    115    name: "HTTP cache stores partial response and serves smaller ranges from it (byte-range-spec)",
    116    requests: [
    117      {
    118        request_headers: [
    119          ['Range', "bytes=-5"]
    120        ],
    121        response_status: [206, "Partial Content"],
    122        response_headers: [
    123          ["Cache-Control", "max-age=3600"],
    124          ["Content-Range", "bytes 4-9/10"]
    125        ],
    126        response_body: "01234"
    127      },
    128      {
    129        request_headers: [
    130          ['Range', "bytes=6-8"]
    131        ],
    132        expected_type: "cached",
    133        expected_status: 206,
    134        expected_response_text: "234"
    135      }
    136    ]
    137  },
    138  {
    139    name: "HTTP cache stores partial response and serves smaller ranges from it (absent last-byte-pos)",
    140    requests: [
    141      {
    142        request_headers: [
    143          ['Range', "bytes=-5"]
    144        ],
    145        response_status: [206, "Partial Content"],
    146        response_headers: [
    147          ["Cache-Control", "max-age=3600"],
    148          ["Content-Range", "bytes 4-9/10"]
    149        ],
    150        response_body: "01234"
    151      },
    152      {
    153        request_headers: [
    154          ["Range", "bytes=6-"]
    155        ],
    156        expected_type: "cached",
    157        expected_status: 206,
    158        expected_response_text: "234"
    159      }
    160    ]
    161  },
    162  {
    163    name: "HTTP cache stores partial response and serves smaller ranges from it (suffix-byte-range-spec)",
    164    requests: [
    165      {
    166        request_headers: [
    167          ['Range', "bytes=-5"]
    168        ],
    169        response_status: [206, "Partial Content"],
    170        response_headers: [
    171          ["Cache-Control", "max-age=3600"],
    172          ["Content-Range", "bytes 4-9/10"]
    173        ],
    174        response_body: "01234"
    175      },
    176      {
    177        request_headers: [
    178          ['Range', "bytes=-1"]
    179        ],
    180        expected_type: "cached",
    181        expected_status: 206,
    182        expected_response_text: "4"
    183      }
    184    ]
    185  },
    186  {
    187    name: "HTTP cache stores partial content and completes it",
    188    requests: [
    189      {
    190        request_headers: [
    191          ['Range', "bytes=-5"]
    192        ],
    193        response_status: [206, "Partial Content"],
    194        response_headers: [
    195          ["Cache-Control", "max-age=3600"],
    196          ["Content-Range", "bytes 0-4/10"]
    197        ],
    198        response_body: "01234"
    199      },
    200      {
    201        expected_request_headers: [
    202          ["range", "bytes=5-"]
    203        ]
    204      }
    205    ]
    206  },
    207 ];
    208 run_tests(tests);