test_partially_cached_content.html 3.2 KB

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