| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../inspector-test.js"></script> | 3 <script src="../inspector-test.js"></script> |
| 4 <script src="../network-test.js"></script> | 4 <script src="../network-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 function loadImage(callback) | 6 function scheduleScriptLoad() { |
| 7 { | 7 window.setTimeout(loadScript, 0); |
| 8 var image = new Image(); | |
| 9 image.onload = callback; | |
| 10 image.src = "resources/resource.php?type=image&random=1&cached=1"; | |
| 11 document.body.appendChild(image); | |
| 12 } | 8 } |
| 13 | 9 |
| 14 function loadData() | 10 function loadScript() { |
| 15 { | 11 var script = document.createElement("script"); |
| 16 loadImage(imageLoaded1); | 12 script.type = "text/javascript"; |
| 17 } | 13 script.src = "resources/random-script.php"; |
| 18 | 14 document.head.appendChild(script); |
| 19 function imageLoaded1() | |
| 20 { | |
| 21 loadImage(imageLoaded2); | |
| 22 } | |
| 23 | |
| 24 function imageLoaded2() | |
| 25 { | |
| 26 console.log("First two images loaded."); | |
| 27 } | |
| 28 | |
| 29 function cacheDisabled() | |
| 30 { | |
| 31 loadImage(allImagesLoaded); | |
| 32 } | |
| 33 | |
| 34 function allImagesLoaded() | |
| 35 { | |
| 36 console.log("Done."); | |
| 37 } | 15 } |
| 38 | 16 |
| 39 function test() | 17 function test() |
| 40 { | 18 { |
| 41 InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "addMessage", s
tep2); | 19 var content1; |
| 42 InspectorTest.evaluateInPage("loadData()"); | 20 var content2; |
| 21 var content3; |
| 22 |
| 23 function loadScriptAndGetContent(callback) |
| 24 { |
| 25 InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "addMessage
", scriptLoaded); |
| 26 InspectorTest.evaluateInPage("scheduleScriptLoad()"); |
| 27 |
| 28 function scriptLoaded() |
| 29 { |
| 30 var resourcesCount = WebInspector.panels.network.resources.length; |
| 31 var resource = WebInspector.panels.network.resources[resourcesCount
- 1]; |
| 32 resource.requestContent(contentLoaded); |
| 33 } |
| 34 |
| 35 function contentLoaded() |
| 36 { |
| 37 var resourcesCount = WebInspector.panels.network.resources.length; |
| 38 var resource = WebInspector.panels.network.resources[resourcesCount
- 1]; |
| 39 callback(resource.content); |
| 40 } |
| 41 } |
| 42 |
| 43 loadScriptAndGetContent(step1); |
| 44 |
| 45 function step1(content) |
| 46 { |
| 47 content1 = content; |
| 48 InspectorTest.reloadPage(step2); |
| 49 } |
| 43 | 50 |
| 44 function step2(msg) | 51 function step2(msg) |
| 45 { | 52 { |
| 46 NetworkAgent.setCacheDisabled(true, step3); | 53 loadScriptAndGetContent(step3); |
| 47 } | 54 } |
| 48 | 55 |
| 49 function step3(msg) | 56 function step3(content) |
| 50 { | 57 { |
| 51 InspectorTest.addSniffer(WebInspector.ConsoleView.prototype, "addMessage
", step4); | 58 content2 = content; |
| 52 InspectorTest.evaluateInPage("cacheDisabled()"); | 59 NetworkAgent.setCacheDisabled(true, step4); |
| 53 } | 60 } |
| 54 | 61 |
| 55 function step4(msg) | 62 function step4(msg) |
| 56 { | 63 { |
| 57 // inspector-test.js appears in network panel occasionally in Safari on | 64 InspectorTest.reloadPage(step5); |
| 58 // Mac, so checking two last resources. | |
| 59 var resourcesCount = WebInspector.panels.network.resources.length; | |
| 60 var resource1 = WebInspector.panels.network.resources[resourcesCount - 2
]; | |
| 61 var resource2 = WebInspector.panels.network.resources[resourcesCount - 1
]; | |
| 62 resource1.requestContent(contentLoaded); | |
| 63 resource2.requestContent(contentLoaded); | |
| 64 } | |
| 65 | |
| 66 var contentLoadedCount = 0; | |
| 67 function contentLoaded() | |
| 68 { | |
| 69 if (++contentLoadedCount !== 2) | |
| 70 return; | |
| 71 | |
| 72 var resourcesCount = WebInspector.panels.network.resources.length; | |
| 73 var resource1 = WebInspector.panels.network.resources[resourcesCount - 2
]; | |
| 74 var resource2 = WebInspector.panels.network.resources[resourcesCount - 1
]; | |
| 75 | |
| 76 InspectorTest.addResult(resource1.url); | |
| 77 InspectorTest.addResult(resource2.url); | |
| 78 InspectorTest.assertTrue(resource1.content !== resource2.content, "Secon
d and third resources differ"); | |
| 79 NetworkAgent.setCacheDisabled(false, step5); | |
| 80 } | 65 } |
| 81 | 66 |
| 82 function step5(msg) | 67 function step5(msg) |
| 83 { | 68 { |
| 69 loadScriptAndGetContent(step6); |
| 70 } |
| 71 |
| 72 function step6(content) |
| 73 { |
| 74 content3 = content; |
| 75 |
| 76 InspectorTest.assertTrue(content1 === content2, "First and second script
s should be equal."); |
| 77 InspectorTest.assertTrue(content2 !== content3, "Second and third script
s should differ."); |
| 78 NetworkAgent.setCacheDisabled(false, step7); |
| 79 } |
| 80 |
| 81 function step7(msg) |
| 82 { |
| 84 InspectorTest.completeTest(); | 83 InspectorTest.completeTest(); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 </script> | 86 </script> |
| 88 </head> | 87 </head> |
| 89 <body onload="runTest()"> | 88 <body onload="runTest()"> |
| 90 <p>Tests disabling cache from inspector.</p> | 89 <p>Tests disabling cache from inspector.</p> |
| 91 </body> | 90 </body> |
| 92 </html> | 91 </html> |
| 93 | 92 |
| OLD | NEW |