2013-07-09 01:45:25 +00:00
<!DOCTYPE HTML>
< html >
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=497003
This test verifies that partially cached content is read from the cache first
and then from the network. It is written in the mochitest framework to take
thread retargeting into consideration of nsIStreamListener callbacks (inc.
nsIRequestObserver). E.g. HTML5 Stream Parser requesting retargeting of
nsIStreamListener callbacks to the parser thread.
-->
< head >
< meta charset = "UTF-8" >
< title > Test for Bug 497003: support sending OnDataAvailable() to other threads< / title >
< script type = "application/javascript" src = "/tests/SimpleTest/SimpleTest.js" > < / script >
< link rel = "stylesheet" type = "text/css" href = "/tests/SimpleTest/test.css" / >
< / head >
< body >
< 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 >
< p > < iframe id = "contentFrame" src = "partial_content.sjs" > < / iframe > < / p >
< pre id = "test" >
< script >
/* Check that the iframe has initial content only after the first load.
*/
function expectInitialContent(e) {
info("expectInitialContent",
"First response received: should have partial content");
2014-06-13 11:39:00 +00:00
var frameElement = document.getElementById('contentFrame');
var frameWindow = frameElement.contentWindow;
2013-07-09 01:45:25 +00:00
// Expect "First response" in received HTML.
var firstResponse = frameWindow.document.getElementById('firstResponse');
ok(firstResponse, "First response should exist");
if (firstResponse) {
is(firstResponse.innerHTML, "First response",
"First response should be correct");
}
// Expect NOT to get any second response element.
var secondResponse = frameWindow.document.getElementById('secondResponse');
ok(!secondResponse, "Should not get text for second response in first.");
// Set up listener for second load.
2014-06-13 11:39:00 +00:00
removeEventListener("load", expectInitialContent, false);
frameElement.addEventListener("load", expectFullContent, false);
2013-07-09 01:45:25 +00:00
// Reload.
2014-06-13 11:39:00 +00:00
frameElement.src="partial_content.sjs";
2013-07-09 01:45:25 +00:00
}
/* Check that the iframe has all the content after the second load.
*/
function expectFullContent(e)
{
info("expectFullContent",
"Second response received: should complete content from first load");
var frameWindow = document.getElementById('contentFrame').contentWindow;
// Expect "First response" to still be there
var firstResponse = frameWindow.document.getElementById('firstResponse');
ok(firstResponse, "First response should exist");
if (firstResponse) {
is(firstResponse.innerHTML, "First response",
"First response should be correct");
}
// Expect "Second response" to be there also.
var secondResponse = frameWindow.document.getElementById('secondResponse');
ok(secondResponse, "Second response should exist");
if (secondResponse) {
is(secondResponse.innerHTML, "Second response",
"Second response should be correct");
}
SimpleTest.finish();
}
// Set listener for first load to expect partial content.
2014-06-13 11:39:00 +00:00
// Note: Set listener on the global object/window since 'load' should not fire
// for partially loaded content in an iframe.
addEventListener("load", expectInitialContent, false);
2013-07-09 01:45:25 +00:00
SimpleTest.waitForExplicitFinish();
< / script >
< / pre >
< / body >
< / html >