summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/bug662200_window.xhtml
blob: 7c6f656f261cb152258e75865813f4da98fc848a (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window id="303267Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="600"
        height="600"
        onload="setTimeout(runTest, 0);"
        title="bug 662200 test">

  <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js" />
  <script type="application/javascript" src="docshell_helpers.js" />
  <script type="application/javascript"><![CDATA[
    Services.prefs.setBoolPref("browser.navigation.requireUserInteraction", false);

    ////
    // Bug 662200
    //
    async function runTest()
    {
      // Load the first test page
      var navData = {
        uri: getHttpUrl("662200a.html"),
        eventsToListenFor: ["pageshow"],
        expectedEvents: [ {type: "pageshow", title: "A"} ],
      };
      await promisePageNavigation(navData);

      // Load the second test page.
      navData = {
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide",
                           title: "A"},
                          {type: "pageshow",
                           title: "B"} ],
      }
      let clicked = promisePageEvents(navData);
      SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
        var link = content.document.getElementById("link");
        var event = content.document.createEvent("MouseEvents");
        event.initMouseEvent("click", true, true, content,
                             0, 0, 0, 0, 0, false, false, false, false, 0, null);
        link.dispatchEvent(event);
      });
      await clicked;

      // Load the third test page.
      navData = {
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide",
                           title: "B"},
                          {type: "pageshow",
                           title: "C"} ],
      };
      clicked = promisePageEvents(navData);
      SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
        var link = content.document.getElementById("link");
        var event = content.document.createEvent("MouseEvents");
        event.initMouseEvent("click", true, true, content,
                             0, 0, 0, 0, 0, false, false, false, false, 0, null);
        link.dispatchEvent(event);
      });
      await clicked;

      // Go back.
      navData = {
        back: true,
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide",
                           title: "C"},
                          {type: "pageshow",
                           title: "B"} ],
      };
      await promisePageNavigation(navData);

      // Reload.
      navData = {
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide",
                           title: "B"},
                          {type: "pageshow",
                           title: "B"} ],
      };
      // Asking the docshell harness to reload for us will call reload on
      // nsDocShell which has different behavior than the reload on nsSHistory
      // so we call reloadCurrentEntry() (which is equivalent to reload(0) and
      // visible from JS) explicitly here.
      let reloaded = promisePageEvents(navData);
      if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
        TestWindow.getBrowser().browsingContext.sessionHistory.reloadCurrentEntry();
      } else {
        SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
          docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory.legacySHistory.reloadCurrentEntry();
        });
      }
      await reloaded;

      // After this sequence of events, we should be able to go back and forward
      is(TestWindow.getBrowser().canGoBack, true, "Should be able to go back!");
      is(TestWindow.getBrowser().canGoForward, true, "Should be able to go forward!");
      let requestedIndex;
      if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
        requestedIndex = TestWindow.getBrowser().browsingContext.sessionHistory.requestedIndex;
      } else {
        requestedIndex = await SpecialPowers.spawn(TestWindow.getBrowser(), [], () => {
          return docShell.sessionHistory.legacySHistory.requestedIndex;
        })
      }
      is(requestedIndex, -1, "Requested index should be cleared!");

      Services.prefs.clearUserPref("browser.navigation.requireUserInteraction");
      // Tell the framework the test is finished.
      finish();
    }

  ]]></script>

  <browser type="content" primary="true" flex="1" id="content" remote="true" />
</window>