|
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 type="application/javascript" 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(e) { |
|
30 info("expectInitialContent", |
|
31 "First response received: should have partial content"); |
|
32 var frameWindow = document.getElementById('contentFrame').contentWindow; |
|
33 |
|
34 // Expect "First response" in received HTML. |
|
35 var firstResponse = frameWindow.document.getElementById('firstResponse'); |
|
36 ok(firstResponse, "First response should exist"); |
|
37 if (firstResponse) { |
|
38 is(firstResponse.innerHTML, "First response", |
|
39 "First response should be correct"); |
|
40 } |
|
41 |
|
42 // Expect NOT to get any second response element. |
|
43 var secondResponse = frameWindow.document.getElementById('secondResponse'); |
|
44 ok(!secondResponse, "Should not get text for second response in first."); |
|
45 |
|
46 // Set up listener for second load. |
|
47 e.target.removeEventListener("load", expectInitialContent, false); |
|
48 e.target.addEventListener("load", expectFullContent, false); |
|
49 |
|
50 // Reload. |
|
51 e.target.src="partial_content.sjs"; |
|
52 } |
|
53 |
|
54 /* Check that the iframe has all the content after the second load. |
|
55 */ |
|
56 function expectFullContent(e) |
|
57 { |
|
58 info("expectFullContent", |
|
59 "Second response received: should complete content from first load"); |
|
60 var frameWindow = document.getElementById('contentFrame').contentWindow; |
|
61 |
|
62 // Expect "First response" to still be there |
|
63 var firstResponse = frameWindow.document.getElementById('firstResponse'); |
|
64 ok(firstResponse, "First response should exist"); |
|
65 if (firstResponse) { |
|
66 is(firstResponse.innerHTML, "First response", |
|
67 "First response should be correct"); |
|
68 } |
|
69 |
|
70 // Expect "Second response" to be there also. |
|
71 var secondResponse = frameWindow.document.getElementById('secondResponse'); |
|
72 ok(secondResponse, "Second response should exist"); |
|
73 if (secondResponse) { |
|
74 is(secondResponse.innerHTML, "Second response", |
|
75 "Second response should be correct"); |
|
76 } |
|
77 |
|
78 SimpleTest.finish(); |
|
79 } |
|
80 |
|
81 // Set listener for first load to expect partial content. |
|
82 document.getElementById('contentFrame') |
|
83 .addEventListener("load", expectInitialContent, false); |
|
84 |
|
85 SimpleTest.waitForExplicitFinish(); |
|
86 |
|
87 </script> |
|
88 </pre> |
|
89 </body> |
|
90 </html> |