mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-26 02:02:33 +00:00
203 lines
5.5 KiB
Plaintext
203 lines
5.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.
|
|
|
|
- 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
|
|
- Corp. Portions created by Netscape Communications Corp. are
|
|
- Copyright (C) 1999 Netscape Communications Corp. All
|
|
- Rights Reserved.
|
|
-
|
|
- Contributor(s):
|
|
-->
|
|
|
|
<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> |