PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/embedding/test/test_bug449141.html

http://github.com/zpao/v8monkey
HTML | 106 lines | 89 code | 14 blank | 3 comment | 0 complexity | ccaa4d7dd6b9e1ed173a36f1d4443c5a MD5 | raw file
  1<!DOCTYPE HTML>
  2<html>
  3<!--
  4https://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">
 14
 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 **/
 23
 24netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 25const Cc = Components.classes;
 26const Ci = Components.interfaces;
 27
 28function getTempDir() {
 29    return Cc["@mozilla.org/file/directory_service;1"]
 30            .getService(Ci.nsIProperties)
 31            .get("TmpD", Ci.nsILocalFile);
 32}
 33
 34// STATE_STOP from nsIWebProgressListener.idl
 35const STATE_STOP = 0x00000010;
 36
 37var progressListener = {
 38  onProgressChange: function() {
 39    /* Ignore progress callback */
 40  },
 41  onStateChange: function(aProgress, aRequest, aStateFlag, aStatus) {
 42    if (aStateFlag & STATE_STOP) {
 43      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 44      var dirExists = false;
 45      var videoExists = false;
 46
 47      var videoFile = getTempDir();
 48      videoFile.append(this.dirName);
 49      dirExists = videoFile.exists();
 50      videoFile.append("320x240.ogv");
 51      videoExists = videoFile.exists();
 52      this.folder.remove(true);
 53      this.file.remove(false);
 54      ok(dirExists, 'Directory containing video file should be created');
 55      ok(videoExists, 'Video should be persisted with document');
 56      SimpleTest.finish();
 57    }    
 58  }
 59};
 60
 61function persistDocument(aDoc) {
 62    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 63
 64    const nsIWBP = Ci.nsIWebBrowserPersist;
 65    const persistFlags =
 66                  nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES
 67                | nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION
 68    const encodingFlags =
 69                  nsIWBP.ENCODE_FLAGS_ENCODE_BASIC_ENTITIES;
 70
 71    var ioService = Components.classes["@mozilla.org/network/io-service;1"]
 72                    .getService(Ci.nsIIOService);
 73
 74    var id = Math.round(Math.random() * 10000);
 75    var dirName = "bug449141_serialized" + id;
 76    progressListener.dirName = dirName;
 77
 78    var file = getTempDir();
 79    file.append("bug449141-serialized" + id + ".html");
 80
 81    var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
 82                    .createInstance(Ci.nsIWebBrowserPersist);
 83    persist.progressListener = progressListener;
 84    persist.persistFlags = persistFlags;
 85    const kWrapColumn = 80;
 86    var folder = getTempDir();
 87    folder.append(dirName);
 88    progressListener.folder = folder;
 89    progressListener.file = file;
 90    persist.saveDocument(aDoc, ioService.newFileURI(file),
 91                         folder,
 92                         aDoc.contentType,
 93                         encodingFlags, kWrapColumn);
 94}
 95
 96SimpleTest.waitForExplicitFinish();
 97
 98addLoadEvent(function() {
 99    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
100    var srcDoc = document.getElementById('source').contentDocument;
101    persistDocument(srcDoc);
102});
103</script>
104</pre>
105</body>
106</html>