diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /embedding/test/test_bug293834.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'embedding/test/test_bug293834.html')
-rw-r--r-- | embedding/test/test_bug293834.html | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/embedding/test/test_bug293834.html b/embedding/test/test_bug293834.html new file mode 100644 index 000000000..0747bf8b7 --- /dev/null +++ b/embedding/test/test_bug293834.html @@ -0,0 +1,137 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=293834 +--> +<head> + <title>Test for Bug 293834</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=293834">Mozilla Bug 293834</a> +<p id="display"> + +</p> +<pre id="results"></pre> +<div id="content" style="display: none"> + <iframe src="bug293834_form.html" id="source"></iframe> + <br> + <iframe id="dest"></iframe> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> +/** Test for Bug 293834 **/ + +var textareas = ["a-textbox", "a-prefilled-textbox"]; +var textboxes = ["a-text", "a-prefilled-text"]; + +function fillform(doc) { + for (var i in textareas) { + doc.getElementById(textareas[i]).textContent += "form state"; + } + for (var i in textboxes) { + doc.getElementById(textboxes[i]).value += "form state"; + } + doc.getElementById('a-checkbox').checked = true; + doc.getElementById("radioa").checked = true; + doc.getElementById("aselect").selectedIndex = 0; +} + +function checkform(doc) { + for (var i in textareas) { + var textContent = doc.getElementById(textareas[i]).textContent; + ok(/form\s+state/m.test(textContent), + "Modified textarea "+textareas[i]+" form state not preserved!"); + } + for (var i in textboxes) { + var value = doc.getElementById(textboxes[i]).value; + ok(/form\s+state/m.test(value), + "Modified textbox "+textboxes[i]+" form state not preserved!"); + } + ok(doc.getElementById('a-checkbox').checked, + "Modified checkbox checked state not preserved!"); + ok(doc.getElementById("radioa").checked, + "Modified radio checked state not preserved!"); + ok(doc.getElementById("aselect").selectedIndex == 0, + "Modified select selected index not preserved"); +} + +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; + +function getTempDir() { + return Cc["@mozilla.org/file/directory_service;1"] + .getService(Ci.nsIProperties) + .get("TmpD", Ci.nsILocalFile); +} + +function getFileContents(aFile) { + const PR_RDONLY = 0x01; + var fileStream = Cc["@mozilla.org/network/file-input-stream;1"] + .createInstance(Ci.nsIFileInputStream); + fileStream.init(aFile, PR_RDONLY, 0400, + Ci.nsIFileInputStream.DELETE_ON_CLOSE + | Ci.nsIFileInputStream.CLOSE_ON_EOF); + var inputStream = Cc["@mozilla.org/scriptableinputstream;1"] + .createInstance(Ci.nsIScriptableInputStream); + inputStream.init(fileStream); + var data = ""; + do { + var str = inputStream.read(inputStream.available()); + data += str; + } while(str.length > 0); + + return data; +} + +function persistDocument(aDoc) { + const nsIWBP = Ci.nsIWebBrowserPersist; + const persistFlags = + nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES + | nsIWBP.PERSIST_FLAGS_FROM_CACHE + | nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION + const encodingFlags = + nsIWBP.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES; + + var ioService = Cc["@mozilla.org/network/io-service;1"] + .getService(Ci.nsIIOService); + + + var file = getTempDir(); + file.append("bug293834-serialized.html"); + + var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] + .createInstance(Ci.nsIWebBrowserPersist); + persist.progressListener = null; + persist.persistFlags = persistFlags; + const kWrapColumn = 80; + var folder = getTempDir(); + folder.append("bug293834-serialized"); + persist.saveDocument(aDoc, ioService.newFileURI(file), + folder, + aDoc.contentType, + encodingFlags, kWrapColumn); + return getFileContents(file); +} + +SimpleTest.waitForExplicitFinish(); + +addLoadEvent(function() { + var srcDoc = document.getElementById('source').contentDocument; + fillform(srcDoc); + checkform(srcDoc); + var serializedString = persistDocument(srcDoc); + + // We can't access file:/// URLs directly for security reasons, + // so we have to parse the serialized content string indirectly + var targetDoc = document.getElementById('dest').contentDocument; + targetDoc.write(serializedString); + + checkform(targetDoc); + SimpleTest.finish(); +}); +</script> +</pre> +</body> +</html> |