1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/test_bug760802.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=760802 1.9 +--> 1.10 +<window title="Mozilla Bug 760802" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <!-- test results are displayed in the html:body --> 1.15 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.16 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=760802" 1.17 + target="_blank">Mozilla Bug 760802</a> 1.18 + <p id="display"></p> 1.19 + <div id="content" style="display: none"/> 1.20 + <iframe id="iframe_not_editable" width="300" height="150" 1.21 + src="data:text/html,<html><body></body></html>"/><br/> 1.22 + </body> 1.23 + 1.24 + <!-- test code goes here --> 1.25 + <script type="application/javascript"><![CDATA[ 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 +const Cc = Components.classes; 1.29 +const Ci = Components.interfaces; 1.30 + 1.31 +function getBaseWindowInterface(win) { 1.32 + return win.QueryInterface(Ci.nsIInterfaceRequestor) 1.33 + .getInterface(Ci.nsIWebNavigation) 1.34 + .QueryInterface(Ci.nsIDocShellTreeItem) 1.35 + .treeOwner 1.36 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.37 + .nsIBaseWindow; 1.38 +} 1.39 + 1.40 +function getBaseWindowInterfaceFromDocShell(win) { 1.41 + return win.QueryInterface(Ci.nsIInterfaceRequestor) 1.42 + .getInterface(Ci.nsIWebNavigation) 1.43 + .QueryInterface(Ci.nsIDocShell) 1.44 + .QueryInterface(Ci.nsIBaseWindow); 1.45 +} 1.46 + 1.47 +function shouldThrowException(fun, exception) { 1.48 + try { 1.49 + fun.call(); 1.50 + return false; 1.51 + } catch (e) { 1.52 + $("display").innerHTML += "<br/>OK thrown: "+e.message; 1.53 + return (e instanceof Components.Exception && 1.54 + e.result === exception) 1.55 + } 1.56 +} 1.57 +function doesntThrowException(fun) !shouldThrowException(fun) 1.58 + 1.59 +var baseWindow = getBaseWindowInterface(this); 1.60 +var nativeHandle = baseWindow.nativeHandle; 1.61 +$("display").innerHTML = "found nativeHandle for this window: "+nativeHandle; 1.62 + 1.63 +var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); 1.64 +var win = wm.getMostRecentWindow("navigator:browser"); 1.65 +var docShell = getBaseWindowInterfaceFromDocShell(win); 1.66 + 1.67 +ok( 1.68 + shouldThrowException(function(){docShell.nativeHandle;}, 1.69 + Components.results.NS_ERROR_NOT_IMPLEMENTED), 1.70 + "nativeHandle should not be implemented for nsDocShell" 1.71 +); 1.72 + 1.73 +ok(typeof(nativeHandle) === "string", "nativeHandle should be a string"); 1.74 +ok(nativeHandle.match(/^0x[0-9a-f]+$/), "nativeHandle should have a memory address format"); 1.75 + 1.76 +var iWin = document.getElementById("iframe_not_editable").contentWindow; 1.77 +is(getBaseWindowInterface(iWin).nativeHandle, nativeHandle, 1.78 + "the nativeHandle of an iframe should be its parent's nativeHandle"); 1.79 + 1.80 +var dialog = win.openDialog("data:text/plain,this is an active window.", "_blank", 1.81 + "chrome,dialog=yes,width=100,height=100"); 1.82 + 1.83 +isnot(getBaseWindowInterface(dialog).nativeHandle, "", 1.84 + "the nativeHandle of a dialog should not be empty"); 1.85 + 1.86 +dialog.close(); 1.87 + 1.88 +todo(false, "the nativeHandle of a window without a mainWidget should be empty"); // how to build a window without a mainWidget ? 1.89 + 1.90 +SimpleTest.finish(); 1.91 + ]]></script> 1.92 +</window>