gecko-dev/embedding/qa/jstests/nsIWebBrowserPersistTest1.txt
2004-08-25 23:02:50 +00:00

221 lines
6.5 KiB
Plaintext

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<title> nsIWebBrowserPersist Interface Test</title>
<!--
Descrpt: This Test Case will serve two purposes.
1. It tests saveURI method and
2. It checks the attribute currentState against PERSIST_STATE_READY,
PERSIST_STATE_SAVING, PERSIST_STATE_FINISHED.
Author: dsirnapalli@netscape.com
Revs: 10.03.01 - Created
Last Run On: 10.24.01.
-->
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Mozilla Communicator Test Cases.
-
- The Initial Developer of the Original Code is
- Netscape Communications Corporation.
- Portions created by the Initial Developer are Copyright (C) 1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- dsirnapalli@netscape.com
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<head>
<!-- script below is ngdriverspecific -->
<script TYPE="text/javascript" SRC="http://bubblegum/ngdriver/suites/testlib.js">
</script>
<script TYPE="text/javascript">
url = "http://www.mozilla.org";
file = "c:\\test1.htm";
astatus = new Array();
i = 0;
persiststate = "";
function saveURI()
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
uri = Components.classes["@mozilla.org/network/standard-url;1"].
createInstance(Components.interfaces.nsIURI);
uri.spec = url;
localFile = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile)
localFile.initWithPath(file)
persistListener = new PersistProgressListener;
persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
createInstance(Components.interfaces.nsIWebBrowserPersist);
persist.progressListener = persistListener;
persist.saveURI(uri, null, localFile);
//persist.cancelSave();
}
catch(e) {
alert("Exception: " + e);
}
}
function setStatus(text)
{
astatus[i] = text;
i++;
}
function setProgress(current, max)
{
progress = current + " out of " + max;
}
function PersistProgressListener()
{
this.init();
}
PersistProgressListener.prototype =
{
QueryInterface : function(aIID)
{
if(aIID.equals(Components.interfaces.nsIWebProgressListener))
return this;
throw Components.results.NS_NOINTERFACE;
},
init : function()
{
},
destroy : function()
{
},
// nsIWebProgressListener
onProgressChange : function (aWebProgress, aRequest,
aCurSelfProgress, aMaxSelfProgress,
aCurTotalProgress, aMaxTotalProgress)
{
setProgress(aCurTotalProgress, aMaxTotalProgress);
},
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if(persist.currentState == persist.PERSIST_STATE_READY)
{
persiststate = persiststate + "Persister is ready to save data." + "<br>";
}
else if(persist.currentState == persist.PERSIST_STATE_SAVING)
{
persiststate = persiststate + "Persister is saving data." + "<br>";
}
else if(persist.currentState == persist.PERSIST_STATE_FINISHED)
{
persiststate = persiststate + "Persister has finished saving data." + "<br>";
}
}
catch(e) {
alert("Exception: " + e);
}
},
onLocationChange : function(aWebProgress, aRequest, aLocation)
{
},
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
{
setStatus(aMessage);
},
onSecurityChange : function(aWebProgress, aRequest, aState)
{
}
}
function constructResults()
{
var results = "";
results = results + "<html><br>";
results = results + "<b><u> Interface:nsIWebBrowserPersist</u></b><br>";
results = results + "<b><u>Method:saveURI()</u></b><br><br>";
results = results + "<b> Result: </b><br>";
results = results + "If " + "<b>" + file + "</b>" + " exist physically and if contains data then the Result is Pass" + "<br><br>";
results = results + "<b> Status: </b><br>";
for(i=0;i<astatus.length;i++)
results = results + astatus[i] + "<br>";
results = results + "<br>";
results = results + "<b> Progress: </b><br>";
results = results + progress + "<br><br>";
results = results + "<b><u>Attribute:currentState</u></b><br><br>";
results = results + "<b> State of Persist Object: </b><br>";
results = results + persiststate + "<br><br>";
results = results + "</html>";
displayResults(results);
}
function displayResults(results)
{
document.results.textarea.value = results;
if (top.name == "testWindow")
{
fixSubmit();
}
else
{
document.write(document.results.textarea.value);
}
}
</script>
</head>
<body>
<!-- form below is ngdriverspecific -->
<form name="results" action="/ngdriver/cgi-bin/writeresults.cgi" method="post">
<script TYPE="text/javascript">
document.write('<input name="resultsfile" type="hidden" value="' + window.opener.document.resultsform.resultsfile.value + '">');
</script>
<input type="hidden" name="textarea">
</form>
<script TYPE="text/javascript">
saveURI();
setTimeout("constructResults();", 3000);
</script>
</body>
</html>