summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/test_bug846906.xhtml
blob: 74bfdf70367e2c987e03e845e77e66500f514c70 (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
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=846906
-->
<window title="Mozilla Bug 846906"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[

  /** Test for Bug 846906 */
  SimpleTest.waitForExplicitFinish();

  var appShellService = SpecialPowers.Services.appShell;
  ok(appShellService, "Should be able to get app shell service");

  var windowlessBrowser = appShellService.createWindowlessBrowser();
  ok(windowlessBrowser, "Should be able to create windowless browser");

  ok(windowlessBrowser instanceof Ci.nsIWindowlessBrowser,
     "Windowless browser should implement nsIWindowlessBrowser");

  var webNavigation = windowlessBrowser.QueryInterface(Ci.nsIWebNavigation);
  ok(webNavigation, "Windowless browser should implement nsIWebNavigation");

  var interfaceRequestor = windowlessBrowser.QueryInterface(Ci.nsIInterfaceRequestor);
  ok(interfaceRequestor, "Should be able to query interface requestor interface");

  var docShell = windowlessBrowser.docShell;
  ok(docShell, "Should be able to get doc shell interface");

  var document = webNavigation.document;
  ok(document, "Should be able to get document");

  var iframe = document.createXULElement("iframe");
  ok(iframe, "Should be able to create iframe");

  iframe.onload = function () {
    ok(true, "Should receive initial onload event");

    iframe.onload = function () {
        ok(true, "Should receive onload event");

        var contentDocument = iframe.contentDocument;
        ok(contentDocument, "Should be able to get content document");

        var div = contentDocument.getElementById("div1");
        ok(div, "Should be able to get element by id");

        var rect = div.getBoundingClientRect();
        ok(rect, "Should be able to get bounding client rect");

        // xxx: can we do better than hardcoding these values here?
        is(rect.width, 1024);
        is(rect.height, 768);

        windowlessBrowser.close();

        // Once the browser is closed, nsIWebNavigation and
        // nsIInterfaceRequestor methods should no longer be accessible.
        try {
          windowlessBrowser.getInterface(Ci.nsIDocShell);
          ok(false);
        } catch (e) {
          is(e.result, Cr.NS_ERROR_NULL_POINTER);
        }

        try {
          windowlessBrowser.document;
          ok(false);
        } catch (e) {
          is(e.result, Cr.NS_ERROR_NULL_POINTER);
        }

        SimpleTest.finish();
    };
    iframe.setAttribute("src", "http://mochi.test:8888/chrome/docshell/test/chrome/bug846906.html");
  };
  document.documentElement.appendChild(iframe);

  ]]>
  </script>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=846906"
     target="_blank">Mozilla Bug 846906</a>
  </body>
</window>