1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * David Epstein <depstein@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 // test cases for nsIWebBrowserFind
44 #include "TestEmbed.h"
45 #include "BrowserImpl.h"
46 #include "BrowserFrm.h"
48 #include "domwindow.h"
51 #include "nsIWebBrowFind.h"
52 #include "UrlDialog.h"
53 #include "QaFindDlg.h"
58 static char THIS_FILE
[] = __FILE__
;
61 // constructor for CNsIWebBrowFind
62 CNsIWebBrowFind::CNsIWebBrowFind(nsIWebBrowser
*mWebBrowser
, CBrowserImpl
*mpBrowserImpl
)
64 qaWebBrowser
= mWebBrowser
;
65 qaBrowserImpl
= mpBrowserImpl
;
68 // destructor for CNsIWebBrowFind
69 CNsIWebBrowFind::~CNsIWebBrowFind()
74 // get webBrowserFind object
75 nsIWebBrowserFind
* CNsIWebBrowFind::GetWebBrowFindObject()
77 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind(do_GetInterface(qaWebBrowser
, &rv
));
79 QAOutput("Didn't get WebBrowserFind object.", 2);
83 RvTestResult(rv
, "nsIWebBrowserFind object test", 1);
84 RvTestResultDlg(rv
, "nsIWebBrowserFind object test");
89 void CNsIWebBrowFind::SetSearchStringTest(PRInt16 displayMode
)
91 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
92 qaWBFind
= GetWebBrowFindObject();
94 nsString searchString
;
95 if (myDialog
.DoModal() == IDOK
) {
98 searchString
.AssignWithConversion(myDialog
.m_textfield
);
99 rv
= qaWBFind
->SetSearchString(searchString
.get());
101 RvTestResult(rv
, "nsIWebBrowserFind::SetSearchString() test", displayMode
);
102 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetSearchString test");
105 void CNsIWebBrowFind::GetSearchStringTest(PRInt16 displayMode
)
107 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
108 qaWBFind
= GetWebBrowFindObject();
111 nsXPIDLString stringBuf
;
113 rv
= qaWBFind
->GetSearchString(getter_Copies(stringBuf
));
114 RvTestResult(rv
, "nsIWebBrowserFind::GetSearchString() test", displayMode
);
115 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetSearchString() test");
116 csSearchStr
= stringBuf
.get();
117 FormatAndPrintOutput("The searched string = ", csSearchStr
, displayMode
);
120 void CNsIWebBrowFind::FindNextTest(PRBool didFind
, PRInt16 displayMode
)
124 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
125 qaWBFind
= GetWebBrowFindObject();
127 rv
= qaWBFind
->FindNext(&didFind
);
128 RvTestResult(rv
, "nsIWebBrowserFind::FindNext() test", displayMode
);
129 RvTestResultDlg(rv
, "nsIWebBrowserFind::FindNext() test");
130 FormatAndPrintOutput("returned didFind = ", didFind
, displayMode
);
133 void CNsIWebBrowFind::SetFindBackwardsTest(PRBool didFindBackwards
, PRInt16 displayMode
)
135 // SetFindBackwards()
136 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
137 qaWBFind
= GetWebBrowFindObject();
139 rv
= qaWBFind
->SetFindBackwards(didFindBackwards
);
140 RvTestResult(rv
, "nsIWebBrowserFind::SetFindBackwards() test", displayMode
);
141 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetFindBackwards() test", displayMode
);
144 void CNsIWebBrowFind::GetFindBackwardsTest(PRBool didFindBackwards
, PRInt16 displayMode
)
146 // GetFindBackwards()
147 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
148 qaWBFind
= GetWebBrowFindObject();
150 rv
= qaWBFind
->GetFindBackwards(&didFindBackwards
);
151 RvTestResult(rv
, "nsIWebBrowserFind::GetFindBackwards() test", displayMode
);
152 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetFindBackwards() test");
153 FormatAndPrintOutput("returned didFindBackwards = ", didFindBackwards
, displayMode
);
156 void CNsIWebBrowFind::SetWrapFindTest(PRBool didWrapFind
, PRInt16 displayMode
)
159 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
160 qaWBFind
= GetWebBrowFindObject();
162 rv
= qaWBFind
->SetWrapFind(didWrapFind
);
163 RvTestResult(rv
, "nsIWebBrowserFind::SetWrapFind() test", displayMode
);
164 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetWrapFind() test");
167 void CNsIWebBrowFind::GetWrapFindTest(PRBool didWrapFind
, PRInt16 displayMode
)
170 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
171 qaWBFind
= GetWebBrowFindObject();
173 rv
= qaWBFind
->GetWrapFind(&didWrapFind
);
174 RvTestResult(rv
, "nsIWebBrowserFind::GetWrapFind() test", displayMode
);
175 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetWrapFind() test");
176 FormatAndPrintOutput("returned didWrapFind = ", didWrapFind
, displayMode
);
179 void CNsIWebBrowFind::SetEntireWordTest(PRBool didEntireWord
, PRInt16 displayMode
)
182 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
183 qaWBFind
= GetWebBrowFindObject();
185 rv
= qaWBFind
->SetEntireWord(didEntireWord
);
186 RvTestResult(rv
, "nsIWebBrowserFind::SetEntireWord() test", displayMode
);
187 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetEntireWord() test");
190 void CNsIWebBrowFind::GetEntireWordTest(PRBool didEntireWord
, PRInt16 displayMode
)
193 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
194 qaWBFind
= GetWebBrowFindObject();
196 rv
= qaWBFind
->GetEntireWord(&didEntireWord
);
197 RvTestResult(rv
, "nsIWebBrowserFind::GetEntireWord() test", displayMode
);
198 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetEntireWord() test");
199 FormatAndPrintOutput("returned didEntireWord = ", didEntireWord
, displayMode
);
202 void CNsIWebBrowFind::SetMatchCase(PRBool didMatchCase
, PRInt16 displayMode
)
205 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
206 qaWBFind
= GetWebBrowFindObject();
208 rv
= qaWBFind
->SetMatchCase(didMatchCase
);
209 RvTestResult(rv
, "nsIWebBrowserFind::SetMatchCase() test", displayMode
);
210 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetMatchCase() test");
213 void CNsIWebBrowFind::GetMatchCase(PRBool didMatchCase
, PRInt16 displayMode
)
216 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
217 qaWBFind
= GetWebBrowFindObject();
219 rv
= qaWBFind
->GetMatchCase(&didMatchCase
);
220 RvTestResult(rv
, "nsIWebBrowserFind::GetMatchCase() test", displayMode
);
221 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetMatchCase() test");
222 FormatAndPrintOutput("returned didMatchCase = ", didMatchCase
, displayMode
);
225 void CNsIWebBrowFind::SetSearchFrames(PRBool didSearchFrames
, PRInt16 displayMode
)
228 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
229 qaWBFind
= GetWebBrowFindObject();
231 rv
= qaWBFind
->SetSearchFrames(didSearchFrames
);
232 RvTestResult(rv
, "nsIWebBrowserFind::SetSearchFrames() test", displayMode
);
233 RvTestResultDlg(rv
, "nsIWebBrowserFind::SetSearchFrames() test");
236 void CNsIWebBrowFind::GetSearchFrames(PRBool didSearchFrames
, PRInt16 displayMode
)
239 nsCOMPtr
<nsIWebBrowserFind
> qaWBFind
;
240 qaWBFind
= GetWebBrowFindObject();
242 rv
= qaWBFind
->GetSearchFrames(&didSearchFrames
);
243 RvTestResult(rv
, "nsIWebBrowserFind::GetSearchFrames() test", displayMode
);
244 RvTestResultDlg(rv
, "nsIWebBrowserFind::GetSearchFrames() test");
245 FormatAndPrintOutput("returned didSearchFrames = ", didSearchFrames
, displayMode
);
248 void CNsIWebBrowFind::OnStartTests(UINT nMenuID
)
252 case ID_INTERFACES_NSIWEBBROWSERFIND_RUNALLTESTS
:
255 case ID_INTERFACES_NSIWEBBROWSERFIND_SETSEARCHSTRINGTEST
:
256 SetSearchStringTest(2);
258 case ID_INTERFACES_NSIWEBBROWSERFIND_GETSEARCHSTRINGTEST
:
259 GetSearchStringTest(2);
261 case ID_INTERFACES_NSIWEBBROWSERFIND_FINDNEXTTEST
:
262 FindNextTest(PR_TRUE
, 2);
264 case ID_INTERFACES_NSIWEBBROWSERFIND_SETFINDBACKWARDSTEST
:
265 SetFindBackwardsTest(PR_TRUE
, 2);
267 case ID_INTERFACES_NSIWEBBROWSERFIND_GETFINDBACKWARDSTEST
:
268 GetFindBackwardsTest(PR_TRUE
, 2);
270 case ID_INTERFACES_NSIWEBBROWSERFIND_SETWRAPFINDTEST
:
271 SetWrapFindTest(PR_TRUE
, 2);
273 case ID_INTERFACES_NSIWEBBROWSERFIND_GETWRAPFINDTEST
:
274 GetWrapFindTest(PR_TRUE
, 2);
276 case ID_INTERFACES_NSIWEBBROWSERFIND_SETENTIREWORDTEST
:
277 SetEntireWordTest(PR_TRUE
, 2);
279 case ID_INTERFACES_NSIWEBBROWSERFIND_GETENTIREWORDTEST
:
280 GetEntireWordTest(PR_TRUE
, 2);
282 case ID_INTERFACES_NSIWEBBROWSERFIND_SETMATCHCASE
:
283 SetMatchCase(PR_TRUE
, 2);
285 case ID_INTERFACES_NSIWEBBROWSERFIND_GETMATCHCASE
:
286 GetMatchCase(PR_TRUE
, 2);
288 case ID_INTERFACES_NSIWEBBROWSERFIND_SETSEARCHFRAMES
:
289 SetSearchFrames(PR_TRUE
, 2);
291 case ID_INTERFACES_NSIWEBBROWSERFIND_GETSEARCHFRAMES
:
292 GetSearchFrames(PR_TRUE
, 2);
297 void CNsIWebBrowFind::RunAllTests()
299 QAOutput("Begin WebBrowserFind tests.", 1);
300 GetWebBrowFindObject();
301 SetSearchStringTest(1);
302 GetSearchStringTest(1);
303 FindNextTest(PR_TRUE
, 1);
304 FindNextTest(PR_TRUE
, 1); // run a 2nd time to advance it
305 SetFindBackwardsTest(PR_TRUE
, 1);
306 GetFindBackwardsTest(PR_TRUE
, 1);
307 FindNextTest(PR_TRUE
, 1); // to find backwards
308 SetWrapFindTest(PR_TRUE
, 1);
309 GetWrapFindTest(PR_TRUE
, 1);
310 FindNextTest(PR_TRUE
, 1); // to wrap around
311 SetEntireWordTest(PR_TRUE
, 1);
312 GetEntireWordTest(PR_TRUE
, 1);
313 FindNextTest(PR_TRUE
, 1); // entire word
314 SetMatchCase(PR_TRUE
, 1);
315 GetMatchCase(PR_TRUE
, 1);
316 FindNextTest(PR_TRUE
, 1); // match case
317 SetSearchFrames(PR_TRUE
, 1);
318 GetSearchFrames(PR_TRUE
, 1);
319 FindNextTest(PR_TRUE
, 1); // frames
321 QAOutput("PR_FALSE tests", 1);
322 SetFindBackwardsTest(PR_FALSE
, 1);
323 GetFindBackwardsTest(PR_FALSE
, 1);
324 FindNextTest(PR_FALSE
, 1); // shouldn't find backwards
325 SetWrapFindTest(PR_FALSE
, 1);
326 GetWrapFindTest(PR_FALSE
, 1);
327 FindNextTest(PR_FALSE
, 1); // shouldn't find wrap around
328 SetEntireWordTest(PR_FALSE
, 1);
329 GetEntireWordTest(PR_FALSE
, 1);
330 FindNextTest(PR_FALSE
, 1); // shouldn't find entire word
331 SetMatchCase(PR_FALSE
, 1);
332 GetMatchCase(PR_FALSE
, 1);
333 FindNextTest(PR_FALSE
, 1); // shouldn't find case
334 SetSearchFrames(PR_FALSE
, 1);
335 GetSearchFrames(PR_FALSE
, 1);
336 FindNextTest(PR_FALSE
, 1); // shouldn't find frame
337 QAOutput("End WebBrowserFind tests.", 1);