4 https://bugzilla.mozilla.org/show_bug.cgi?id=293834
7 <title>Test for Bug
293834</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=293834">Mozilla Bug
293834</a>
17 <pre id=
"results"></pre>
18 <div id=
"content" style=
"display: none">
19 <iframe src=
"bug293834_form.html" id=
"source"></iframe>
21 <iframe id=
"dest"></iframe>
24 <script class=
"testbody" type=
"text/javascript">
25 /** Test for Bug
293834 **/
27 var textareas = [
"a-textbox",
"a-prefilled-textbox"];
28 var textboxes = [
"a-text",
"a-prefilled-text"];
30 function fillform(doc) {
31 for (var i in textareas) {
32 doc.getElementById(textareas[i]).textContent +=
"form state";
34 for (var i in textboxes) {
35 doc.getElementById(textboxes[i]).value +=
"form state";
37 doc.getElementById('a-checkbox').checked = true;
38 doc.getElementById(
"radioa").checked = true;
39 doc.getElementById(
"aselect").selectedIndex =
0;
42 function checkform(doc) {
43 for (var i in textareas) {
44 var textContent = doc.getElementById(textareas[i]).textContent;
45 ok(/form state/.test(textContent),
46 "Modified textarea "+textareas[i]+
" form state not preserved!");
48 for (var i in textboxes) {
49 var value = doc.getElementById(textboxes[i]).value;
50 ok(/form state/.test(value),
51 "Modified textbox "+textboxes[i]+
" form state not preserved!");
53 ok(doc.getElementById('a-checkbox').checked,
54 "Modified checkbox checked state not preserved!");
55 ok(doc.getElementById(
"radioa").checked,
56 "Modified radio checked state not preserved!");
57 ok(doc.getElementById(
"aselect").selectedIndex ==
0,
58 "Modified select selected index not preserved");
61 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
62 const Cc = Components.classes;
63 const Ci = Components.interfaces;
65 function getTempDir() {
66 return Cc[
"@mozilla.org/file/directory_service;1"]
67 .getService(Ci.nsIProperties)
68 .get(
"TmpD", Ci.nsILocalFile);
71 function getFileContents(aFile) {
72 const PR_RDONLY =
0x01;
73 var fileStream = Cc[
"@mozilla.org/network/file-input-stream;1"]
74 .createInstance(Ci.nsIFileInputStream);
75 fileStream.init(aFile, PR_RDONLY,
0400,
76 Ci.nsIFileInputStream.DELETE_ON_CLOSE
77 | Ci.nsIFileInputStream.CLOSE_ON_EOF);
78 var inputStream = Cc[
"@mozilla.org/scriptableinputstream;1"]
79 .createInstance(Ci.nsIScriptableInputStream);
80 inputStream.init(fileStream);
83 var str = inputStream.read(inputStream.available());
85 } while(str.length
> 0);
90 function persistDocument(aDoc) {
91 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
93 const nsIWBP = Ci.nsIWebBrowserPersist;
95 nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
96 | nsIWBP.PERSIST_FLAGS_FROM_CACHE
97 | nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION
99 nsIWBP.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES;
101 var ioService = Components.classes[
"@mozilla.org/network/io-service;1"]
102 .getService(Ci.nsIIOService);
105 var file = getTempDir();
106 file.append(
"bug293834-serialized.html");
108 var persist = Cc[
"@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
109 .createInstance(Ci.nsIWebBrowserPersist);
110 persist.progressListener = null;
111 persist.persistFlags = persistFlags;
112 const kWrapColumn =
80;
113 var folder = getTempDir();
114 folder.append(
"bug293834-serialized");
115 persist.saveDocument(aDoc, ioService.newFileURI(file),
118 encodingFlags, kWrapColumn);
119 return getFileContents(file);
122 SimpleTest.waitForExplicitFinish();
124 addLoadEvent(function() {
125 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
126 var srcDoc = document.getElementById('source').contentDocument;
129 var serializedString = persistDocument(srcDoc);
131 // We can't access file:/// URLs directly for security reasons,
132 // so we have to parse the serialized content string indirectly
133 var targetDoc = document.getElementById('dest').contentDocument;
134 targetDoc.write(serializedString);
136 checkform(targetDoc);