test_partially_cached_content.html (3433B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=497003 5 6 This test verifies that partially cached content is read from the cache first 7 and then from the network. It is written in the mochitest framework to take 8 thread retargeting into consideration of nsIStreamListener callbacks (inc. 9 nsIRequestObserver). E.g. HTML5 Stream Parser requesting retargeting of 10 nsIStreamListener callbacks to the parser thread. 11 --> 12 <head> 13 <meta charset="UTF-8"> 14 <title>Test for Bug 497003: support sending OnDataAvailable() to other threads</title> 15 <script src="/tests/SimpleTest/SimpleTest.js"></script> 16 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 17 </head> 18 <body> 19 <p><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=497003">Mozilla Bug 497003: support sending OnDataAvailable() to other threads</a></p> 20 <p><iframe id="contentFrame" src="partial_content.sjs"></iframe></p> 21 22 <pre id="test"> 23 <script> 24 25 26 27 /* Check that the iframe has initial content only after the first load. 28 */ 29 function expectInitialContent() { 30 info("expectInitialContent", 31 "First response received: should have partial content"); 32 var frameElement = document.getElementById('contentFrame'); 33 var frameWindow = frameElement.contentWindow; 34 35 // Expect "First response" in received HTML. 36 var firstResponse = frameWindow.document.getElementById('firstResponse'); 37 ok(firstResponse, "First response should exist"); 38 if (firstResponse) { 39 is(firstResponse.innerHTML, "First response", 40 "First response should be correct"); 41 } 42 43 // Expect NOT to get any second response element. 44 var secondResponse = frameWindow.document.getElementById('secondResponse'); 45 ok(!secondResponse, "Should not get text for second response in first."); 46 47 // Set up listener for second load. 48 removeEventListener("load", expectInitialContent, false); 49 frameElement.addEventListener("load", expectFullContent); 50 51 var reload = ()=>frameElement.src = "partial_content.sjs"; 52 53 // Before reload, disable rcwn to avoid racing and a non-range request. 54 SpecialPowers.pushPrefEnv({set: [["network.http.rcwn.enabled", false]]}, 55 reload); 56 } 57 58 /* Check that the iframe has all the content after the second load. 59 */ 60 function expectFullContent() 61 { 62 info("expectFullContent", 63 "Second response received: should complete content from first load"); 64 var frameWindow = document.getElementById('contentFrame').contentWindow; 65 66 // Expect "First response" to still be there 67 var firstResponse = frameWindow.document.getElementById('firstResponse'); 68 ok(firstResponse, "First response should exist"); 69 if (firstResponse) { 70 is(firstResponse.innerHTML, "First response", 71 "First response should be correct"); 72 } 73 74 // Expect "Second response" to be there also. 75 var secondResponse = frameWindow.document.getElementById('secondResponse'); 76 ok(secondResponse, "Second response should exist"); 77 if (secondResponse) { 78 is(secondResponse.innerHTML, "Second response", 79 "Second response should be correct"); 80 } 81 82 SimpleTest.finish(); 83 } 84 85 // Set listener for first load to expect partial content. 86 // Note: Set listener on the global object/window since 'load' should not fire 87 // for partially loaded content in an iframe. 88 addEventListener("load", expectInitialContent, false); 89 90 SimpleTest.waitForExplicitFinish(); 91 92 </script> 93 </pre> 94 </body> 95 </html>