OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Synchronous XMLHttpRequest and caching during document load</title> |
| 5 </head> |
| 6 <body> |
| 7 <script src="../resources/testharness.js"></script> |
| 8 <script src="../resources/testharnessreport.js"></script> |
| 9 <script type="text/javascript"> |
| 10 |
| 11 // Test what caching XMLHttpRequest performs when issuing |
| 12 // sync requests over various verbs and with various |
| 13 // kinds of query portions. Without any cache control |
| 14 // headers. |
| 15 var verbs = [ "GET", |
| 16 "PUT", |
| 17 "POST", |
| 18 "PROPFIND"]; |
| 19 |
| 20 var query_kinds = [ |
| 21 {query: "'?random'", |
| 22 name: "constant query", |
| 23 // The list of verbs we expect the request not to be repeated for. |
| 24 should_cache: []}, |
| 25 {query: "", |
| 26 name: "no query", |
| 27 should_cache: []}, |
| 28 {query: "'?' + (Math.random() + Date.now()).toString()", |
| 29 name: "unique query string", |
| 30 should_cache: []}, |
| 31 {query: "'?'", |
| 32 name: "empty query", |
| 33 should_cache: []}]; |
| 34 |
| 35 var base_url = "resources/echo-random.php"; |
| 36 |
| 37 function runTest() { |
| 38 for (var i = 0; i < verbs.length; i++) { |
| 39 var verb = verbs[i]; |
| 40 for (var j = 0; j < query_kinds.length; j++) { |
| 41 var q1 = eval(query_kinds[j].query) || ""; |
| 42 |
| 43 var request_url1 = base_url + q1; |
| 44 var xhr1 = new XMLHttpRequest; |
| 45 xhr1.open(verb, request_url1, false); |
| 46 xhr1.send(); |
| 47 var result1 = xhr1.responseText; |
| 48 |
| 49 var xhr2 = new XMLHttpRequest(); |
| 50 var q2 = eval(query_kinds[j].query) || ""; |
| 51 var request_url2 = base_url + q2; |
| 52 xhr2.open(verb, request_url2, false); |
| 53 xhr2.send(); |
| 54 var result2 = xhr2.responseText; |
| 55 |
| 56 test(function () { |
| 57 if (query_kinds[j].should_cache.indexOf(verb) >= 0) |
| 58 assert_true(result1 === result2); |
| 59 else |
| 60 assert_false(result1 === result2); |
| 61 }, "Test repeated sync requests using verb '" + verb + " with " + qu
ery_kinds[j].name); |
| 62 } |
| 63 } |
| 64 } |
| 65 |
| 66 test(runTest, document.title); |
| 67 </script> |
| 68 <div id="log"></div> |
| 69 </body> |
| 70 </html> |
OLD | NEW |