Back to index

lightning-sunbird  0.9+nobinonly
nsIWebBrowFind.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 //
00040 // test cases for nsIWebBrowserFind
00041 //
00042 
00043 #include "Stdafx.h"
00044 #include "TestEmbed.h"
00045 #include "BrowserImpl.h"
00046 #include "BrowserFrm.h"
00047 #include "Tests.h"
00048 #include "domwindow.h"
00049 #include "QaUtils.h"
00050 #include <stdio.h>
00051 #include "nsIWebBrowFind.h"
00052 #include "UrlDialog.h"
00053 #include "QaFindDlg.h"
00054 
00055 #ifdef _DEBUG
00056 #define new DEBUG_NEW
00057 #undef THIS_FILE
00058 static char THIS_FILE[] = __FILE__;
00059 #endif
00060 
00061 // constructor for CNsIWebBrowFind
00062 CNsIWebBrowFind::CNsIWebBrowFind(nsIWebBrowser *mWebBrowser, CBrowserImpl *mpBrowserImpl)
00063 {
00064        qaWebBrowser = mWebBrowser;
00065        qaBrowserImpl = mpBrowserImpl;
00066 }
00067 
00068 // destructor for CNsIWebBrowFind
00069 CNsIWebBrowFind::~CNsIWebBrowFind()
00070 {
00071 
00072 }
00073 
00074        // get webBrowserFind object
00075 nsIWebBrowserFind * CNsIWebBrowFind::GetWebBrowFindObject()
00076 {
00077        nsCOMPtr<nsIWebBrowserFind> qaWBFind(do_GetInterface(qaWebBrowser, &rv));
00078        if (!qaWBFind) {
00079               QAOutput("Didn't get WebBrowserFind object.", 2);
00080               return NULL;
00081        }
00082        else {
00083               RvTestResult(rv, "nsIWebBrowserFind object test", 1);
00084               RvTestResultDlg(rv, "nsIWebBrowserFind object test");
00085               return(qaWBFind);
00086        }
00087 }
00088 
00089 void CNsIWebBrowFind::SetSearchStringTest(PRInt16 displayMode)
00090 {
00091        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00092        qaWBFind = GetWebBrowFindObject();
00093 
00094        nsString searchString;
00095        if (myDialog.DoModal() == IDOK) {
00096 
00097               // SetSearchString()
00098               searchString.AssignWithConversion(myDialog.m_textfield);
00099               rv = qaWBFind->SetSearchString(searchString.get());
00100        }
00101        RvTestResult(rv, "nsIWebBrowserFind::SetSearchString() test", displayMode);
00102        RvTestResultDlg(rv, "nsIWebBrowserFind::SetSearchString test");
00103 }
00104 
00105 void CNsIWebBrowFind::GetSearchStringTest(PRInt16 displayMode)
00106 {
00107        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00108        qaWBFind = GetWebBrowFindObject();
00109 
00110        // GetSearchString()
00111        nsXPIDLString stringBuf;
00112        CString csSearchStr;
00113        rv = qaWBFind->GetSearchString(getter_Copies(stringBuf));
00114        RvTestResult(rv, "nsIWebBrowserFind::GetSearchString() test", displayMode);
00115        RvTestResultDlg(rv, "nsIWebBrowserFind::GetSearchString() test");
00116        csSearchStr = stringBuf.get();
00117        FormatAndPrintOutput("The searched string = ", csSearchStr, displayMode);
00118 }
00119 
00120 void CNsIWebBrowFind::FindNextTest(PRBool didFind, PRInt16 displayMode)
00121 {
00122        // FindNext()
00123 
00124        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00125        qaWBFind = GetWebBrowFindObject();
00126 
00127        rv = qaWBFind->FindNext(&didFind);
00128        RvTestResult(rv, "nsIWebBrowserFind::FindNext() test", displayMode);
00129        RvTestResultDlg(rv, "nsIWebBrowserFind::FindNext() test");
00130        FormatAndPrintOutput("returned didFind = ", didFind, displayMode);
00131 }
00132 
00133 void CNsIWebBrowFind::SetFindBackwardsTest(PRBool didFindBackwards, PRInt16 displayMode)
00134 {
00135        // SetFindBackwards()
00136        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00137        qaWBFind = GetWebBrowFindObject();
00138        
00139        rv = qaWBFind->SetFindBackwards(didFindBackwards);
00140        RvTestResult(rv, "nsIWebBrowserFind::SetFindBackwards() test", displayMode);
00141        RvTestResultDlg(rv, "nsIWebBrowserFind::SetFindBackwards() test", displayMode);
00142 }
00143 
00144 void CNsIWebBrowFind::GetFindBackwardsTest(PRBool didFindBackwards, PRInt16 displayMode)
00145 {
00146        // GetFindBackwards()
00147        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00148        qaWBFind = GetWebBrowFindObject();
00149        
00150        rv = qaWBFind->GetFindBackwards(&didFindBackwards);
00151        RvTestResult(rv, "nsIWebBrowserFind::GetFindBackwards() test", displayMode);
00152        RvTestResultDlg(rv, "nsIWebBrowserFind::GetFindBackwards() test");
00153        FormatAndPrintOutput("returned didFindBackwards = ", didFindBackwards, displayMode);
00154 }
00155 
00156 void CNsIWebBrowFind::SetWrapFindTest(PRBool didWrapFind, PRInt16 displayMode)
00157 {
00158        // SetWrapFind()
00159        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00160        qaWBFind = GetWebBrowFindObject();
00161        
00162        rv = qaWBFind->SetWrapFind(didWrapFind);
00163        RvTestResult(rv, "nsIWebBrowserFind::SetWrapFind() test", displayMode);
00164        RvTestResultDlg(rv, "nsIWebBrowserFind::SetWrapFind() test");
00165 }
00166 
00167 void CNsIWebBrowFind::GetWrapFindTest(PRBool didWrapFind, PRInt16 displayMode)
00168 {
00169        // GetWrapFind()
00170        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00171        qaWBFind = GetWebBrowFindObject();
00172        
00173        rv = qaWBFind->GetWrapFind(&didWrapFind);
00174        RvTestResult(rv, "nsIWebBrowserFind::GetWrapFind() test", displayMode);
00175        RvTestResultDlg(rv, "nsIWebBrowserFind::GetWrapFind() test");
00176        FormatAndPrintOutput("returned didWrapFind = ", didWrapFind, displayMode);
00177 }
00178 
00179 void CNsIWebBrowFind::SetEntireWordTest(PRBool didEntireWord, PRInt16 displayMode)
00180 {
00181        // SetEntireWord()
00182        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00183        qaWBFind = GetWebBrowFindObject();
00184        
00185        rv = qaWBFind->SetEntireWord(didEntireWord);
00186        RvTestResult(rv, "nsIWebBrowserFind::SetEntireWord() test", displayMode);
00187        RvTestResultDlg(rv, "nsIWebBrowserFind::SetEntireWord() test");
00188 }
00189 
00190 void CNsIWebBrowFind::GetEntireWordTest(PRBool didEntireWord, PRInt16 displayMode)
00191 {
00192        // GetEntireWord()
00193        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00194        qaWBFind = GetWebBrowFindObject();
00195        
00196        rv = qaWBFind->GetEntireWord(&didEntireWord);
00197        RvTestResult(rv, "nsIWebBrowserFind::GetEntireWord() test", displayMode);
00198        RvTestResultDlg(rv, "nsIWebBrowserFind::GetEntireWord() test");
00199        FormatAndPrintOutput("returned didEntireWord = ", didEntireWord, displayMode);
00200 }
00201 
00202 void CNsIWebBrowFind::SetMatchCase(PRBool didMatchCase, PRInt16 displayMode)
00203 {
00204        // SetMatchCase()
00205        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00206        qaWBFind = GetWebBrowFindObject();
00207        
00208        rv = qaWBFind->SetMatchCase(didMatchCase);
00209        RvTestResult(rv, "nsIWebBrowserFind::SetMatchCase() test", displayMode);
00210        RvTestResultDlg(rv, "nsIWebBrowserFind::SetMatchCase() test");
00211 }
00212 
00213 void CNsIWebBrowFind::GetMatchCase(PRBool didMatchCase, PRInt16 displayMode)
00214 {
00215        // GetMatchCase()
00216        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00217        qaWBFind = GetWebBrowFindObject();
00218        
00219        rv = qaWBFind->GetMatchCase(&didMatchCase);
00220        RvTestResult(rv, "nsIWebBrowserFind::GetMatchCase() test", displayMode);
00221        RvTestResultDlg(rv, "nsIWebBrowserFind::GetMatchCase() test");
00222        FormatAndPrintOutput("returned didMatchCase = ", didMatchCase, displayMode);
00223 }
00224 
00225 void CNsIWebBrowFind::SetSearchFrames(PRBool didSearchFrames, PRInt16 displayMode)
00226 {
00227        // SetSearchFrames()
00228        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00229        qaWBFind = GetWebBrowFindObject();
00230        
00231        rv = qaWBFind->SetSearchFrames(didSearchFrames);
00232        RvTestResult(rv, "nsIWebBrowserFind::SetSearchFrames() test", displayMode);
00233        RvTestResultDlg(rv, "nsIWebBrowserFind::SetSearchFrames() test");
00234 }
00235 
00236 void CNsIWebBrowFind::GetSearchFrames(PRBool didSearchFrames, PRInt16 displayMode)
00237 {
00238        // GetSearchFrames()
00239        nsCOMPtr<nsIWebBrowserFind> qaWBFind;
00240        qaWBFind = GetWebBrowFindObject();
00241        
00242        rv = qaWBFind->GetSearchFrames(&didSearchFrames);
00243        RvTestResult(rv, "nsIWebBrowserFind::GetSearchFrames() test", displayMode);
00244        RvTestResultDlg(rv, "nsIWebBrowserFind::GetSearchFrames() test");
00245        FormatAndPrintOutput("returned didSearchFrames = ", didSearchFrames, displayMode);
00246 }
00247 
00248 void CNsIWebBrowFind::OnStartTests(UINT nMenuID)
00249 {
00250        switch(nMenuID)
00251        {
00252               case ID_INTERFACES_NSIWEBBROWSERFIND_RUNALLTESTS :
00253                      RunAllTests();
00254                      break ;
00255               case ID_INTERFACES_NSIWEBBROWSERFIND_SETSEARCHSTRINGTEST :
00256                      SetSearchStringTest(2);
00257                      break ;
00258               case ID_INTERFACES_NSIWEBBROWSERFIND_GETSEARCHSTRINGTEST :
00259                      GetSearchStringTest(2);
00260                      break ;
00261               case ID_INTERFACES_NSIWEBBROWSERFIND_FINDNEXTTEST  :
00262                      FindNextTest(PR_TRUE, 2);
00263                      break ;
00264               case ID_INTERFACES_NSIWEBBROWSERFIND_SETFINDBACKWARDSTEST :
00265                      SetFindBackwardsTest(PR_TRUE, 2);
00266                      break ;
00267               case ID_INTERFACES_NSIWEBBROWSERFIND_GETFINDBACKWARDSTEST :
00268                      GetFindBackwardsTest(PR_TRUE, 2);
00269                      break ;
00270               case ID_INTERFACES_NSIWEBBROWSERFIND_SETWRAPFINDTEST :
00271                      SetWrapFindTest(PR_TRUE, 2);
00272                      break ;
00273               case ID_INTERFACES_NSIWEBBROWSERFIND_GETWRAPFINDTEST  :
00274                      GetWrapFindTest(PR_TRUE, 2);
00275                      break ;
00276               case ID_INTERFACES_NSIWEBBROWSERFIND_SETENTIREWORDTEST  :
00277                      SetEntireWordTest(PR_TRUE, 2);
00278                      break ;
00279               case ID_INTERFACES_NSIWEBBROWSERFIND_GETENTIREWORDTEST :
00280                      GetEntireWordTest(PR_TRUE, 2);
00281                      break ;
00282               case ID_INTERFACES_NSIWEBBROWSERFIND_SETMATCHCASE :
00283                      SetMatchCase(PR_TRUE, 2);
00284                      break ;
00285               case ID_INTERFACES_NSIWEBBROWSERFIND_GETMATCHCASE :
00286                      GetMatchCase(PR_TRUE, 2);
00287                      break ;
00288               case ID_INTERFACES_NSIWEBBROWSERFIND_SETSEARCHFRAMES  :
00289                      SetSearchFrames(PR_TRUE, 2);
00290                      break ;
00291               case ID_INTERFACES_NSIWEBBROWSERFIND_GETSEARCHFRAMES  :
00292                      GetSearchFrames(PR_TRUE, 2);
00293                      break ;
00294        }
00295 }
00296 
00297 void CNsIWebBrowFind::RunAllTests()
00298 {
00299        QAOutput("Begin WebBrowserFind tests.", 1);
00300        GetWebBrowFindObject();
00301        SetSearchStringTest(1);
00302        GetSearchStringTest(1);
00303        FindNextTest(PR_TRUE, 1);
00304        FindNextTest(PR_TRUE, 1);  // run a 2nd time to advance it
00305        SetFindBackwardsTest(PR_TRUE, 1);
00306        GetFindBackwardsTest(PR_TRUE, 1);
00307        FindNextTest(PR_TRUE, 1);   // to find backwards
00308        SetWrapFindTest(PR_TRUE, 1);
00309        GetWrapFindTest(PR_TRUE, 1);
00310        FindNextTest(PR_TRUE, 1);  // to wrap around
00311        SetEntireWordTest(PR_TRUE, 1);
00312        GetEntireWordTest(PR_TRUE, 1);
00313        FindNextTest(PR_TRUE, 1);  // entire word
00314        SetMatchCase(PR_TRUE, 1);
00315        GetMatchCase(PR_TRUE, 1);
00316        FindNextTest(PR_TRUE, 1);  // match case
00317        SetSearchFrames(PR_TRUE, 1);
00318        GetSearchFrames(PR_TRUE, 1);
00319        FindNextTest(PR_TRUE, 1);  // frames
00320 
00321        QAOutput("PR_FALSE tests", 1);
00322        SetFindBackwardsTest(PR_FALSE, 1);
00323        GetFindBackwardsTest(PR_FALSE, 1);
00324        FindNextTest(PR_FALSE, 1);         // shouldn't find backwards
00325        SetWrapFindTest(PR_FALSE, 1);
00326        GetWrapFindTest(PR_FALSE, 1);
00327        FindNextTest(PR_FALSE, 1);         // shouldn't find wrap around
00328        SetEntireWordTest(PR_FALSE, 1);
00329        GetEntireWordTest(PR_FALSE, 1);
00330        FindNextTest(PR_FALSE, 1);         // shouldn't find entire word
00331        SetMatchCase(PR_FALSE, 1);
00332        GetMatchCase(PR_FALSE, 1);
00333        FindNextTest(PR_FALSE, 1);         // shouldn't find case
00334        SetSearchFrames(PR_FALSE, 1);
00335        GetSearchFrames(PR_FALSE, 1);
00336        FindNextTest(PR_FALSE, 1);         // shouldn't find frame
00337        QAOutput("End WebBrowserFind tests.", 1);
00338 }