Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / nsIWebBrow.cpp
blob40995ed748338b734b96333c088d031e1b6c4188
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
13 * License.
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.
22 * Contributor(s):
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 nsIWebBrowser and nsIWebBrowserSetup
43 #include "Stdafx.h"
44 #include "TestEmbed.h"
45 #include "BrowserImpl.h"
46 #include "BrowserFrm.h"
47 #include "Tests.h"
48 #include "domwindow.h"
49 #include "QaUtils.h"
50 #include <stdio.h>
51 #include "nsIWebBrow.h"
53 #ifdef _DEBUG
54 #define new DEBUG_NEW
55 #undef THIS_FILE
56 static char THIS_FILE[] = __FILE__;
57 #endif
59 // constructor for CNsIWebBrowser
60 CNsIWebBrowser::CNsIWebBrowser(nsIWebBrowser *mWebBrowser, CBrowserImpl *mpBrowserImpl)
62 qaWebBrowser = mWebBrowser;
63 qaBrowserImpl = mpBrowserImpl;
66 // destructor for CNsIWebBrowser
67 CNsIWebBrowser::~CNsIWebBrowser()
72 void CNsIWebBrowser::WBAddListener(PRInt16 displayMode)
74 // AddWebBrowserListener
75 nsWeakPtr weakling(
76 do_GetWeakReference(static_cast<nsIContextMenuListener*>(qaBrowserImpl)));
77 rv = qaWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIContextMenuListener));
78 RvTestResult(rv, "AddWebBrowserListener(). nsIContextMenuListener test", displayMode);
79 RvTestResultDlg(rv, "AddWebBrowserListener(). nsIContextMenuListener test", true);
82 void CNsIWebBrowser::WBRemoveListener(PRInt16 displayMode)
84 // RemoveWebBrowserListener
85 nsWeakPtr weakling(
86 do_GetWeakReference(static_cast<nsIContextMenuListener*>(qaBrowserImpl)));
88 rv = qaWebBrowser->RemoveWebBrowserListener(weakling, NS_GET_IID(nsIContextMenuListener));
89 RvTestResult(rv, "RemoveWebBrowserListener(). nsIContextMenuListener test", displayMode);
90 RvTestResultDlg(rv, "RemoveWebBrowserListener(). nsIContextMenuListener test");
93 void CNsIWebBrowser::WBGetContainerWindow(PRInt16 displayMode)
95 // GetContainerWindow
96 nsCOMPtr<nsIWebBrowserChrome> qaWebBrowserChrome;
97 rv = qaWebBrowser->GetContainerWindow(getter_AddRefs(qaWebBrowserChrome));
98 RvTestResult(rv, "nsIWebBrowser::GetContainerWindow() test", displayMode);
99 RvTestResultDlg(rv, "nsIWebBrowser::GetContainerWindow() test");
100 if (!qaWebBrowserChrome)
101 QAOutput("Didn't get web browser chrome object.", displayMode);
102 else {
103 rv = qaWebBrowserChrome->ShowAsModal();
104 RvTestResult(rv, "nsIWebBrowserChrome::ShowAsModal() test", displayMode);
105 RvTestResultDlg(rv, "nsIWebBrowserChrome::ShowAsModal() test");
109 void CNsIWebBrowser::WBSetContainerWindow(PRInt16 displayMode)
111 // SetContainerWindow
113 rv = qaWebBrowser->SetContainerWindow(static_cast<nsIWebBrowserChrome*>(qaBrowserImpl));
114 RvTestResult(rv, "nsIWebBrowser::SetContainerWindow() test", displayMode);
115 RvTestResultDlg(rv, "nsIWebBrowser::SetContainerWindow() test");
118 void CNsIWebBrowser::WBGetURIContentListener(PRInt16 displayMode)
120 // GetParentURIContentListener
122 rv = qaWebBrowser->GetParentURIContentListener(getter_AddRefs(qaURIContentListener));
123 RvTestResult(rv, "nsIWebBrowser::GetParentURIContentListener() test", displayMode);
124 RvTestResultDlg(rv, "nsIWebBrowser::GetParentURIContentListener() test");
125 if (!qaURIContentListener)
126 QAOutput("Didn't get uri content listener object.", displayMode);
127 else {
128 nsCOMPtr<nsISupports> qaSupports;
129 rv = qaURIContentListener->GetLoadCookie(getter_AddRefs(qaSupports));
130 RvTestResult(rv, "nsIURIContentListener::GetLoadCookie() test", displayMode);
131 RvTestResultDlg(rv, "nsIURIContentListener::GetLoadCookie() test");
135 void CNsIWebBrowser::WBSetURIContentListener(PRInt16 displayMode)
137 // SetParentURIContentListener
139 rv = qaWebBrowser->SetParentURIContentListener(static_cast<nsIURIContentListener*>(qaBrowserImpl));
140 RvTestResult(rv, "nsIWebBrowser::SetParentURIContentListener() test", displayMode);
141 RvTestResultDlg(rv, "nsIWebBrowser::SetParentURIContentListener() test");
144 void CNsIWebBrowser::WBGetDOMWindow(PRInt16 displayMode)
146 // GetContentDOMWindow
147 nsCOMPtr<nsIDOMWindow> qaDOMWindow;
148 rv = qaWebBrowser->GetContentDOMWindow(getter_AddRefs(qaDOMWindow));
149 RvTestResult(rv, "nsIWebBrowser::GetContentDOMWindow() test", displayMode);
150 RvTestResultDlg(rv, "nsIWebBrowser::GetContentDOMWindow() test");
151 if (!qaDOMWindow)
152 QAOutput("Didn't get dom window object.", displayMode);
153 else {
154 rv = qaDOMWindow->ScrollTo(50,50);
155 RvTestResult(rv, "nsIDOMWindow::ScrollTo() test", displayMode);
156 RvTestResultDlg(rv, "nsIDOMWindow::ScrollTo() test");
160 void CNsIWebBrowser::OnStartTests(UINT nMenuID)
162 switch(nMenuID)
164 case ID_INTERFACES_NSIWEBBROWSER_RUNALLTESTS :
165 RunAllTests();
166 break ;
167 case ID_INTERFACES_NSIWEBBROWSER_ADDWEBBROWSERLISTENER :
168 WBAddListener(2);
169 break ;
170 case ID_INTERFACES_NSIWEBBROWSER_REMOVEWEBBROWSERLISTENER :
171 WBRemoveListener(2);
172 break ;
173 case ID_INTERFACES_NSIWEBBROWSER_GETCONTAINERWINDOW :
174 WBGetContainerWindow(2);
175 break ;
176 case ID_INTERFACES_NSIWEBBROWSER_SETCONTAINERWINDOW :
177 WBSetContainerWindow(2);
178 break ;
179 case ID_INTERFACES_NSIWEBBROWSER_GETPARENTURICONTENTLISTENER :
180 WBGetURIContentListener(2);
181 break ;
182 case ID_INTERFACES_NSIWEBBROWSER_SETPARENTURICONTENTLISTENER :
183 WBSetURIContentListener(2);
184 break ;
185 case ID_INTERFACES_NSIWEBBROWSER_GETCONTENTDOMWINDOW :
186 WBGetDOMWindow(2);
187 break ;
188 case ID_INTERFACES_NSIWEBBROWSER_NSIWBSETUPSETPROPERTY :
189 WBSSetupProperty(2);
190 break ;
194 void CNsIWebBrowser::RunAllTests()
196 WBAddListener(1);
197 WBRemoveListener(1);
198 WBSetContainerWindow(1);
199 WBGetContainerWindow(1);
200 WBSetURIContentListener(1);
201 WBGetURIContentListener(1);
202 WBGetDOMWindow(1);
203 WBSSetupProperty(1);
206 void CNsIWebBrowser::WBSSetupProperty(PRInt16 displayMode)
208 // nsIWebBrowserSetup methods
210 nsCOMPtr <nsIWebBrowserSetup> qaWBSetup(do_QueryInterface(qaWebBrowser, &rv));
211 RvTestResult(rv, "nsIWebBrowserSetup object test", displayMode);
212 RvTestResultDlg(rv, "nsIWebBrowserSetup object test");
214 if (!qaWBSetup) {
215 QAOutput("Didn't get WebBrowser Setup object.", displayMode);
216 return;
219 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, PR_TRUE);
220 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_TRUE)", 1);
221 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_TRUE)");
223 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, PR_FALSE);
224 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_FALSE)", 1);
225 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_PLUGINS, PR_FALSE)");
227 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT, PR_TRUE);
228 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_TRUE)", 1);
229 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_TRUE)");
231 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT, PR_FALSE);
232 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_FALSE)", 1);
233 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_JAVASCRIPT, PR_FALSE)");
235 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS, PR_TRUE);
236 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_TRUE)", 1);
237 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_TRUE)");
239 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_META_REDIRECTS, PR_FALSE);
240 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_FALSE)", 1);
241 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_META_REDIRECTS, PR_FALSE)");
243 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES, PR_TRUE);
244 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_TRUE)", 1);
245 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_TRUE)");
247 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_SUBFRAMES, PR_FALSE);
248 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_FALSE)", 1);
249 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_SUBFRAMES, PR_FALSE)");
251 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_IMAGES, PR_TRUE);
252 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_TRUE)", 1);
253 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_TRUE)");
255 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_IMAGES, PR_FALSE);
256 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_FALSE)", 1);
257 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_ALLOW_IMAGES, PR_FALSE)");
259 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE);
260 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE)", 1);
261 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_TRUE)");
263 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE);
264 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE)", 1);
265 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_FOCUS_DOC_BEFORE_CONTENT, PR_FALSE)");
267 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_TRUE);
268 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_TRUE)", 1);
269 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_TRUE)");
271 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_USE_GLOBAL_HISTORY, PR_FALSE);
272 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_FALSE)", 1);
273 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_USE_GLOBAL_HISTORY, PR_FALSE)");
275 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER, PR_TRUE);
276 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_TRUE)", 1);
277 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_TRUE)");
279 rv = qaWBSetup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER, PR_FALSE);
280 RvTestResult(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_FALSE)", 1);
281 RvTestResultDlg(rv, "nsIWebBrowserSetup:SetProperty(SETUP_IS_CHROME_WRAPPER, PR_FALSE)");