embedding/test/test_bug293834.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=293834
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 293834</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=293834">Mozilla Bug 293834</a>
michael@0 13 <p id="display">
michael@0 14
michael@0 15 </p>
michael@0 16 <pre id="results"></pre>
michael@0 17 <div id="content" style="display: none">
michael@0 18 <iframe src="bug293834_form.html" id="source"></iframe>
michael@0 19 <br>
michael@0 20 <iframe id="dest"></iframe>
michael@0 21 </div>
michael@0 22 <pre id="test">
michael@0 23 <script class="testbody" type="text/javascript">
michael@0 24 /** Test for Bug 293834 **/
michael@0 25
michael@0 26 var textareas = ["a-textbox", "a-prefilled-textbox"];
michael@0 27 var textboxes = ["a-text", "a-prefilled-text"];
michael@0 28
michael@0 29 function fillform(doc) {
michael@0 30 for (var i in textareas) {
michael@0 31 doc.getElementById(textareas[i]).textContent += "form state";
michael@0 32 }
michael@0 33 for (var i in textboxes) {
michael@0 34 doc.getElementById(textboxes[i]).value += "form state";
michael@0 35 }
michael@0 36 doc.getElementById('a-checkbox').checked = true;
michael@0 37 doc.getElementById("radioa").checked = true;
michael@0 38 doc.getElementById("aselect").selectedIndex = 0;
michael@0 39 }
michael@0 40
michael@0 41 function checkform(doc) {
michael@0 42 for (var i in textareas) {
michael@0 43 var textContent = doc.getElementById(textareas[i]).textContent;
michael@0 44 ok(/form\s+state/m.test(textContent),
michael@0 45 "Modified textarea "+textareas[i]+" form state not preserved!");
michael@0 46 }
michael@0 47 for (var i in textboxes) {
michael@0 48 var value = doc.getElementById(textboxes[i]).value;
michael@0 49 ok(/form\s+state/m.test(value),
michael@0 50 "Modified textbox "+textboxes[i]+" form state not preserved!");
michael@0 51 }
michael@0 52 ok(doc.getElementById('a-checkbox').checked,
michael@0 53 "Modified checkbox checked state not preserved!");
michael@0 54 ok(doc.getElementById("radioa").checked,
michael@0 55 "Modified radio checked state not preserved!");
michael@0 56 ok(doc.getElementById("aselect").selectedIndex == 0,
michael@0 57 "Modified select selected index not preserved");
michael@0 58 }
michael@0 59
michael@0 60 const Cc = SpecialPowers.Cc;
michael@0 61 const Ci = SpecialPowers.Ci;
michael@0 62
michael@0 63 function getTempDir() {
michael@0 64 return Cc["@mozilla.org/file/directory_service;1"]
michael@0 65 .getService(Ci.nsIProperties)
michael@0 66 .get("TmpD", Ci.nsILocalFile);
michael@0 67 }
michael@0 68
michael@0 69 function getFileContents(aFile) {
michael@0 70 const PR_RDONLY = 0x01;
michael@0 71 var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]
michael@0 72 .createInstance(Ci.nsIFileInputStream);
michael@0 73 fileStream.init(aFile, PR_RDONLY, 0400,
michael@0 74 Ci.nsIFileInputStream.DELETE_ON_CLOSE
michael@0 75 | Ci.nsIFileInputStream.CLOSE_ON_EOF);
michael@0 76 var inputStream = Cc["@mozilla.org/scriptableinputstream;1"]
michael@0 77 .createInstance(Ci.nsIScriptableInputStream);
michael@0 78 inputStream.init(fileStream);
michael@0 79 var data = "";
michael@0 80 do {
michael@0 81 var str = inputStream.read(inputStream.available());
michael@0 82 data += str;
michael@0 83 } while(str.length > 0);
michael@0 84
michael@0 85 return data;
michael@0 86 }
michael@0 87
michael@0 88 function persistDocument(aDoc) {
michael@0 89 const nsIWBP = Ci.nsIWebBrowserPersist;
michael@0 90 const persistFlags =
michael@0 91 nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
michael@0 92 | nsIWBP.PERSIST_FLAGS_FROM_CACHE
michael@0 93 | nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION
michael@0 94 const encodingFlags =
michael@0 95 nsIWBP.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES;
michael@0 96
michael@0 97 var ioService = Cc["@mozilla.org/network/io-service;1"]
michael@0 98 .getService(Ci.nsIIOService);
michael@0 99
michael@0 100
michael@0 101 var file = getTempDir();
michael@0 102 file.append("bug293834-serialized.html");
michael@0 103
michael@0 104 var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
michael@0 105 .createInstance(Ci.nsIWebBrowserPersist);
michael@0 106 persist.progressListener = null;
michael@0 107 persist.persistFlags = persistFlags;
michael@0 108 const kWrapColumn = 80;
michael@0 109 var folder = getTempDir();
michael@0 110 folder.append("bug293834-serialized");
michael@0 111 persist.saveDocument(aDoc, ioService.newFileURI(file),
michael@0 112 folder,
michael@0 113 aDoc.contentType,
michael@0 114 encodingFlags, kWrapColumn);
michael@0 115 return getFileContents(file);
michael@0 116 }
michael@0 117
michael@0 118 SimpleTest.waitForExplicitFinish();
michael@0 119
michael@0 120 addLoadEvent(function() {
michael@0 121 var srcDoc = document.getElementById('source').contentDocument;
michael@0 122 fillform(srcDoc);
michael@0 123 checkform(srcDoc);
michael@0 124 var serializedString = persistDocument(srcDoc);
michael@0 125
michael@0 126 // We can't access file:/// URLs directly for security reasons,
michael@0 127 // so we have to parse the serialized content string indirectly
michael@0 128 var targetDoc = document.getElementById('dest').contentDocument;
michael@0 129 targetDoc.write(serializedString);
michael@0 130
michael@0 131 checkform(targetDoc);
michael@0 132 SimpleTest.finish();
michael@0 133 });
michael@0 134 </script>
michael@0 135 </pre>
michael@0 136 </body>
michael@0 137 </html>

mercurial