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