heuristic.any.js (3088B)
1 // META: global=window,worker 2 // META: title=HTTP Cache - Heuristic 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 { 10 name: "HTTP cache reuses an unknown response with Last-Modified based upon heuristic freshness when Cache-Control: public is present", 11 requests: [ 12 { 13 response_status: [299, "Whatever"], 14 response_headers: [ 15 ["Last-Modified", (-3 * 100)], 16 ["Cache-Control", "public"] 17 ], 18 }, 19 { 20 expected_type: "cached", 21 response_status: [299, "Whatever"] 22 } 23 ] 24 }, 25 { 26 name: "HTTP cache does not reuse an unknown response with Last-Modified based upon heuristic freshness when Cache-Control: public is not present", 27 requests: [ 28 { 29 response_status: [299, "Whatever"], 30 response_headers: [ 31 ["Last-Modified", (-3 * 100)] 32 ], 33 }, 34 { 35 expected_type: "not_cached", 36 } 37 ] 38 }, 39 { 40 name: "HTTP cache does not reuse a redirected response with no max-age and no Last-Modified header", 41 requests: [ 42 { 43 response_status: [301, "Moved Permanently"], 44 response_headers: [ 45 ["Cache-Control", "private"], 46 ["Location", "redirect_target"] 47 ], 48 }, 49 { skip: true}, // Response to first redirect 50 { 51 response_status: [301, "Moved Permanently"], 52 response_headers: [ 53 ["Cache-Control", "private"], 54 ["Location", "redirect_target"] 55 ], 56 expected_type: "not_cached", 57 }, 58 { skip: true}, // response to second redirect 59 ], 60 check_count: true, 61 }, 62 ]; 63 64 function check_status(status) { 65 var succeed = status[0]; 66 var code = status[1]; 67 var phrase = status[2]; 68 var body = status[3]; 69 if (body === undefined) { 70 body = http_content(code); 71 } 72 var expected_type = "not_cached"; 73 var desired = "does not use" 74 if (succeed === true) { 75 expected_type = "cached"; 76 desired = "reuses"; 77 } 78 tests.push( 79 { 80 name: "HTTP cache " + desired + " a " + code + " " + phrase + " response with Last-Modified based upon heuristic freshness", 81 requests: [ 82 { 83 response_status: [code, phrase], 84 response_headers: [ 85 ["Last-Modified", (-3 * 100)] 86 ], 87 response_body: body 88 }, 89 { 90 expected_type: expected_type, 91 response_status: [code, phrase], 92 response_body: body 93 } 94 ] 95 } 96 ) 97 } 98 [ 99 [true, 200, "OK"], 100 [true, 203, "Non-Authoritative Information"], 101 [true, 204, "No Content", ""], 102 [true, 404, "Not Found"], 103 [true, 405, "Method Not Allowed"], 104 [true, 410, "Gone"], 105 [true, 414, "URI Too Long"], 106 [true, 501, "Not Implemented"] 107 ].forEach(check_status); 108 [ 109 [false, 201, "Created"], 110 [false, 202, "Accepted"], 111 [false, 403, "Forbidden"], 112 [false, 502, "Bad Gateway"], 113 [false, 503, "Service Unavailable"], 114 [false, 504, "Gateway Timeout"], 115 ].forEach(check_status); 116 run_tests(tests);