widget/tests/test_bug760802.xul

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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"/>
    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,&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;"/><br/>
    19   </body>
    21   <!-- test code goes here -->
    22   <script type="application/javascript"><![CDATA[
    23 SimpleTest.waitForExplicitFinish();
    25 const Cc = Components.classes;
    26 const Ci = Components.interfaces;
    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 }
    37 function getBaseWindowInterfaceFromDocShell(win) {
    38   return win.QueryInterface(Ci.nsIInterfaceRequestor)
    39     .getInterface(Ci.nsIWebNavigation)
    40     .QueryInterface(Ci.nsIDocShell)
    41     .QueryInterface(Ci.nsIBaseWindow);
    42 }
    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)
    56 var baseWindow = getBaseWindowInterface(this);
    57 var nativeHandle = baseWindow.nativeHandle;
    58 $("display").innerHTML = "found nativeHandle for this window: "+nativeHandle;
    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);
    64 ok(
    65   shouldThrowException(function(){docShell.nativeHandle;},
    66               Components.results.NS_ERROR_NOT_IMPLEMENTED),
    67   "nativeHandle should not be implemented for nsDocShell"
    68 );
    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");
    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");
    77 var dialog = win.openDialog("data:text/plain,this is an active window.", "_blank",
    78                             "chrome,dialog=yes,width=100,height=100");
    80 isnot(getBaseWindowInterface(dialog).nativeHandle, "",
    81       "the nativeHandle of a dialog should not be empty");
    83 dialog.close();
    85 todo(false, "the nativeHandle of a window without a mainWidget should be empty"); // how to build a window without a mainWidget ?
    87 SimpleTest.finish();
    88   ]]></script>
    89 </window>

mercurial