summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/bug582176_window.xul
blob: ad594ee0cff0eb5178634a5675c1d2bca82bb57f (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
<?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="nextTestAsync();"
        title="bug 582176 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[
  
    // Define the generator-iterator for the tests.
    var tests = testIterator();

    ////
    // Execute the next test in the generator function.
    //
    function nextTestAsync() {
      SimpleTest.executeSoon(tests.next.bind(tests));
    }

    ////
    // Generator function for test steps for bug 582176:
    // Description goes here.
    //
    function testIterator()
    {
      var browser = document.getElementById('content');
      browser.addEventListener("pageshow", nextTestAsync, true);

      enableBFCache(true);

      var notificationCount = 0;
      var observer = {
        observe: function(aSubject, aTopic, aData) {
          is(aSubject, browser.contentWindow,
             "correct subject");
          is(aTopic, "content-document-global-created",
             "correct topic");
          is(aData, "http://mochi.test:8888",
             "correct data");
          notificationCount++;
        }
      };

      os = Components.classes["@mozilla.org/observer-service;1"].
        getService(Components.interfaces.nsIObserverService);
      os.addObserver(observer, "content-document-global-created", false);

      browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html");
      yield undefined;
      is(browser.contentWindow.testVar, undefined,
         "variable unexpectedly there already");
      browser.contentWindow.wrappedJSObject.testVar = 1;
      is(notificationCount, 1, "Should notify on first navigation");

      browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html?2");
      yield undefined;
      is(browser.contentWindow.wrappedJSObject.testVar, undefined,
         "variable should no longer be there");
      is(notificationCount, 2, "Should notify on second navigation");

      browser.goBack();
      yield undefined;
      is(browser.contentWindow.wrappedJSObject.testVar, 1,
         "variable should still be there");
      is(notificationCount, 2, "Should not notify on back navigation");

      browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_xml.xml");
      yield undefined;
      is(browser.contentDocument.body.textContent, "xslt result",
         "Transform performed successfully");
      is(notificationCount, 3, "Should notify only once on XSLT navigation");

      os.removeObserver(observer, "content-document-global-created")

      // Tell the framework the test is finished.  Include the final 'yield' 
      // statement to prevent a StopIteration exception from being thrown.
      finish();
      yield undefined;
    }
    
  ]]></script>
  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
</window>