Back to index

lightning-sunbird  0.9+nobinonly
DomWindow.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  *   Ashish Bhatt <ashishbhatt@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 // File Overview....
00040 //
00041 // Test cases for the nsIDOMWindow Interface
00042 
00043 
00044 #include "stdafx.h"
00045 #include "QaUtils.h"
00046 #include <stdio.h>
00047 #include "domWindow.h"
00048 #include "resource.h"
00049 
00050 
00051 CDomWindow::CDomWindow(nsIWebBrowser* mWebBrowser)
00052 {
00053        qaWebBrowser = mWebBrowser ;
00054 }
00055 
00056 CDomWindow::~CDomWindow()
00057 {
00058 
00059 }
00060 
00061 
00062 void CDomWindow::OnStartTests(UINT nMenuID)
00063 {
00064        // Calls  all or indivdual test cases on the basis of the 
00065        // option selected from menu.
00066 
00067        switch(nMenuID)
00068        {
00069        case ID_INTERFACES_NSIDOMWINDOW_RUNALLTESTS :
00070               RunAllTests();
00071               break;
00072        case ID_INTERFACES_NSIDOMWINDOW_GETDOMDOCUMENT :
00073               GetDocument();
00074               break;
00075        case ID_INTERFACES_NSIDOMWINDOW_GETPARENT : 
00076               GetParent();
00077               break;
00078        case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLBARS :
00079               GetScrollbars();
00080               break;
00081        case ID_INTERFACES_NSIDOMWINDOW_GETFRAMES :
00082               GetFrames();
00083               break;
00084        case ID_INTERFACES_NSIDOMWINDOW_GETNAME :
00085               //GetName();
00086               break;
00087        case ID_INTERFACES_NSIDOMWINDOW_GETTEXTZOOM : 
00088               GetTextZoom();
00089               break;
00090        case ID_INTERFACES_NSIDOMWINDOW_SETTEXTZOOM : 
00091               SetTextZoom();
00092               break;
00093        case ID_INTERFACES_NSIDOMWINDOW_GETSCSOLLX : 
00094               GetScrollX();
00095               break;
00096        case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLY :
00097               GetScrollY();
00098               break;
00099        case ID_INTERFACES_NSIDOMWINDOW_SCROLLTO :
00100               ScrollTo();
00101               break;
00102        case ID_INTERFACES_NSIDOMWINDOW_SCROLLBY :
00103               ScrollBy();
00104               break;
00105        case ID_INTERFACES_NSIDOMWINDOW_GETSELECTION :
00106               GetSelection();
00107               break;
00108        case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYLINES :
00109               ScrollByLines();
00110               break;
00111        case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYPAGES :
00112               ScrollByPages();
00113               break;
00114        case ID_INTERFACES_NSIDOMWINDOW_SIZETOCONTENT :
00115               SizeToContent();
00116               break;
00117        default :
00118               AfxMessageBox("Not added menu handler for this menu item");
00119               break;
00120        }
00121 }
00122 void CDomWindow::RunAllTests()
00123 {
00124        PRInt32 scrollX = 0 ;
00125        PRInt32 scrollY = 0;
00126        PRInt32 bVisible =0;
00127        float fTextZoom = 0.0;
00128 
00129        nsCOMPtr<nsIDOMWindow> oDomWindow;
00130        //nsCOMPtr<nsIDOMWindow> oDomWindowTop;
00131        //nsCOMPtr<nsIDOMWindow> oDomWindowParent;
00132 
00133        nsCOMPtr<nsIDOMBarProp> oDomBarProp;
00134        nsCOMPtr<nsIDOMWindowCollection> oDomWindowCol;
00135        nsCOMPtr<nsIDOMDocument> oDomDocument;
00136        nsCOMPtr<nsISelection> oSelection;
00137        
00138        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00139     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 1);
00140        if (!oDomWindow)
00141        {
00142               AfxMessageBox("Cannot create Dom Window Object");
00143               return;
00144        }
00145 
00146 /*     rv = oDomWindow->GetTop(getter_AddRefs(oDomWindowTop));
00147     RvTestResult(rv, "nsIDOMWindow::GetTop()' rv test", 1);
00148        if (!oDomWindowTop)
00149        {
00150               AfxMessageBox("Cannot create Dom Window Top Object");
00151               return;
00152        }
00153 
00154        rv = oDomWindow->GetParent(getter_AddRefs(oDomWindow));
00155     RvTestResult(rv, "nsIDOMWindow::GetParent()' rv test", 1);
00156        if (!oDomWindow)
00157        {
00158               AfxMessageBox("Cannot create Dom Window Parent Object");
00159               return;
00160        }
00161 
00162 */
00163 
00164        rv = oDomWindow->GetScrollbars(getter_AddRefs(oDomBarProp));
00165     RvTestResult(rv, "nsIDOMWindow::GetScrollbars()' rv test", 1);
00166        if (!oDomBarProp)
00167        {
00168               AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
00169               return;
00170        }
00171 
00172        rv = oDomWindow->GetFrames(getter_AddRefs(oDomWindowCol));
00173     RvTestResult(rv, "nsIDOMWindow::GetFrames()' rv test", 1);
00174        if (!oDomWindowCol)
00175        {
00176               AfxMessageBox("Cannot create Dom Window Collection Object");
00177               return;
00178        }
00179 
00180        rv = oDomWindow->GetDocument(getter_AddRefs(oDomDocument));
00181     RvTestResult(rv, "nsIDOMWindow::GetDocument()' rv test", 1);
00182        if (!oDomDocument)
00183        {
00184               AfxMessageBox("Cannot create Dom Document Object");
00185               return;
00186        }
00187 
00188        rv = oDomWindow->GetSelection(getter_AddRefs(oSelection));
00189     RvTestResult(rv, "nsIDOMWindow::GetSelection()' rv test", 1);
00190        if (!oSelection)
00191        {
00192               AfxMessageBox("Cannot get the  Selection Object");
00193               return;
00194        }
00195 
00196        //  nsIDOMBarProp's only attribute
00197        //rv = oDomBarProp->GetVisible(&bVisible);
00198 
00199 
00200        rv = oDomWindow->GetTextZoom(&fTextZoom);
00201            RvTestResult(rv, "nsIDOMWindow::GetTextZoom()' rv test", 1);
00202 
00203        rv = oDomWindow->SetTextZoom(12.0);
00204        //fTextZoom = 4.0 ;
00205        rv = oDomWindow->SetTextZoom(fTextZoom);
00206            RvTestResult(rv, "nsIDOMWindow::SetTextZoom()' rv test", 1);
00207 
00208        rv = oDomWindow->GetScrollX(&scrollX);
00209           RvTestResult(rv, "nsIDOMWindow::GetScrollX()' rv test", 1);
00210 
00211        rv = oDomWindow->GetScrollY(&scrollY);
00212           RvTestResult(rv, "nsIDOMWindow::GetScrollY()' rv test", 1);
00213 
00214        rv = oDomWindow->ScrollTo(100,100);
00215           RvTestResult(rv, "nsIDOMWindow::ScrollTo()' rv test", 1);
00216 
00217 
00218        rv = oDomWindow->ScrollBy(5, 5);
00219           RvTestResult(rv, "nsIDOMWindow::ScrollBy()' rv test", 1);
00220 
00221        rv = oDomWindow->ScrollByLines(5);
00222           RvTestResult(rv, "nsIDOMWindow::ScrollByLines()' rv test", 1);
00223 
00224        rv = oDomWindow->ScrollByPages(1);
00225           RvTestResult(rv, "nsIDOMWindow::ScrollByPages()' rv test", 1);
00226 
00227        //rv = oDomWindow->SizeToContent();
00228        //   RvTestResult(rv, "nsIDOMWindow::SizeToContent()' rv test", 1);
00229 
00230 }
00231 
00232 void CDomWindow::GetTop()
00233 {
00234        nsCOMPtr<nsIDOMWindow> oDomWindow;
00235        nsCOMPtr<nsIDOMWindow> oDomWindowTop;
00236        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00237     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00238        if (!oDomWindow)
00239        {
00240               AfxMessageBox("Cannot create Dom Window Object");
00241               return;
00242        }
00243 
00244     rv = oDomWindow->GetTop(getter_AddRefs(oDomWindowTop));
00245     RvTestResult(rv, "nsIDOMWindow::GetTop()' rv test", 1);
00246        if (!oDomWindowTop)
00247        {
00248               AfxMessageBox("Cannot create Dom Window Top Object");
00249               return;
00250        }
00251 }
00252 
00253 void CDomWindow::GetParent()
00254 {
00255        nsCOMPtr<nsIDOMWindow> oDomWindow;
00256        nsCOMPtr<nsIDOMWindow> oDomWindowParent;
00257 
00258        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00259     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00260        if (!oDomWindow)
00261        {
00262               AfxMessageBox("Cannot create Dom Window Object");
00263               return;
00264        }
00265 
00266        rv = oDomWindow->GetParent(getter_AddRefs(oDomWindow));
00267     RvTestResult(rv, "nsIDOMWindow::GetParent()' rv test", 0);
00268        if (!oDomWindow)
00269        {
00270               AfxMessageBox("Cannot create Dom Window Parent Object");
00271               return;
00272        }
00273 
00274 }
00275 
00276 
00277 void CDomWindow::GetScrollbars()
00278 {
00279        nsCOMPtr<nsIDOMWindow> oDomWindow;
00280        nsCOMPtr<nsIDOMBarProp> oDomBarProp;
00281 
00282        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00283     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00284        if (!oDomWindow)
00285        {
00286               AfxMessageBox("Cannot create Dom Window Object");
00287               return;
00288        }
00289 
00290        rv = oDomWindow->GetScrollbars(getter_AddRefs(oDomBarProp));
00291     RvTestResult(rv, "nsIDOMWindow::GetScrollbars()' rv test", 0);
00292        if (!oDomBarProp)
00293        {
00294               AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
00295               return;
00296        }
00297 
00298 }
00299 
00300 void CDomWindow::GetFrames()
00301 {
00302        nsCOMPtr<nsIDOMWindow> oDomWindow;
00303        nsCOMPtr<nsIDOMWindowCollection> oDomWindowCol;
00304 
00305        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00306     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00307        if (!oDomWindow)
00308        {
00309               AfxMessageBox("Cannot create Dom Window Object");
00310               return;
00311        }
00312        rv = oDomWindow->GetFrames(getter_AddRefs(oDomWindowCol));
00313     RvTestResult(rv, "nsIDOMWindow::GetFrames()' rv test", 0);
00314        if (!oDomWindowCol)
00315        {
00316               AfxMessageBox("Cannot create Dom Window Collection Object");
00317               return;
00318        }
00319 }
00320 
00321 void CDomWindow::GetDocument()
00322 {
00323        nsCOMPtr<nsIDOMWindow> oDomWindow;
00324        nsCOMPtr<nsIDOMDocument> oDomDocument;
00325 
00326        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00327     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00328        if (!oDomWindow)
00329        {
00330               AfxMessageBox("Cannot create Dom Window Object");
00331               return;
00332        }
00333 
00334        rv = oDomWindow->GetDocument(getter_AddRefs(oDomDocument));
00335     RvTestResult(rv, "nsIDOMWindow::GetDocument()' rv test",0);
00336        if (!oDomDocument)
00337        {
00338               AfxMessageBox("Cannot create Dom Document Object");
00339               return;
00340        }
00341 }
00342 
00343 void CDomWindow::GetSelection()
00344 {
00345        nsCOMPtr<nsIDOMWindow> oDomWindow;
00346        nsCOMPtr<nsISelection> oSelection;
00347 
00348        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00349     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test",0);
00350 
00351        if (!oDomWindow)
00352        {
00353               AfxMessageBox("Cannot create Dom Window Object");
00354               return;
00355        }
00356 
00357        rv = oDomWindow->GetSelection(getter_AddRefs(oSelection));
00358     RvTestResult(rv, "nsIDOMWindow::GetSelection()' rv test", 0);
00359        if (!oSelection)
00360        {
00361               AfxMessageBox("Cannot get the  Selection Object");
00362               return;
00363        }
00364 }
00365 
00366 void CDomWindow::GetTextZoom()
00367 {
00368        float fTextZoom = 0.0 ;
00369        nsCOMPtr<nsIDOMWindow> oDomWindow;
00370        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00371     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00372 
00373        if (!oDomWindow)
00374        {
00375               AfxMessageBox("Cannot create Dom Window Object");
00376               return;
00377        }
00378        rv = oDomWindow->GetTextZoom(&fTextZoom);
00379        RvTestResult(rv, "nsIDOMWindow::GetTextZoom()' rv test", 0);
00380 }
00381 
00382 void CDomWindow::SetTextZoom()
00383 {
00384        float fTextZoom = 0.0 ;
00385 
00386        fTextZoom = 12.0;
00387        rv = GetDOMOWindowObject()->SetTextZoom(fTextZoom);
00388        RvTestResult(rv, "nsIDOMWindow::SetTextZoom()' rv test", 0);
00389 }
00390 
00391 void CDomWindow::GetScrollX()
00392 {
00393        PRInt32 scrollX = 0 ;
00394        nsCOMPtr<nsIDOMWindow> oDomWindow;
00395        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00396     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00397 
00398        if (!oDomWindow)
00399        {
00400               AfxMessageBox("Cannot create Dom Window Object");
00401               return;
00402        }
00403        rv = oDomWindow->GetScrollX(&scrollX);
00404        RvTestResult(rv, "nsIDOMWindow::GetScrollX()' rv test", 0);
00405 }
00406 
00407 void CDomWindow::GetScrollY()
00408 {      
00409        PRInt32 scrollY = 0 ;
00410        nsCOMPtr<nsIDOMWindow> oDomWindow;
00411        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00412     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00413 
00414        if (!oDomWindow)
00415        {
00416               AfxMessageBox("Cannot create Dom Window Object");
00417               return;
00418        }
00419        rv = oDomWindow->GetScrollY(&scrollY);
00420        RvTestResult(rv, "nsIDOMWindow::GetScrollY()' rv test", 0);
00421 }
00422 
00423 void CDomWindow::ScrollTo()
00424 {
00425        nsCOMPtr<nsIDOMWindow> oDomWindow;
00426        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00427     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00428 
00429        if (!oDomWindow)
00430        {
00431               AfxMessageBox("Cannot create Dom Window Object");
00432               return;
00433        }
00434        rv = oDomWindow->ScrollTo(100,100);
00435     RvTestResult(rv, "nsIDOMWindow::ScrollTo()' rv test", 0);
00436 }
00437 
00438 
00439 void CDomWindow::ScrollBy()
00440 {
00441        nsCOMPtr<nsIDOMWindow> oDomWindow;
00442        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00443     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00444 
00445        if (!oDomWindow)
00446        {
00447               AfxMessageBox("Cannot create Dom Window Object");
00448               return;
00449        }
00450        rv = oDomWindow->ScrollBy(5, 5);
00451        RvTestResult(rv, "nsIDOMWindow::ScrollBy()' rv test", 0);
00452 }
00453 
00454 void CDomWindow::ScrollByLines()
00455 {
00456        nsCOMPtr<nsIDOMWindow> oDomWindow;
00457        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00458     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00459 
00460        if (!oDomWindow)
00461        {
00462               AfxMessageBox("Cannot create Dom Window Object");
00463               return;
00464        }
00465        rv = oDomWindow->ScrollByLines(5);
00466     RvTestResult(rv, "nsIDOMWindow::ScrollByLines()' rv test",0);
00467 
00468 }
00469 
00470 void CDomWindow::ScrollByPages()
00471 {
00472        nsCOMPtr<nsIDOMWindow> oDomWindow;
00473        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00474     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00475 
00476        if (!oDomWindow)
00477        {
00478               AfxMessageBox("Cannot create Dom Window Object");
00479               return;
00480        }
00481        rv = oDomWindow->ScrollByPages(1);
00482        RvTestResult(rv, "nsIDOMWindow::ScrollByPages()' rv test", 0);
00483 }
00484 
00485 void CDomWindow::SizeToContent()
00486 {
00487        nsCOMPtr<nsIDOMWindow> oDomWindow;
00488        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00489     RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow()' rv test", 0);
00490 
00491        if (!oDomWindow)
00492        {
00493               AfxMessageBox("Cannot create Dom Window Object");
00494               return;
00495        }
00496        rv = oDomWindow->SizeToContent();
00497        RvTestResult(rv, "nsIDOMWindow::SizeToContent()' rv test", 0);
00498 }
00499 
00500 
00501 nsIDOMWindow* CDomWindow::GetDOMOWindowObject()
00502 {
00503        nsCOMPtr<nsIDOMWindow> oDomWindow;
00504        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(oDomWindow));
00505        if (!oDomWindow)
00506               AfxMessageBox("Cannot create Dom Window Object");
00507        return oDomWindow;
00508 
00509 }