Back to index

lightning-sunbird  0.9+nobinonly
nsIWebBrow.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 nsIWebBrowser and nsIWebBrowserSetup
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 "nsIWebBrow.h"
00052 
00053 #ifdef _DEBUG
00054 #define new DEBUG_NEW
00055 #undef THIS_FILE
00056 static char THIS_FILE[] = __FILE__;
00057 #endif
00058 
00059 // constructor for CNsIWebBrowser
00060 CNsIWebBrowser::CNsIWebBrowser(nsIWebBrowser *mWebBrowser, CBrowserImpl *mpBrowserImpl)
00061 {
00062        qaWebBrowser = mWebBrowser;
00063        qaBrowserImpl = mpBrowserImpl;
00064 }
00065 
00066 // destructor for CNsIWebBrowser
00067 CNsIWebBrowser::~CNsIWebBrowser()
00068 {
00069 
00070 }
00071 
00072 void CNsIWebBrowser::WBAddListener(PRInt16 displayMode)
00073 {
00074        // AddWebBrowserListener
00075        nsWeakPtr weakling(
00076         do_GetWeakReference(NS_STATIC_CAST(nsIContextMenuListener*, qaBrowserImpl)));
00077     rv = qaWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIContextMenuListener));
00078        RvTestResult(rv, "AddWebBrowserListener(). nsIContextMenuListener test", displayMode);
00079        RvTestResultDlg(rv, "AddWebBrowserListener(). nsIContextMenuListener test", true);
00080 }
00081 
00082 void CNsIWebBrowser::WBRemoveListener(PRInt16 displayMode)
00083 {
00084        // RemoveWebBrowserListener
00085        nsWeakPtr weakling(
00086         do_GetWeakReference(NS_STATIC_CAST(nsIContextMenuListener*, qaBrowserImpl)));
00087 
00088        rv = qaWebBrowser->RemoveWebBrowserListener(weakling, NS_GET_IID(nsIContextMenuListener));
00089        RvTestResult(rv, "RemoveWebBrowserListener(). nsIContextMenuListener test", displayMode);
00090        RvTestResultDlg(rv, "RemoveWebBrowserListener(). nsIContextMenuListener test");
00091 }
00092 
00093 void CNsIWebBrowser::WBGetContainerWindow(PRInt16 displayMode)
00094 {
00095        // GetContainerWindow
00096        nsCOMPtr<nsIWebBrowserChrome> qaWebBrowserChrome;
00097        rv = qaWebBrowser->GetContainerWindow(getter_AddRefs(qaWebBrowserChrome));
00098        RvTestResult(rv, "nsIWebBrowser::GetContainerWindow() test", displayMode);
00099        RvTestResultDlg(rv, "nsIWebBrowser::GetContainerWindow() test");
00100        if (!qaWebBrowserChrome)
00101               QAOutput("Didn't get web browser chrome object.", displayMode);
00102        else {
00103               rv = qaWebBrowserChrome->ShowAsModal();
00104               RvTestResult(rv, "nsIWebBrowserChrome::ShowAsModal() test", displayMode);
00105               RvTestResultDlg(rv, "nsIWebBrowserChrome::ShowAsModal() test");
00106        }
00107 }
00108 
00109 void CNsIWebBrowser::WBSetContainerWindow(PRInt16 displayMode)
00110 {
00111        // SetContainerWindow
00112 
00113        rv = qaWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, qaBrowserImpl));
00114        RvTestResult(rv, "nsIWebBrowser::SetContainerWindow() test", displayMode);
00115        RvTestResultDlg(rv, "nsIWebBrowser::SetContainerWindow() test");
00116 }
00117 
00118 void CNsIWebBrowser::WBGetURIContentListener(PRInt16 displayMode)
00119 {
00120        // GetParentURIContentListener
00121 
00122        rv = qaWebBrowser->GetParentURIContentListener(getter_AddRefs(qaURIContentListener));
00123        RvTestResult(rv, "nsIWebBrowser::GetParentURIContentListener() test", displayMode);
00124        RvTestResultDlg(rv, "nsIWebBrowser::GetParentURIContentListener() test");
00125        if (!qaURIContentListener)
00126               QAOutput("Didn't get uri content listener object.", displayMode);
00127        else {
00128               nsCOMPtr<nsISupports> qaSupports;
00129               rv = qaURIContentListener->GetLoadCookie(getter_AddRefs(qaSupports));
00130               RvTestResult(rv, "nsIURIContentListener::GetLoadCookie() test", displayMode);
00131               RvTestResultDlg(rv, "nsIURIContentListener::GetLoadCookie() test");
00132        }
00133 }
00134 
00135 void CNsIWebBrowser::WBSetURIContentListener(PRInt16 displayMode)
00136 {
00137        // SetParentURIContentListener
00138 
00139        rv = qaWebBrowser->SetParentURIContentListener(NS_STATIC_CAST(nsIURIContentListener*, qaBrowserImpl));
00140        RvTestResult(rv, "nsIWebBrowser::SetParentURIContentListener() test", displayMode);
00141        RvTestResultDlg(rv, "nsIWebBrowser::SetParentURIContentListener() test");
00142 }
00143 
00144 void CNsIWebBrowser::WBGetDOMWindow(PRInt16 displayMode)
00145 {
00146        // GetContentDOMWindow
00147        nsCOMPtr<nsIDOMWindow> qaDOMWindow;
00148        rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(qaDOMWindow));
00149        RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow() test", displayMode);
00150        RvTestResultDlg(rv, "nsIWebBrowser::GetContentDOMWindow() test");
00151        if (!qaDOMWindow)
00152               QAOutput("Didn't get dom window object.", displayMode);
00153        else {
00154               rv = qaDOMWindow->ScrollTo(50,50);
00155               RvTestResult(rv, "nsIDOMWindow::ScrollTo() test", displayMode);
00156               RvTestResultDlg(rv, "nsIDOMWindow::ScrollTo() test");
00157        }
00158 }
00159 
00160 void CNsIWebBrowser::OnStartTests(UINT nMenuID)
00161 {
00162        switch(nMenuID)
00163        {
00164               case ID_INTERFACES_NSIWEBBROWSER_RUNALLTESTS :
00165                      RunAllTests();
00166                      break ;
00167               case ID_INTERFACES_NSIWEBBROWSER_ADDWEBBROWSERLISTENER :
00168                      WBAddListener(2);
00169                      break ;
00170               case ID_INTERFACES_NSIWEBBROWSER_REMOVEWEBBROWSERLISTENER :
00171                      WBRemoveListener(2);
00172                      break ;
00173               case ID_INTERFACES_NSIWEBBROWSER_GETCONTAINERWINDOW  :
00174                      WBGetContainerWindow(2);
00175                      break ;
00176               case ID_INTERFACES_NSIWEBBROWSER_SETCONTAINERWINDOW :
00177                      WBSetContainerWindow(2);
00178                      break ;
00179               case ID_INTERFACES_NSIWEBBROWSER_GETPARENTURICONTENTLISTENER :
00180                      WBGetURIContentListener(2);
00181                      break ;
00182               case ID_INTERFACES_NSIWEBBROWSER_SETPARENTURICONTENTLISTENER :
00183                      WBSetURIContentListener(2);
00184                      break ;
00185               case ID_INTERFACES_NSIWEBBROWSER_GETCONTENTDOMWINDOW  :
00186                      WBGetDOMWindow(2);
00187                      break ;
00188               case ID_INTERFACES_NSIWEBBROWSER_NSIWBSETUPSETPROPERTY  :
00189                      WBSSetupProperty(2);
00190                      break ;
00191        }
00192 }
00193 
00194 void CNsIWebBrowser::RunAllTests()
00195 {
00196        WBAddListener(1);
00197        WBRemoveListener(1);
00198        WBSetContainerWindow(1);
00199        WBGetContainerWindow(1);
00200        WBSetURIContentListener(1);
00201        WBGetURIContentListener(1);
00202        WBGetDOMWindow(1);
00203        WBSSetupProperty(1);
00204 }
00205 
00206 void CNsIWebBrowser::WBSSetupProperty(PRInt16 displayMode)
00207 {
00208        // nsIWebBrowserSetup methods
00209 
00210        nsCOMPtr <nsIWebBrowserSetup> qaWBSetup(do_QueryInterface(qaWebBrowser, &rv));
00211        RvTestResult(rv, "nsIWebBrowserSetup object test", displayMode);
00212        RvTestResultDlg(rv, "nsIWebBrowserSetup object test");
00213 
00214        if (!qaWBSetup) {
00215               QAOutput("Didn't get WebBrowser Setup object.", displayMode);
00216               return;
00217        }
00218 
00219        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, PR_TRUE);
00220        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_TRUE)", 1);
00221        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_TRUE)");
00222 
00223        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, PR_FALSE);
00224        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_FALSE)", 1);
00225        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_FALSE)");
00226 
00227        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT, PR_TRUE);
00228        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_TRUE)", 1);
00229        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_TRUE)");
00230 
00231        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT, PR_FALSE);
00232        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_FALSE)", 1);
00233        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_FALSE)");
00234 
00235        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS, PR_TRUE);
00236        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_TRUE)", 1);
00237        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_TRUE)");
00238 
00239        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS, PR_FALSE);
00240        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_FALSE)", 1);
00241        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_FALSE)");
00242 
00243        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES, PR_TRUE);
00244        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_TRUE)", 1);
00245        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_TRUE)");
00246 
00247        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES, PR_FALSE);
00248        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_FALSE)", 1);
00249        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_FALSE)");
00250 
00251        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_IMAGES, PR_TRUE);
00252        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_TRUE)", 1);
00253        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_TRUE)");
00254 
00255        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_IMAGES, PR_FALSE);
00256        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_FALSE)", 1);
00257        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_FALSE)");
00258 
00259        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE);
00260        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE)", 1);
00261        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE)");
00262 
00263        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE);
00264        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE)", 1);
00265        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE)");
00266 
00267        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_TRUE);
00268        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_TRUE)", 1);
00269        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_TRUE)");
00270 
00271        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_FALSE);
00272        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_FALSE)", 1);
00273        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_FALSE)");
00274 
00275        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER, PR_TRUE);
00276        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_TRUE)", 1);
00277        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_TRUE)");
00278 
00279        rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER, PR_FALSE);
00280        RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_FALSE)", 1);
00281        RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_FALSE)");
00282 }