netwerk/test/mochitests/test_partially_cached_content.html

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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

mercurial