gecko-dev/toolkit/components/windowcreator/test/test_bug293834.html
Brian Grinstead ede8c44ef2 Bug 1544322 - Part 2.1 - Remove the [type] attribute for one-liner <script> tags loading files in /tests/SimpleTest/ in everything except for dom/ r=bzbarsky
This excludes dom/, otherwise the file size is too large for phabricator to handle.

This is an autogenerated commit to handle scripts loading mochitest harness files, in
the simple case where the script src is on the same line as the tag.

This was generated with https://bug1544322.bmoattachments.org/attachment.cgi?id=9058170
using the `--part 2` argument.

Differential Revision: https://phabricator.services.mozilla.com/D27456

--HG--
extra : moz-landing-system : lando
2019-04-16 03:50:44 +00:00

131 lines
4.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=293834
-->
<head>
<title>Test for Bug 293834</title>
<script 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 (let i in textareas) {
doc.getElementById(textareas[i]).textContent += "form state";
}
for (let 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 (let 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 (let 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 SpecialPowers.Services.dirsvc.get("TmpD", Ci.nsIFile);
}
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, 0o400,
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 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, SpecialPowers.Services.io.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>