Bumping manifests a=b2g-bump
[gecko.git] / embedding / test / test_bug449141.html
blob7f40f7ae6175478387ed836feae2c24d16958db0
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=449141
5 -->
6 <head>
7 <title>Test for Bug 449141</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=449141">Mozilla Bug 449141</a>
13 <p id="display">
15 </p>
16 <pre id="results"></pre>
17 <div id="content" style="display: none">
18 <iframe src="bug449141_page.html" id="source"></iframe>
19 </div>
20 <pre id="test">
21 <script class="testbody" type="text/javascript">
22 /** Test for Bug 449141 **/
24 const Cc = SpecialPowers.Cc;
25 const Ci = SpecialPowers.Ci;
27 function getTempDir() {
28 return Cc["@mozilla.org/file/directory_service;1"]
29 .getService(Ci.nsIProperties)
30 .get("TmpD", Ci.nsILocalFile);
33 // STATE_STOP from nsIWebProgressListener.idl
34 const STATE_STOP = 0x00000010;
36 var progressListener = {
37 onProgressChange: function() {
38 /* Ignore progress callback */
40 onStateChange: function(aProgress, aRequest, aStateFlag, aStatus) {
41 if (aStateFlag & STATE_STOP) {
42 var dirExists = false;
43 var videoExists = false;
45 var videoFile = getTempDir();
46 videoFile.append(this.dirName);
47 dirExists = videoFile.exists();
48 videoFile.append("320x240.ogv");
49 videoExists = videoFile.exists();
50 this.folder.remove(true);
51 this.file.remove(false);
52 ok(dirExists, 'Directory containing video file should be created');
53 ok(videoExists, 'Video should be persisted with document');
54 SimpleTest.finish();
59 function persistDocument(aDoc) {
60 const nsIWBP = Ci.nsIWebBrowserPersist;
61 const persistFlags =
62 nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
63 | nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION
64 const encodingFlags =
65 nsIWBP.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES;
67 var ioService = Cc["@mozilla.org/network/io-service;1"]
68 .getService(Ci.nsIIOService);
70 var id = Math.round(Math.random() * 10000);
71 var dirName = "bug449141_serialized" + id;
72 progressListener.dirName = dirName;
74 var file = getTempDir();
75 file.append("bug449141-serialized" + id + ".html");
77 var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
78 .createInstance(Ci.nsIWebBrowserPersist);
79 persist.progressListener = progressListener;
80 persist.persistFlags = persistFlags;
81 const kWrapColumn = 80;
82 var folder = getTempDir();
83 folder.append(dirName);
84 progressListener.folder = folder;
85 progressListener.file = file;
86 persist.saveDocument(aDoc, ioService.newFileURI(file),
87 folder,
88 aDoc.contentType,
89 encodingFlags, kWrapColumn);
92 SimpleTest.waitForExplicitFinish();
94 addLoadEvent(function() {
95 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
96 var srcDoc = document.getElementById('source').contentDocument;
97 persistDocument(srcDoc);
98 });
99 </script>
100 </pre>
101 </body>
102 </html>