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 ***** */
39 // nsiWebProg.cpp : implementation file
43 #include "TestEmbed.h"
44 #include "nsIWebProg.h"
47 #include "BrowserFrm.h"
48 #include "BrowserImpl.h"
49 #include "BrowserView.h"
50 #include "domwindow.h"
51 #include "WebProgDlg.h"
56 static char THIS_FILE
[] = __FILE__
;
59 /////////////////////////////////////////////////////////////////////////////
62 // constructor for CnsiWebProg
63 CnsiWebProg::CnsiWebProg(nsIWebBrowser
*mWebBrowser
,
64 CBrowserImpl
*mpBrowserImpl
)
66 qaWebBrowser
= mWebBrowser
;
67 qaBrowserImpl
= mpBrowserImpl
;
70 // destructor for CnsiWebProg
71 CnsiWebProg::~CnsiWebProg()
75 // nsIWebProgress test cases
78 nsIWebProgress
* CnsiWebProg::GetWebProgObject()
80 nsCOMPtr
<nsIInterfaceRequestor
> qaIReq(do_QueryInterface(qaWebBrowser
));
81 nsCOMPtr
<nsIWebProgress
> qaWebProgress(do_GetInterface(qaIReq
));
84 QAOutput("Didn't get web progress object.", 2);
88 QAOutput("We got web progress object.", 1);
89 return (qaWebProgress
);
93 void CnsiWebProg::AddWebProgLstnr(PRUint32 theFlag
, PRInt16 displayMode
)
95 nsCAutoString
flagName(NS_LITERAL_CSTRING("xxxx"));
97 ConvertWPFlagToString(theFlag
, flagName
);
100 qaWebProgress
= GetWebProgObject();
101 nsCOMPtr
<nsIWebProgressListener
> listener(static_cast<nsIWebProgressListener
*>(qaBrowserImpl
));
102 rv
= qaWebProgress
->AddProgressListener(listener
, theFlag
);
103 // StoreWebProgFlag(theFlag);
104 RvTestResult(rv
, "nsIWebProgress::AddProgressListener() test", displayMode
);
105 RvTestResultDlg(rv
, "nsIWebProgress::AddProgressListener() test", true);
106 FormatAndPrintOutput("WebProgressListener flag = ", flagName
, displayMode
);
109 void CnsiWebProg::RemoveWebProgLstnr(PRInt16 displayMode
)
111 // removeWebProgListener
112 qaWebProgress
= GetWebProgObject();
113 nsCOMPtr
<nsIWebProgressListener
> listener(static_cast<nsIWebProgressListener
*>(qaBrowserImpl
));
114 rv
= qaWebProgress
->RemoveProgressListener(listener
);
115 RvTestResult(rv
, "nsIWebProgress::RemoveProgressListener() test", displayMode
);
116 RvTestResultDlg(rv
, "nsIWebProgress::RemoveProgressListener() test");
119 void CnsiWebProg::GetTheDOMWindow(PRInt16 displayMode
)
122 qaWebProgress
= GetWebProgObject();
123 nsCOMPtr
<nsIDOMWindow
> qaDOMWindow
;
124 rv
= qaWebProgress
->GetDOMWindow(getter_AddRefs(qaDOMWindow
));
125 RvTestResult(rv
, "nsIWebProgress::GetDOMWindow() test", displayMode
);
126 RvTestResultDlg(rv
, "nsIWebProgress::GetDOMWindow() test");
128 QAOutput("Didn't get DOM Window object.", displayMode
);
131 void CnsiWebProg::GetIsLoadingDocTest(PRInt16 displayMode
)
134 qaWebProgress
= GetWebProgObject();
135 rv
= qaWebProgress
->GetIsLoadingDocument(&docLoading
);
136 RvTestResult(rv
, "nsIWebProgress::GetisLoadingDocument() test", displayMode
);
137 RvTestResultDlg(rv
, "nsIWebProgress::GetisLoadingDocument() test");
138 FormatAndPrintOutput("GetisLoadingDocument return value = ", docLoading
, displayMode
);
141 void CnsiWebProg::ConvertWPFlagToString(PRUint32 theFlag
,
142 nsCAutoString
& flagName
)
146 case nsIWebProgress::NOTIFY_STATE_REQUEST
:
147 flagName
.AssignLiteral("NOTIFY_STATE_REQUEST");
149 case nsIWebProgress::NOTIFY_STATE_DOCUMENT
:
150 flagName
.AssignLiteral("NOTIFY_STATE_DOCUMENT");
152 case nsIWebProgress::NOTIFY_STATE_NETWORK
:
153 flagName
.AssignLiteral("NOTIFY_STATE_NETWORK");
155 case nsIWebProgress::NOTIFY_STATE_WINDOW
:
156 flagName
.AssignLiteral("NOTIFY_STATE_WINDOW");
158 case nsIWebProgress::NOTIFY_STATE_ALL
:
159 flagName
.AssignLiteral("NOTIFY_STATE_ALL");
161 case nsIWebProgress::NOTIFY_PROGRESS
:
162 flagName
.AssignLiteral("NOTIFY_PROGRESS");
164 case nsIWebProgress::NOTIFY_STATUS
:
165 flagName
.AssignLiteral("NOTIFY_STATUS");
167 case nsIWebProgress::NOTIFY_SECURITY
:
168 flagName
.AssignLiteral("NOTIFY_SECURITY");
170 case nsIWebProgress::NOTIFY_LOCATION
:
171 flagName
.AssignLiteral("NOTIFY_LOCATION");
173 case nsIWebProgress::NOTIFY_ALL
:
174 flagName
.AssignLiteral("NOTIFY_ALL");
176 case nsIWebProgress::NOTIFY_STATE_DOCUMENT
| nsIWebProgress::NOTIFY_STATE_REQUEST
:
177 flagName
.AssignLiteral("NOTIFY_STATE_DOCUMENT&REQUEST");
179 case nsIWebProgress::NOTIFY_STATE_DOCUMENT
| nsIWebProgress::NOTIFY_STATE_REQUEST
180 | nsIWebProgress::NOTIFY_STATE_NETWORK
:
181 flagName
.AssignLiteral("NOTIFY_STATE_DOCUMENT&REQUEST&NETWORK");
183 case nsIWebProgress::NOTIFY_STATE_NETWORK
| nsIWebProgress::NOTIFY_STATE_WINDOW
:
184 flagName
.AssignLiteral("NOTIFY_STATE_NETWORK&WINDOW");
189 void CnsiWebProg::StoreWebProgFlag(PRUint32 theFlag
)
191 theStoredFlag
= theFlag
;
194 void CnsiWebProg::RetrieveWebProgFlag()
197 nsCAutoString
flagName(NS_LITERAL_CSTRING("NOTIFY_ALL"));
199 theFlag
= theStoredFlag
;
200 ConvertWPFlagToString(theFlag
, flagName
);
201 FormatAndPrintOutput("WebProgressListener flag = ", flagName
, 2);
204 void CnsiWebProg::OnStartTests(UINT nMenuID
)
206 CWebProgDlg myDialog
;
210 case ID_INTERFACES_NSIWEBPROGRESS_RUNALLTESTS
:
213 case ID_INTERFACES_NSIWEBPROGRESS_ADDPROGRESSLISTENER
:
214 if (myDialog
.DoModal() == IDOK
)
215 AddWebProgLstnr(myDialog
.m_wpFlagValue
, 2);
217 case ID_INTERFACES_NSIWEBPROGRESS_REMOVEPROGRESSLISTENER
:
218 RemoveWebProgLstnr(2);
220 case ID_INTERFACES_NSIWEBPROGRESS_GETDOMWINDOW
:
223 case ID_INTERFACES_NSIWEBPROGRESS_ISLOADINGDOCUMENT
:
224 GetIsLoadingDocTest(2);
229 void CnsiWebProg::RunAllTests(void)
232 PRUint32 theFlag
= 0x000000ff;
233 for (i
= 0; i
< 10; i
++) {
236 theFlag
= nsIWebProgress::NOTIFY_STATE_REQUEST
;
239 theFlag
= nsIWebProgress::NOTIFY_STATE_DOCUMENT
;
242 theFlag
= nsIWebProgress::NOTIFY_STATE_NETWORK
;
245 theFlag
= nsIWebProgress::NOTIFY_STATE_WINDOW
;
248 theFlag
= nsIWebProgress::NOTIFY_STATE_ALL
;
251 theFlag
= nsIWebProgress::NOTIFY_PROGRESS
;
254 theFlag
= nsIWebProgress::NOTIFY_STATUS
;
257 theFlag
= nsIWebProgress::NOTIFY_SECURITY
;
260 theFlag
= nsIWebProgress::NOTIFY_LOCATION
;
263 theFlag
= nsIWebProgress::NOTIFY_ALL
;
266 AddWebProgLstnr(theFlag
, 1);
267 RemoveWebProgLstnr(1);
270 GetIsLoadingDocTest(1);
273 /////////////////////////////////////////////////////////////////////////////
274 // CnsiWebProg message handlers