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 * Ashish Bhatt <ashishbhatt@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 ***** */
41 // Test cases for the nsIDOMWindow Interface
47 #include "domWindow.h"
51 CDomWindow::CDomWindow(nsIWebBrowser
* mWebBrowser
)
53 qaWebBrowser
= mWebBrowser
;
56 CDomWindow::~CDomWindow()
62 void CDomWindow::OnStartTests(UINT nMenuID
)
64 // Calls all or indivdual test cases on the basis of the
65 // option selected from menu.
69 case ID_INTERFACES_NSIDOMWINDOW_RUNALLTESTS
:
72 case ID_INTERFACES_NSIDOMWINDOW_GETDOMDOCUMENT
:
75 case ID_INTERFACES_NSIDOMWINDOW_GETPARENT
:
78 case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLBARS
:
81 case ID_INTERFACES_NSIDOMWINDOW_GETFRAMES
:
84 case ID_INTERFACES_NSIDOMWINDOW_GETNAME
:
87 case ID_INTERFACES_NSIDOMWINDOW_GETTEXTZOOM
:
90 case ID_INTERFACES_NSIDOMWINDOW_SETTEXTZOOM
:
93 case ID_INTERFACES_NSIDOMWINDOW_GETSCSOLLX
:
96 case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLY
:
99 case ID_INTERFACES_NSIDOMWINDOW_SCROLLTO
:
102 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBY
:
105 case ID_INTERFACES_NSIDOMWINDOW_GETSELECTION
:
108 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYLINES
:
111 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYPAGES
:
114 case ID_INTERFACES_NSIDOMWINDOW_SIZETOCONTENT
:
118 AfxMessageBox("Not added menu handler for this menu item");
122 void CDomWindow::RunAllTests()
124 PRInt32 scrollX
= 0 ;
127 float fTextZoom
= 0.0;
129 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
130 //nsCOMPtr<nsIDOMWindow> oDomWindowTop;
131 //nsCOMPtr<nsIDOMWindow> oDomWindowParent;
133 nsCOMPtr
<nsIDOMBarProp
> oDomBarProp
;
134 nsCOMPtr
<nsIDOMWindowCollection
> oDomWindowCol
;
135 nsCOMPtr
<nsIDOMDocument
> oDomDocument
;
136 nsCOMPtr
<nsISelection
> oSelection
;
138 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
139 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 1);
142 AfxMessageBox("Cannot create Dom Window Object");
146 /* rv = oDomWindow->GetTop(getter_AddRefs(oDomWindowTop));
147 RvTestResult(rv, "nsIDOMWindow::GetTop()' rv test", 1);
150 AfxMessageBox("Cannot create Dom Window Top Object");
154 rv = oDomWindow->GetParent(getter_AddRefs(oDomWindow));
155 RvTestResult(rv, "nsIDOMWindow::GetParent()' rv test", 1);
158 AfxMessageBox("Cannot create Dom Window Parent Object");
164 rv
= oDomWindow
->GetScrollbars(getter_AddRefs(oDomBarProp
));
165 RvTestResult(rv
, "nsIDOMWindow::GetScrollbars()' rv test", 1);
168 AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
172 rv
= oDomWindow
->GetFrames(getter_AddRefs(oDomWindowCol
));
173 RvTestResult(rv
, "nsIDOMWindow::GetFrames()' rv test", 1);
176 AfxMessageBox("Cannot create Dom Window Collection Object");
180 rv
= oDomWindow
->GetDocument(getter_AddRefs(oDomDocument
));
181 RvTestResult(rv
, "nsIDOMWindow::GetDocument()' rv test", 1);
184 AfxMessageBox("Cannot create Dom Document Object");
188 rv
= oDomWindow
->GetSelection(getter_AddRefs(oSelection
));
189 RvTestResult(rv
, "nsIDOMWindow::GetSelection()' rv test", 1);
192 AfxMessageBox("Cannot get the Selection Object");
196 // nsIDOMBarProp's only attribute
197 //rv = oDomBarProp->GetVisible(&bVisible);
200 rv
= oDomWindow
->GetTextZoom(&fTextZoom
);
201 RvTestResult(rv
, "nsIDOMWindow::GetTextZoom()' rv test", 1);
203 rv
= oDomWindow
->SetTextZoom(12.0);
205 rv
= oDomWindow
->SetTextZoom(fTextZoom
);
206 RvTestResult(rv
, "nsIDOMWindow::SetTextZoom()' rv test", 1);
208 rv
= oDomWindow
->GetScrollX(&scrollX
);
209 RvTestResult(rv
, "nsIDOMWindow::GetScrollX()' rv test", 1);
211 rv
= oDomWindow
->GetScrollY(&scrollY
);
212 RvTestResult(rv
, "nsIDOMWindow::GetScrollY()' rv test", 1);
214 rv
= oDomWindow
->ScrollTo(100,100);
215 RvTestResult(rv
, "nsIDOMWindow::ScrollTo()' rv test", 1);
218 rv
= oDomWindow
->ScrollBy(5, 5);
219 RvTestResult(rv
, "nsIDOMWindow::ScrollBy()' rv test", 1);
221 rv
= oDomWindow
->ScrollByLines(5);
222 RvTestResult(rv
, "nsIDOMWindow::ScrollByLines()' rv test", 1);
224 rv
= oDomWindow
->ScrollByPages(1);
225 RvTestResult(rv
, "nsIDOMWindow::ScrollByPages()' rv test", 1);
227 //rv = oDomWindow->SizeToContent();
228 // RvTestResult(rv, "nsIDOMWindow::SizeToContent()' rv test", 1);
232 void CDomWindow::GetTop()
234 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
235 nsCOMPtr
<nsIDOMWindow
> oDomWindowTop
;
236 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
237 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
240 AfxMessageBox("Cannot create Dom Window Object");
244 rv
= oDomWindow
->GetTop(getter_AddRefs(oDomWindowTop
));
245 RvTestResult(rv
, "nsIDOMWindow::GetTop()' rv test", 1);
248 AfxMessageBox("Cannot create Dom Window Top Object");
253 void CDomWindow::GetParent()
255 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
256 nsCOMPtr
<nsIDOMWindow
> oDomWindowParent
;
258 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
259 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
262 AfxMessageBox("Cannot create Dom Window Object");
266 rv
= oDomWindow
->GetParent(getter_AddRefs(oDomWindow
));
267 RvTestResult(rv
, "nsIDOMWindow::GetParent()' rv test", 0);
270 AfxMessageBox("Cannot create Dom Window Parent Object");
277 void CDomWindow::GetScrollbars()
279 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
280 nsCOMPtr
<nsIDOMBarProp
> oDomBarProp
;
282 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
283 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
286 AfxMessageBox("Cannot create Dom Window Object");
290 rv
= oDomWindow
->GetScrollbars(getter_AddRefs(oDomBarProp
));
291 RvTestResult(rv
, "nsIDOMWindow::GetScrollbars()' rv test", 0);
294 AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
300 void CDomWindow::GetFrames()
302 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
303 nsCOMPtr
<nsIDOMWindowCollection
> oDomWindowCol
;
305 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
306 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
309 AfxMessageBox("Cannot create Dom Window Object");
312 rv
= oDomWindow
->GetFrames(getter_AddRefs(oDomWindowCol
));
313 RvTestResult(rv
, "nsIDOMWindow::GetFrames()' rv test", 0);
316 AfxMessageBox("Cannot create Dom Window Collection Object");
321 void CDomWindow::GetDocument()
323 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
324 nsCOMPtr
<nsIDOMDocument
> oDomDocument
;
326 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
327 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
330 AfxMessageBox("Cannot create Dom Window Object");
334 rv
= oDomWindow
->GetDocument(getter_AddRefs(oDomDocument
));
335 RvTestResult(rv
, "nsIDOMWindow::GetDocument()' rv test",0);
338 AfxMessageBox("Cannot create Dom Document Object");
343 void CDomWindow::GetSelection()
345 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
346 nsCOMPtr
<nsISelection
> oSelection
;
348 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
349 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test",0);
353 AfxMessageBox("Cannot create Dom Window Object");
357 rv
= oDomWindow
->GetSelection(getter_AddRefs(oSelection
));
358 RvTestResult(rv
, "nsIDOMWindow::GetSelection()' rv test", 0);
361 AfxMessageBox("Cannot get the Selection Object");
366 void CDomWindow::GetTextZoom()
368 float fTextZoom
= 0.0 ;
369 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
370 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
371 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
375 AfxMessageBox("Cannot create Dom Window Object");
378 rv
= oDomWindow
->GetTextZoom(&fTextZoom
);
379 RvTestResult(rv
, "nsIDOMWindow::GetTextZoom()' rv test", 0);
382 void CDomWindow::SetTextZoom()
384 float fTextZoom
= 0.0 ;
387 rv
= GetDOMOWindowObject()->SetTextZoom(fTextZoom
);
388 RvTestResult(rv
, "nsIDOMWindow::SetTextZoom()' rv test", 0);
391 void CDomWindow::GetScrollX()
393 PRInt32 scrollX
= 0 ;
394 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
395 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
396 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
400 AfxMessageBox("Cannot create Dom Window Object");
403 rv
= oDomWindow
->GetScrollX(&scrollX
);
404 RvTestResult(rv
, "nsIDOMWindow::GetScrollX()' rv test", 0);
407 void CDomWindow::GetScrollY()
409 PRInt32 scrollY
= 0 ;
410 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
411 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
412 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
416 AfxMessageBox("Cannot create Dom Window Object");
419 rv
= oDomWindow
->GetScrollY(&scrollY
);
420 RvTestResult(rv
, "nsIDOMWindow::GetScrollY()' rv test", 0);
423 void CDomWindow::ScrollTo()
425 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
426 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
427 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
431 AfxMessageBox("Cannot create Dom Window Object");
434 rv
= oDomWindow
->ScrollTo(100,100);
435 RvTestResult(rv
, "nsIDOMWindow::ScrollTo()' rv test", 0);
439 void CDomWindow::ScrollBy()
441 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
442 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
443 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
447 AfxMessageBox("Cannot create Dom Window Object");
450 rv
= oDomWindow
->ScrollBy(5, 5);
451 RvTestResult(rv
, "nsIDOMWindow::ScrollBy()' rv test", 0);
454 void CDomWindow::ScrollByLines()
456 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
457 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
458 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
462 AfxMessageBox("Cannot create Dom Window Object");
465 rv
= oDomWindow
->ScrollByLines(5);
466 RvTestResult(rv
, "nsIDOMWindow::ScrollByLines()' rv test",0);
470 void CDomWindow::ScrollByPages()
472 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
473 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
474 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
478 AfxMessageBox("Cannot create Dom Window Object");
481 rv
= oDomWindow
->ScrollByPages(1);
482 RvTestResult(rv
, "nsIDOMWindow::ScrollByPages()' rv test", 0);
485 void CDomWindow::SizeToContent()
487 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
488 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
489 RvTestResult(rv
, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
493 AfxMessageBox("Cannot create Dom Window Object");
496 rv
= oDomWindow
->SizeToContent();
497 RvTestResult(rv
, "nsIDOMWindow::SizeToContent()' rv test", 0);
501 nsIDOMWindow
* CDomWindow::GetDOMOWindowObject()
503 nsCOMPtr
<nsIDOMWindow
> oDomWindow
;
504 rv
= qaWebBrowser
->GetContentDOMWindow(getter_AddRefs(oDomWindow
));
506 AfxMessageBox("Cannot create Dom Window Object");