<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<title> nsIWebBrowserPersist Interface Test</title>
<!--
     Descrpt: This Test Case tests saveDocument method.
     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">
file = "c:\\test2.htm";
data = "c:\\test2_data";
astatus = new Array();
i = 0;

function saveDocument()
{
  try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

    localFile = Components.classes["@mozilla.org/file/local;1"]
               .createInstance(Components.interfaces.nsILocalFile);
    localFile.initWithPath(file)

    dataPath = Components.classes["@mozilla.org/file/local;1"]
              .createInstance(Components.interfaces.nsILocalFile)
    dataPath.initWithPath(data)

    persistListener = new PersistProgressListener;
    persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
             .createInstance(Components.interfaces.nsIWebBrowserPersist);

    persist.progressListener = persistListener;
    persist.saveDocument(document, localFile, dataPath);
    //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)
  {
  },

  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:saveDocument()</u></b><br><br>";
  results = results + "<b> Result: </b><br>";
  results = results + "If " + "<b>" + file + "</b>" + " exist physically and " + "<b><br>";
  results = results + "If " + data + "</b>" + " exist physically and if " + data +
                      " contains file1_htm, testlib.js, file_1.data folder 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>";
  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>

<p>This is nsIWebBrowserPersist Interface test case</p>
<p>This is the IFRAME used for testing</p>
<iframe id="frame1" width="100%" height="480" src="http://www.mozilla.org/"/>

<script TYPE="text/javascript">
setTimeout("saveDocument();", 2000);
setTimeout("constructResults();", 5000);
</script>

</body>
</html>