docshell/test/chrome/bug662200_window.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     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 662200 test">
    11   <script type="application/javascript"
    12   src="docshell_helpers.js">
    13   </script>
    14   <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
    15   <script type="application/javascript"><![CDATA[
    17     // Define the generator-iterator for the tests.
    18     var tests = testIterator();
    20     ////
    21     // Execute the next test in the generator function.
    22     //
    23     function nextTest() {
    24       tests.next();
    25     }
    27     ////
    28     // Generator function for test steps for bug 662200:  
    29     // Description goes here.
    30     //
    31     function testIterator()
    32     {
    33       // Load the first test page
    34       var navData = {
    35         uri: getHttpUrl("662200a.html"),
    36         eventsToListenFor: ["pageshow"],
    37         expectedEvents: [ {type: "pageshow", title: "A"} ],
    38         onNavComplete: nextTest
    39       };
    40       doPageNavigation(navData);
    41       yield undefined;
    43       // Load the second test page.
    44       navData = {
    45         eventsToListenFor: ["pageshow", "pagehide"],
    46         expectedEvents: [ {type: "pagehide", 
    47                            title: "A"},
    48                           {type: "pageshow", 
    49                            title: "B"} ],
    50         onNavComplete: nextTest
    51       }
    52       waitForPageEvents(navData);
    53       var link = TestWindow.getDocument().getElementById("link");
    54       var event = TestWindow.getDocument().createEvent("MouseEvents");
    55       event.initMouseEvent("click", true, true, TestWindow.getWindow(),
    56                            0, 0, 0, 0, 0, false, false, false, false, 0, null);
    57       link.dispatchEvent(event);
    58       yield undefined;
    60       // Load the third test page.
    61       navData = {
    62         eventsToListenFor: ["pageshow", "pagehide"],
    63         expectedEvents: [ {type: "pagehide", 
    64                            title: "B"},
    65                           {type: "pageshow", 
    66                            title: "C"} ],
    67         onNavComplete: nextTest
    68       };
    69       waitForPageEvents(navData);
    70       var link = TestWindow.getDocument().getElementById("link");
    71       var event = TestWindow.getDocument().createEvent("MouseEvents");
    72       event.initMouseEvent("click", true, true, TestWindow.getWindow(),
    73                            0, 0, 0, 0, 0, false, false, false, false, 0, null);
    74       link.dispatchEvent(event);
    75       yield undefined;
    77       // Go back.
    78       navData = {
    79         back: true,
    80         eventsToListenFor: ["pageshow", "pagehide"],
    81         expectedEvents: [ {type: "pagehide", 
    82                            title: "C"},
    83                           {type: "pageshow", 
    84                            title: "B"} ],
    85         onNavComplete: nextTest
    86       };
    87       doPageNavigation(navData);
    88       yield undefined;
    90       var Ci = Components.interfaces;
    91       var docshell = TestWindow.getWindow()
    92                                .QueryInterface(Ci.nsIInterfaceRequestor)
    93                                .getInterface(Ci.nsIWebNavigation)
    94                                .QueryInterface(Ci.nsIDocShell);
    95       var shistory = docshell.QueryInterface(Ci.nsIInterfaceRequestor)
    96                              .getInterface(Ci.nsISHistory)
    97                              .QueryInterface(Ci.nsIWebNavigation);
    99       // Reload.
   100       navData = {
   101         eventsToListenFor: ["pageshow", "pagehide"],
   102         expectedEvents: [ {type: "pagehide", 
   103                            title: "B"},
   104                           {type: "pageshow", 
   105                            title: "B"} ],
   106         onNavComplete: nextTest
   107       };
   108       // Asking the docshell harness to reload for us will call reload on
   109       // nsDocShell which has different behavior than the reload on nsSHistory
   110       // so we call reload explicitly here
   111       waitForPageEvents(navData);
   112       shistory.reload(0);
   113       yield undefined;
   115       // After this sequence of events, we should be able to go back and forward
   116       is(TestWindow.getBrowser().canGoBack, true, "Should be able to go back!");
   117       is(TestWindow.getBrowser().canGoForward, true, "Should be able to go forward!");
   118       is(shistory.requestedIndex, -1, "Requested index should be cleared!");
   120       // Tell the framework the test is finished.  Include the final 'yield' 
   121       // statement to prevent a StopIteration exception from being thrown.
   122       finish();
   123       yield undefined;
   124     }
   126   ]]></script>
   128   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   129 </window>

mercurial