Back to index

lightning-sunbird  0.9+nobinonly
nsIWebProg.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   David Epstein <depstein@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 // nsiWebProg.cpp : implementation file
00040 //
00041 
00042 #include "Stdafx.h"
00043 #include "TestEmbed.h"
00044 #include "nsIWebProg.h"
00045 #include "Tests.h"
00046 #include "QaUtils.h"
00047 #include "BrowserFrm.h"
00048 #include "BrowserImpl.h"
00049 #include "BrowserView.h"
00050 #include "domwindow.h"
00051 #include "WebProgDlg.h"
00052 
00053 #ifdef _DEBUG
00054 #define new DEBUG_NEW
00055 #undef THIS_FILE
00056 static char THIS_FILE[] = __FILE__;
00057 #endif
00058 
00060 // CnsiWebProg
00061 
00062 // constructor for CnsiWebProg
00063 CnsiWebProg::CnsiWebProg(nsIWebBrowser *mWebBrowser, 
00064                                            CBrowserImpl *mpBrowserImpl)
00065 {
00066        qaWebBrowser = mWebBrowser;
00067        qaBrowserImpl = mpBrowserImpl;
00068 }
00069 
00070 // destructor for CnsiWebProg
00071 CnsiWebProg::~CnsiWebProg()
00072 {
00073 }
00074 
00075        // nsIWebProgress test cases
00076 
00077               // get webProg object
00078 nsIWebProgress * CnsiWebProg::GetWebProgObject()
00079 {
00080        nsCOMPtr<nsIInterfaceRequestor> qaIReq(do_QueryInterface(qaWebBrowser));
00081        nsCOMPtr<nsIWebProgress> qaWebProgress(do_GetInterface(qaIReq));
00082 
00083        if (!qaWebProgress) {
00084               QAOutput("Didn't get web progress object.", 2);
00085               return NULL;
00086        }
00087        else {
00088               QAOutput("We got web progress object.", 1);
00089               return (qaWebProgress);
00090        }
00091 }
00092 
00093 void CnsiWebProg::AddWebProgLstnr(PRUint32 theFlag, PRInt16 displayMode)
00094 {
00095        nsCAutoString flagName(NS_LITERAL_CSTRING("xxxx"));
00096 
00097        ConvertWPFlagToString(theFlag, flagName);
00098 
00099                      // addWebProgListener
00100        qaWebProgress = GetWebProgObject();
00101        nsCOMPtr<nsIWebProgressListener> listener(NS_STATIC_CAST(nsIWebProgressListener*, qaBrowserImpl));
00102        rv = qaWebProgress->AddProgressListener(listener, theFlag);
00103 //     StoreWebProgFlag(theFlag);
00104        RvTestResult(rv, "nsIWebProgress::AddProgressListener() test", displayMode);
00105        RvTestResultDlg(rv, "nsIWebProgress::AddProgressListener() test", true);
00106        FormatAndPrintOutput("WebProgressListener flag = ", flagName, displayMode);
00107 }
00108 
00109 void CnsiWebProg::RemoveWebProgLstnr(PRInt16 displayMode)
00110 {
00111               // removeWebProgListener
00112        qaWebProgress = GetWebProgObject();
00113        nsCOMPtr<nsIWebProgressListener> listener(NS_STATIC_CAST(nsIWebProgressListener*, qaBrowserImpl));
00114        rv = qaWebProgress->RemoveProgressListener(listener);
00115        RvTestResult(rv, "nsIWebProgress::RemoveProgressListener() test", displayMode);
00116        RvTestResultDlg(rv, "nsIWebProgress::RemoveProgressListener() test");
00117 }
00118 
00119 void CnsiWebProg::GetTheDOMWindow(PRInt16 displayMode)
00120 {
00121               // getTheDOMWindow
00122        qaWebProgress = GetWebProgObject();
00123        nsCOMPtr<nsIDOMWindow> qaDOMWindow;
00124        rv = qaWebProgress->GetDOMWindow(getter_AddRefs(qaDOMWindow));
00125        RvTestResult(rv, "nsIWebProgress::GetDOMWindow() test", displayMode);
00126        RvTestResultDlg(rv, "nsIWebProgress::GetDOMWindow() test");
00127        if (!qaDOMWindow)
00128               QAOutput("Didn't get DOM Window object.", displayMode);
00129 }
00130 
00131 void CnsiWebProg::GetIsLoadingDocTest(PRInt16 displayMode)
00132 {
00133        PRBool docLoading;
00134        qaWebProgress = GetWebProgObject();
00135        rv = qaWebProgress->GetIsLoadingDocument(&docLoading);
00136        RvTestResult(rv, "nsIWebProgress::GetisLoadingDocument() test", displayMode);
00137        RvTestResultDlg(rv, "nsIWebProgress::GetisLoadingDocument() test");
00138        FormatAndPrintOutput("GetisLoadingDocument return value = ", docLoading, displayMode);
00139 }
00140 
00141 void CnsiWebProg::ConvertWPFlagToString(PRUint32 theFlag,
00142                                                                       nsCAutoString& flagName)
00143 {
00144        switch(theFlag)
00145        {
00146        case nsIWebProgress::NOTIFY_STATE_REQUEST:
00147               flagName.AssignLiteral("NOTIFY_STATE_REQUEST");
00148               break;
00149        case nsIWebProgress::NOTIFY_STATE_DOCUMENT:
00150               flagName.AssignLiteral("NOTIFY_STATE_DOCUMENT");
00151               break;
00152        case nsIWebProgress::NOTIFY_STATE_NETWORK:
00153               flagName.AssignLiteral("NOTIFY_STATE_NETWORK");
00154               break;
00155        case nsIWebProgress::NOTIFY_STATE_WINDOW:
00156               flagName.AssignLiteral("NOTIFY_STATE_WINDOW");
00157               break;
00158        case nsIWebProgress::NOTIFY_STATE_ALL:
00159               flagName.AssignLiteral("NOTIFY_STATE_ALL");
00160               break;
00161        case nsIWebProgress::NOTIFY_PROGRESS:
00162               flagName.AssignLiteral("NOTIFY_PROGRESS");
00163               break;
00164        case nsIWebProgress::NOTIFY_STATUS:
00165               flagName.AssignLiteral("NOTIFY_STATUS");
00166               break;
00167        case nsIWebProgress::NOTIFY_SECURITY:
00168               flagName.AssignLiteral("NOTIFY_SECURITY");
00169               break;
00170        case nsIWebProgress::NOTIFY_LOCATION:
00171               flagName.AssignLiteral("NOTIFY_LOCATION");
00172               break;
00173        case nsIWebProgress::NOTIFY_ALL:
00174               flagName.AssignLiteral("NOTIFY_ALL");
00175               break;
00176        case nsIWebProgress::NOTIFY_STATE_DOCUMENT | nsIWebProgress::NOTIFY_STATE_REQUEST:
00177               flagName.AssignLiteral("NOTIFY_STATE_DOCUMENT&REQUEST");
00178               break;
00179        case nsIWebProgress::NOTIFY_STATE_DOCUMENT | nsIWebProgress::NOTIFY_STATE_REQUEST
00180                                    | nsIWebProgress::NOTIFY_STATE_NETWORK    :
00181               flagName.AssignLiteral("NOTIFY_STATE_DOCUMENT&REQUEST&NETWORK");
00182               break;
00183        case nsIWebProgress::NOTIFY_STATE_NETWORK | nsIWebProgress::NOTIFY_STATE_WINDOW:
00184               flagName.AssignLiteral("NOTIFY_STATE_NETWORK&WINDOW");
00185               break;
00186        }
00187 }
00188 
00189 void CnsiWebProg::StoreWebProgFlag(PRUint32 theFlag)
00190 {
00191        theStoredFlag = theFlag;
00192 }
00193 
00194 void CnsiWebProg::RetrieveWebProgFlag()
00195 {
00196        PRUint32 theFlag;
00197        nsCAutoString flagName(NS_LITERAL_CSTRING("NOTIFY_ALL"));
00198 
00199        theFlag = theStoredFlag;
00200        ConvertWPFlagToString(theFlag, flagName);
00201        FormatAndPrintOutput("WebProgressListener flag = ", flagName, 2);
00202 }
00203 
00204 void CnsiWebProg::OnStartTests(UINT nMenuID)
00205 {
00206        CWebProgDlg myDialog;
00207 
00208        switch(nMenuID)
00209        {
00210               case ID_INTERFACES_NSIWEBPROGRESS_RUNALLTESTS :
00211                      RunAllTests();
00212                      break ;
00213               case ID_INTERFACES_NSIWEBPROGRESS_ADDPROGRESSLISTENER :
00214                      if (myDialog.DoModal() == IDOK)
00215                             AddWebProgLstnr(myDialog.m_wpFlagValue, 2);
00216                      break ;
00217               case ID_INTERFACES_NSIWEBPROGRESS_REMOVEPROGRESSLISTENER :
00218                      RemoveWebProgLstnr(2);
00219                      break ;
00220               case ID_INTERFACES_NSIWEBPROGRESS_GETDOMWINDOW  :
00221                      GetTheDOMWindow(2);
00222                      break ;
00223               case ID_INTERFACES_NSIWEBPROGRESS_ISLOADINGDOCUMENT :
00224                      GetIsLoadingDocTest(2);
00225                      break;
00226        }
00227 }
00228 
00229 void CnsiWebProg::RunAllTests(void)
00230 {
00231        int i;
00232        PRUint32 theFlag = 0x000000ff;
00233        for (i = 0; i < 10; i++) {
00234               switch(i) {
00235               case 0:
00236                      theFlag = nsIWebProgress::NOTIFY_STATE_REQUEST;
00237                      break;
00238               case 1:
00239                      theFlag = nsIWebProgress::NOTIFY_STATE_DOCUMENT;
00240                      break;
00241               case 2:
00242                      theFlag = nsIWebProgress::NOTIFY_STATE_NETWORK;
00243                      break;
00244               case 3:
00245                      theFlag = nsIWebProgress::NOTIFY_STATE_WINDOW;
00246                      break;
00247               case 4:
00248                      theFlag = nsIWebProgress::NOTIFY_STATE_ALL;
00249                      break;
00250               case 5:
00251                      theFlag = nsIWebProgress::NOTIFY_PROGRESS;
00252                      break;
00253               case 6:
00254                      theFlag = nsIWebProgress::NOTIFY_STATUS;
00255                      break;
00256               case 7:
00257                      theFlag = nsIWebProgress::NOTIFY_SECURITY;
00258                      break;
00259               case 8:
00260                      theFlag = nsIWebProgress::NOTIFY_LOCATION;
00261                      break;
00262               case 9:
00263                      theFlag = nsIWebProgress::NOTIFY_ALL;
00264                      break;
00265               }
00266               AddWebProgLstnr(theFlag, 1);
00267               RemoveWebProgLstnr(1);
00268        }
00269        GetTheDOMWindow(1);
00270        GetIsLoadingDocTest(1);
00271 }
00272 
00274 // CnsiWebProg message handlers