summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/test_partially_cached_content.html
blob: 8b6df555f87826ae26f7e5fbcff5dd79fe8c4f1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!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 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");
  var frameElement = document.getElementById('contentFrame');
  var frameWindow = frameElement.contentWindow;

  // 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.
  removeEventListener("load", expectInitialContent, false);
  frameElement.addEventListener("load", expectFullContent);

  var reload = ()=>frameElement.src = "partial_content.sjs";

  // Before reload, disable rcwn to avoid racing and a non-range request.
  SpecialPowers.pushPrefEnv({set: [["network.http.rcwn.enabled", false]]},
                            reload);
}

/* 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.
// Note: Set listener on the global object/window since 'load' should not fire
// for partially loaded content in an iframe.
addEventListener("load", expectInitialContent, false);

SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>