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

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4   https://bugzilla.mozilla.org/show_bug.cgi?id=497003
     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>
    22 <pre id="test">
    23 <script>
    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;
    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   }
    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.");
    46   // Set up listener for second load.
    47   e.target.removeEventListener("load", expectInitialContent, false);
    48   e.target.addEventListener("load", expectFullContent, false);
    50   // Reload.
    51   e.target.src="partial_content.sjs";
    52 }
    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;
    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   }
    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   }
    78   SimpleTest.finish();
    79 }
    81 // Set listener for first load to expect partial content.
    82 document.getElementById('contentFrame')
    83   .addEventListener("load", expectInitialContent, false);
    85 SimpleTest.waitForExplicitFinish();
    87 </script>
    88 </pre>
    89 </body>
    90 </html>

mercurial