|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=760802 |
|
6 --> |
|
7 <window title="Mozilla Bug 760802" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760802" |
|
14 target="_blank">Mozilla Bug 760802</a> |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"/> |
|
17 <iframe id="iframe_not_editable" width="300" height="150" |
|
18 src="data:text/html,<html><body></body></html>"/><br/> |
|
19 </body> |
|
20 |
|
21 <!-- test code goes here --> |
|
22 <script type="application/javascript"><![CDATA[ |
|
23 SimpleTest.waitForExplicitFinish(); |
|
24 |
|
25 const Cc = Components.classes; |
|
26 const Ci = Components.interfaces; |
|
27 |
|
28 function getBaseWindowInterface(win) { |
|
29 return win.QueryInterface(Ci.nsIInterfaceRequestor) |
|
30 .getInterface(Ci.nsIWebNavigation) |
|
31 .QueryInterface(Ci.nsIDocShellTreeItem) |
|
32 .treeOwner |
|
33 .QueryInterface(Ci.nsIInterfaceRequestor) |
|
34 .nsIBaseWindow; |
|
35 } |
|
36 |
|
37 function getBaseWindowInterfaceFromDocShell(win) { |
|
38 return win.QueryInterface(Ci.nsIInterfaceRequestor) |
|
39 .getInterface(Ci.nsIWebNavigation) |
|
40 .QueryInterface(Ci.nsIDocShell) |
|
41 .QueryInterface(Ci.nsIBaseWindow); |
|
42 } |
|
43 |
|
44 function shouldThrowException(fun, exception) { |
|
45 try { |
|
46 fun.call(); |
|
47 return false; |
|
48 } catch (e) { |
|
49 $("display").innerHTML += "<br/>OK thrown: "+e.message; |
|
50 return (e instanceof Components.Exception && |
|
51 e.result === exception) |
|
52 } |
|
53 } |
|
54 function doesntThrowException(fun) !shouldThrowException(fun) |
|
55 |
|
56 var baseWindow = getBaseWindowInterface(this); |
|
57 var nativeHandle = baseWindow.nativeHandle; |
|
58 $("display").innerHTML = "found nativeHandle for this window: "+nativeHandle; |
|
59 |
|
60 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); |
|
61 var win = wm.getMostRecentWindow("navigator:browser"); |
|
62 var docShell = getBaseWindowInterfaceFromDocShell(win); |
|
63 |
|
64 ok( |
|
65 shouldThrowException(function(){docShell.nativeHandle;}, |
|
66 Components.results.NS_ERROR_NOT_IMPLEMENTED), |
|
67 "nativeHandle should not be implemented for nsDocShell" |
|
68 ); |
|
69 |
|
70 ok(typeof(nativeHandle) === "string", "nativeHandle should be a string"); |
|
71 ok(nativeHandle.match(/^0x[0-9a-f]+$/), "nativeHandle should have a memory address format"); |
|
72 |
|
73 var iWin = document.getElementById("iframe_not_editable").contentWindow; |
|
74 is(getBaseWindowInterface(iWin).nativeHandle, nativeHandle, |
|
75 "the nativeHandle of an iframe should be its parent's nativeHandle"); |
|
76 |
|
77 var dialog = win.openDialog("data:text/plain,this is an active window.", "_blank", |
|
78 "chrome,dialog=yes,width=100,height=100"); |
|
79 |
|
80 isnot(getBaseWindowInterface(dialog).nativeHandle, "", |
|
81 "the nativeHandle of a dialog should not be empty"); |
|
82 |
|
83 dialog.close(); |
|
84 |
|
85 todo(false, "the nativeHandle of a window without a mainWidget should be empty"); // how to build a window without a mainWidget ? |
|
86 |
|
87 SimpleTest.finish(); |
|
88 ]]></script> |
|
89 </window> |