Attachment #387212: mochitest test case for bug #303267

View | Details | Raw Unified | Return to bug 303267
Collapse All | Expand All

(-)a/docshell/test/chrome/Makefile.in (+3 lines)
Line     Link Here 
 Lines 59-74   _TEST_FILES = \ Link Here 
59
		bug92598_window.xul \
59
		bug92598_window.xul \
60
		92598_nostore.html \
60
		92598_nostore.html \
61
		test_bug112564.xul \
61
		test_bug112564.xul \
62
		bug112564_window.xul \
62
		bug112564_window.xul \
63
		test_bug113934.xul \
63
		test_bug113934.xul \
64
		bug113934_window.xul \
64
		bug113934_window.xul \
65
		test_bug215405.xul \
65
		test_bug215405.xul \
66
		bug215405_window.xul \
66
		bug215405_window.xul \
67
		test_bug303267.xul \
68
    bug303267_window.xul \
69
    bug303267.html \
67
		test_bug364461.xul \
70
		test_bug364461.xul \
68
		bug364461_window.xul \
71
		bug364461_window.xul \
69
		test_bug396519.xul \
72
		test_bug396519.xul \
70
		bug396519_window.xul \
73
		bug396519_window.xul \
71
		test_bug428288.html \
74
		test_bug428288.html \
72
		test_bug449778.xul \
75
		test_bug449778.xul \
73
		bug449778_window.xul \
76
		bug449778_window.xul \
74
		test_bug449780.xul \
77
		test_bug449780.xul \
(-)a/docshell/test/chrome/bug303267.html (+25 lines)
Line     Link Here 
Line 0    Link Here 
1
<html>
2
<head>
3
  <title>
4
    bug303267.html
5
    </title>
6
  </head>
7
<body onpageshow="showpageshowcount()">
8
<script>
9
var pageshowcount = 0;
10
function showpageshowcount()
11
{
12
	pageshowcount++;
13
	var div1 = document.getElementById("div1");
14
	while (div1.firstChild)
15
	{
16
		div1.removeChild(div1.firstChild);
17
	}
18
	div1.appendChild(document.createTextNode(
19
	  "pageshowcount: " + pageshowcount));
20
}
21
</script>
22
<div id="div1">
23
	</div>
24
</body>
25
</html>
(-)a/docshell/test/chrome/bug303267_window.xul (+103 lines)
Line     Link Here 
Line 0    Link Here 
1
<?xml version="1.0"?>
2
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3
4
<window id="303267Test"
5
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
6
        width="600"
7
        height="600"
8
        onload="setTimeout(nextTest,0);"
9
        title="bug 303267 test">
10
11
  <script type="application/javascript"  
12
  src="chrome://mochikit/content/chrome/docshell/test/chrome/docshell_helpers.js">
13
  </script>
14
15
  <script type="application/javascript"><![CDATA[
16
  
17
    // Define the generator-iterator for the tests.
18
    var tests = testIterator();
19
20
    ////
21
    // Execute the next test in the generator function.
22
    //
23
    function nextTest() {
24
      tests.next();
25
    }
26
27
    ////
28
    // Generator function for test steps for bug 303267:  When a page is 
29
    // displayed from the bfcache, the script globals should
30
    // remain intact from the page's initial load.
31
    //
32
    function testIterator()
33
    {
34
      // Load an initial test page which should be saved in the bfcache.
35
      var navData = {
36
        uri: getHttpUrl("bug303267.html"),
37
        eventsToListenFor: ["pageshow"],
38
        expectedEvents: [ {type: "pageshow", title: "bug303267.html"} ],
39
        onNavComplete: nextTest
40
      };
41
      doPageNavigation(navData);
42
      yield;
43
      
44
      // Save the HTML of the test page for later comparison.
45
      var originalHTML = getInnerHTMLById("div1");
46
47
      // Load a second test page.  The first test page's pagehide event should
48
      // have the .persisted property set to true, indicating that it was 
49
      // stored in the bfcache.
50
      navData = {
51
        uri: "data:text/html,<html><head><title>page2</title></head>" +
52
             "<body>bug303267, page2</body></html>",
53
        eventsToListenFor: ["pageshow", "pagehide"],
54
        expectedEvents: [ {type: "pagehide", 
55
                           title: "bug303267.html", 
56
                           persisted: true},
57
                          {type: "pageshow", 
58
                           title: "page2"} ],
59
        onNavComplete: nextTest
60
      };
61
      doPageNavigation(navData);
62
      yield;
63
      
64
      // Go back.  Verify that the pageshow event for the original test page 
65
      // had a .persisted property of true, indicating that it came from the 
66
      // bfcache.
67
      navData = {
68
        back: true,
69
        eventsToListenFor: ["pageshow", "pagehide"],
70
        expectedEvents: [ {type: "pagehide", 
71
                           title: "page2"},
72
                          {type: "pageshow", 
73
                           title: "bug303267.html", 
74
                           persisted: true} ],
75
        onNavComplete: nextTest
76
      };
77
      doPageNavigation(navData);
78
      yield;
79
      
80
      // After going back, if showpagecount() could access a global variable
81
      // and change the test div's innerHTML, then we pass.  Otherwise, it
82
      // threw an exception and the following test will fail.
83
      var newHTML = getInnerHTMLById("div1");
84
      isnot(originalHTML, 
85
        newHTML, "HTML not updated on pageshow; javascript broken?");
86
87
      // Tell the framework the test is finished.  Include the final 'yield' 
88
      // statement to prevent a StopIteration exception from being thrown.
89
      finish();
90
      yield;
91
    }
92
93
    ////
94
    // Return the innerHTML of a particular element in the content document.
95
    //
96
    function getInnerHTMLById(id) {
97
      return TestWindow.getDocument().getElementById(id).innerHTML;
98
    }
99
    
100
  ]]></script>
101
102
  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
103
</window>
(-)a/docshell/test/chrome/test_bug303267.xul (+42 lines)
Line     Link Here 
Line 0    Link Here 
1
<?xml version="1.0"?>
2
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3
<?xml-stylesheet
4
  href="chrome://mochikit/content/tests/SimpleTest/test.css"
5
  type="text/css"?>
6
<!--
7
https://bugzilla.mozilla.org/show_bug.cgi?id=303267.xul
8
-->
9
<window title="Mozilla Bug 303267"
10
  xmlns:html="http://www.w3.org/1999/xhtml"
11
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
12
13
  <title>Test for Bug 303267</title>
14
  <script type="application/javascript"
15
          src="chrome://mochikit/content/MochiKit/packed.js"></script>
16
  <script type="application/javascript"
17
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
18
19
<body  xmlns="http://www.w3.org/1999/xhtml">
20
<a target="_blank"
21
   href="https://bugzilla.mozilla.org/show_bug.cgi?id=303267">Mozilla Bug 303267</a>
22
<p id="display"></p>
23
<div id="content" style="display: none">
24
25
</div>
26
<pre id="test">
27
</pre>
28
</body>
29
30
<script class="testbody" type="application/javascript">
31
<![CDATA[
32
33
/** Test for Bug 303267 **/
34
35
SimpleTest.waitForExplicitFinish();
36
window.open("bug303267_window.xul", "bug303267",
37
            "chrome,width=600,height=600");
38
39
]]>
40
</script>
41
42
</window>

Return to bug 303267