1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
3 <title> nsIWebBrowserPersist Interface Test</title>
5 Descrpt: This Test Case will serve two purposes.
6 1. It tests saveURI method and
7 2. It checks the attribute currentState against PERSIST_STATE_READY,
8 PERSIST_STATE_SAVING, PERSIST_STATE_FINISHED.
9 Author: dsirnapalli@netscape.com
10 Revs: 10.03.01 - Created
11 Last Run On: 10.24.01.
13 <!-- ***** BEGIN LICENSE BLOCK *****
14 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
16 - The contents of this file are subject to the Mozilla Public License Version
17 - 1.1 (the "License"); you may not use this file except in compliance with
18 - the License. You may obtain a copy of the License at
19 - http://www.mozilla.org/MPL/
21 - Software distributed under the License is distributed on an "AS IS" basis,
22 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
23 - for the specific language governing rights and limitations under the
26 - The Original Code is Mozilla Communicator Test Cases.
28 - The Initial Developer of the Original Code is
29 - Netscape Communications Corporation.
30 - Portions created by the Initial Developer are Copyright (C) 1999
31 - the Initial Developer. All Rights Reserved.
34 - dsirnapalli@netscape.com
36 - Alternatively, the contents of this file may be used under the terms of
37 - either the GNU General Public License Version 2 or later (the "GPL"), or
38 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
39 - in which case the provisions of the GPL or the LGPL are applicable instead
40 - of those above. If you wish to allow use of your version of this file only
41 - under the terms of either the GPL or the LGPL, and not to allow others to
42 - use your version of this file under the terms of the MPL, indicate your
43 - decision by deleting the provisions above and replace them with the notice
44 - and other provisions required by the LGPL or the GPL. If you do not delete
45 - the provisions above, a recipient may use your version of this file under
46 - the terms of any one of the MPL, the GPL or the LGPL.
48 - ***** END LICENSE BLOCK ***** -->
52 <!-- script below is ngdriverspecific -->
53 <script TYPE="text/javascript" SRC="http://bubblegum/ngdriver/suites/testlib.js">
56 <script TYPE="text/javascript">
58 url = "http://www.mozilla.org";
59 file = "c:\\test1.htm";
60 astatus = new Array();
67 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
69 uri = Components.classes["@mozilla.org/network/standard-url;1"].
70 createInstance(Components.interfaces.nsIURI);
73 localFile = Components.classes["@mozilla.org/file/local;1"].
74 createInstance(Components.interfaces.nsILocalFile)
75 localFile.initWithPath(file)
77 persistListener = new PersistProgressListener;
78 persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
79 createInstance(Components.interfaces.nsIWebBrowserPersist);
81 persist.progressListener = persistListener;
82 persist.saveURI(uri, null, localFile);
83 //persist.cancelSave();
86 alert("Exception: " + e);
90 function setStatus(text)
96 function setProgress(current, max)
98 progress = current + " out of " + max;
101 function PersistProgressListener()
106 PersistProgressListener.prototype =
108 QueryInterface : function(aIID)
110 if(aIID.equals(Components.interfaces.nsIWebProgressListener))
112 throw Components.results.NS_NOINTERFACE;
123 // nsIWebProgressListener
124 onProgressChange : function (aWebProgress, aRequest,
125 aCurSelfProgress, aMaxSelfProgress,
126 aCurTotalProgress, aMaxTotalProgress)
128 setProgress(aCurTotalProgress, aMaxTotalProgress);
131 onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
134 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
135 if(persist.currentState == persist.PERSIST_STATE_READY)
137 persiststate = persiststate + "Persister is ready to save data." + "<br>";
139 else if(persist.currentState == persist.PERSIST_STATE_SAVING)
141 persiststate = persiststate + "Persister is saving data." + "<br>";
143 else if(persist.currentState == persist.PERSIST_STATE_FINISHED)
145 persiststate = persiststate + "Persister has finished saving data." + "<br>";
149 alert("Exception: " + e);
153 onLocationChange : function(aWebProgress, aRequest, aLocation)
157 onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
162 onSecurityChange : function(aWebProgress, aRequest, aState)
167 function constructResults()
170 results = results + "<html><br>";
171 results = results + "<b><u> Interface:nsIWebBrowserPersist</u></b><br>";
172 results = results + "<b><u>Method:saveURI()</u></b><br><br>";
173 results = results + "<b> Result: </b><br>";
174 results = results + "If " + "<b>" + file + "</b>" + " exist physically and if contains data then the Result is Pass" + "<br><br>";
175 results = results + "<b> Status: </b><br>";
176 for(i=0;i<astatus.length;i++)
177 results = results + astatus[i] + "<br>";
178 results = results + "<br>";
179 results = results + "<b> Progress: </b><br>";
180 results = results + progress + "<br><br>";
181 results = results + "<b><u>Attribute:currentState</u></b><br><br>";
182 results = results + "<b> State of Persist Object: </b><br>";
183 results = results + persiststate + "<br><br>";
185 results = results + "</html>";
187 displayResults(results);
190 function displayResults(results)
192 document.results.textarea.value = results;
193 if (top.name == "testWindow")
199 document.write(document.results.textarea.value);
207 <!-- form below is ngdriverspecific -->
208 <form name="results" action="/ngdriver/cgi-bin/writeresults.cgi" method="post">
209 <script TYPE="text/javascript">
210 document.write('<input name="resultsfile" type="hidden" value="' + window.opener.document.resultsform.resultsfile.value + '">');
212 <input type="hidden" name="textarea">
215 <script TYPE="text/javascript">
217 setTimeout("constructResults();", 3000);