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