widget/tests/test_bug466599.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.

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=466599
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 466599"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 9 onload="initAndRunTests()">
michael@0 10 <script type="application/javascript"
michael@0 11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 12
michael@0 13 <!-- test results are displayed in the html:body -->
michael@0 14 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none"></div>
michael@0 17 <pre id="test"></pre>
michael@0 18 </body>
michael@0 19
michael@0 20 <!-- test code goes here -->
michael@0 21 <script class="testbody" type="application/javascript">
michael@0 22 <![CDATA[
michael@0 23
michael@0 24 /** Test for Bug 466599 **/
michael@0 25
michael@0 26 function getLoadContext() {
michael@0 27 const Ci = Components.interfaces;
michael@0 28 return window.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 29 .getInterface(Ci.nsIWebNavigation)
michael@0 30 .QueryInterface(Ci.nsILoadContext);
michael@0 31 }
michael@0 32
michael@0 33 function copyToClipboard(txt)
michael@0 34 {
michael@0 35 var clipid = Components.interfaces.nsIClipboard;
michael@0 36 var clip =
michael@0 37 Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(clipid);
michael@0 38 if (!clip)
michael@0 39 return false;
michael@0 40 var trans =
michael@0 41 Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
michael@0 42 if (!trans)
michael@0 43 return false;
michael@0 44 trans.init(getLoadContext());
michael@0 45 trans.addDataFlavor('text/html');
michael@0 46 var str =
michael@0 47 Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
michael@0 48 var copytext = txt;
michael@0 49 str.data = copytext;
michael@0 50 trans.setTransferData("text/html",str,copytext.length*2);
michael@0 51 if (!clip)
michael@0 52 return false;
michael@0 53 clip.setData(trans,null,clipid.kGlobalClipboard);
michael@0 54 return true;
michael@0 55 }
michael@0 56
michael@0 57 function readFromClipboard()
michael@0 58 {
michael@0 59 var clipid = Components.interfaces.nsIClipboard;
michael@0 60 var clip =
michael@0 61 Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(clipid);
michael@0 62 if (!clip)
michael@0 63 return;
michael@0 64 var trans =
michael@0 65 Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
michael@0 66 if (!trans)
michael@0 67 return;
michael@0 68 trans.init(getLoadContext());
michael@0 69 trans.addDataFlavor('text/html');
michael@0 70 clip.getData(trans,clipid.kGlobalClipboard);
michael@0 71 var str = new Object();
michael@0 72 var strLength = new Object();
michael@0 73 trans.getTransferData("text/html",str,strLength);
michael@0 74 if (str)
michael@0 75 str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
michael@0 76 if (str)
michael@0 77 pastetext = str.data.substring(0,strLength.value / 2);
michael@0 78 return pastetext;
michael@0 79 }
michael@0 80
michael@0 81 function encodeHtmlEntities(s)
michael@0 82 {
michael@0 83 var result = '';
michael@0 84 for (var i = 0; i < s.length; i++) {
michael@0 85 var c = s.charAt(i);
michael@0 86 result += {'<':'&lt;', '>':'&gt;', '&':'&amp;', '"':'&quot;'}[c] || c;
michael@0 87 }
michael@0 88 return result;
michael@0 89 }
michael@0 90
michael@0 91 function initAndRunTests()
michael@0 92 {
michael@0 93 var source = '<p>Lorem ipsum</p>';
michael@0 94 var expect = new RegExp('<html>.*charset=utf-8.*' + source + '.*</html>', 'im');
michael@0 95
michael@0 96 var result = copyToClipboard(source);
michael@0 97 ok(result, "copied HTML data to system pasteboard");
michael@0 98
michael@0 99 result = readFromClipboard();
michael@0 100 ok(expect.test(result), "data on system pasteboard is wrapped with charset metadata");
michael@0 101
michael@0 102 $("display").innerHTML =
michael@0 103 '<em>source:</em> <pre>' + encodeHtmlEntities(source) + '</pre><br/>' +
michael@0 104 '<em>result:</em> <pre>' + encodeHtmlEntities(result) + '</pre>';
michael@0 105 }
michael@0 106
michael@0 107 ]]>
michael@0 108 </script>
michael@0 109 </window>

mercurial