Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / DomWindow.cpp
blob0448c3272963eb832eaaf6a50472711826dc06ed
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 * 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 ***** */
39 // File Overview....
41 // Test cases for the nsIDOMWindow Interface
44 #include "stdafx.h"
45 #include "QaUtils.h"
46 #include <stdio.h>
47 #include "domWindow.h"
48 #include "resource.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.
67 switch(nMenuID)
69 case ID_INTERFACES_NSIDOMWINDOW_RUNALLTESTS :
70 RunAllTests();
71 break;
72 case ID_INTERFACES_NSIDOMWINDOW_GETDOMDOCUMENT :
73 GetDocument();
74 break;
75 case ID_INTERFACES_NSIDOMWINDOW_GETPARENT :
76 GetParent();
77 break;
78 case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLBARS :
79 GetScrollbars();
80 break;
81 case ID_INTERFACES_NSIDOMWINDOW_GETFRAMES :
82 GetFrames();
83 break;
84 case ID_INTERFACES_NSIDOMWINDOW_GETNAME :
85 //GetName();
86 break;
87 case ID_INTERFACES_NSIDOMWINDOW_GETTEXTZOOM :
88 GetTextZoom();
89 break;
90 case ID_INTERFACES_NSIDOMWINDOW_SETTEXTZOOM :
91 SetTextZoom();
92 break;
93 case ID_INTERFACES_NSIDOMWINDOW_GETSCSOLLX :
94 GetScrollX();
95 break;
96 case ID_INTERFACES_NSIDOMWINDOW_GETSCROLLY :
97 GetScrollY();
98 break;
99 case ID_INTERFACES_NSIDOMWINDOW_SCROLLTO :
100 ScrollTo();
101 break;
102 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBY :
103 ScrollBy();
104 break;
105 case ID_INTERFACES_NSIDOMWINDOW_GETSELECTION :
106 GetSelection();
107 break;
108 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYLINES :
109 ScrollByLines();
110 break;
111 case ID_INTERFACES_NSIDOMWINDOW_SCROLLBYPAGES :
112 ScrollByPages();
113 break;
114 case ID_INTERFACES_NSIDOMWINDOW_SIZETOCONTENT :
115 SizeToContent();
116 break;
117 default :
118 AfxMessageBox("Not added menu handler for this menu item");
119 break;
122 void CDomWindow::RunAllTests()
124 PRInt32 scrollX = 0 ;
125 PRInt32 scrollY = 0;
126 PRInt32 bVisible =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);
140 if (!oDomWindow)
142 AfxMessageBox("Cannot create Dom Window Object");
143 return;
146 /* rv = oDomWindow->GetTop(getter_AddRefs(oDomWindowTop));
147 RvTestResult(rv, "nsIDOMWindow::GetTop()' rv test", 1);
148 if (!oDomWindowTop)
150 AfxMessageBox("Cannot create Dom Window Top Object");
151 return;
154 rv = oDomWindow->GetParent(getter_AddRefs(oDomWindow));
155 RvTestResult(rv, "nsIDOMWindow::GetParent()' rv test", 1);
156 if (!oDomWindow)
158 AfxMessageBox("Cannot create Dom Window Parent Object");
159 return;
164 rv = oDomWindow->GetScrollbars(getter_AddRefs(oDomBarProp));
165 RvTestResult(rv, "nsIDOMWindow::GetScrollbars()' rv test", 1);
166 if (!oDomBarProp)
168 AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
169 return;
172 rv = oDomWindow->GetFrames(getter_AddRefs(oDomWindowCol));
173 RvTestResult(rv, "nsIDOMWindow::GetFrames()' rv test", 1);
174 if (!oDomWindowCol)
176 AfxMessageBox("Cannot create Dom Window Collection Object");
177 return;
180 rv = oDomWindow->GetDocument(getter_AddRefs(oDomDocument));
181 RvTestResult(rv, "nsIDOMWindow::GetDocument()' rv test", 1);
182 if (!oDomDocument)
184 AfxMessageBox("Cannot create Dom Document Object");
185 return;
188 rv = oDomWindow->GetSelection(getter_AddRefs(oSelection));
189 RvTestResult(rv, "nsIDOMWindow::GetSelection()' rv test", 1);
190 if (!oSelection)
192 AfxMessageBox("Cannot get the Selection Object");
193 return;
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);
204 //fTextZoom = 4.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);
238 if (!oDomWindow)
240 AfxMessageBox("Cannot create Dom Window Object");
241 return;
244 rv = oDomWindow->GetTop(getter_AddRefs(oDomWindowTop));
245 RvTestResult(rv, "nsIDOMWindow::GetTop()' rv test", 1);
246 if (!oDomWindowTop)
248 AfxMessageBox("Cannot create Dom Window Top Object");
249 return;
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);
260 if (!oDomWindow)
262 AfxMessageBox("Cannot create Dom Window Object");
263 return;
266 rv = oDomWindow->GetParent(getter_AddRefs(oDomWindow));
267 RvTestResult(rv, "nsIDOMWindow::GetParent()' rv test", 0);
268 if (!oDomWindow)
270 AfxMessageBox("Cannot create Dom Window Parent Object");
271 return;
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);
284 if (!oDomWindow)
286 AfxMessageBox("Cannot create Dom Window Object");
287 return;
290 rv = oDomWindow->GetScrollbars(getter_AddRefs(oDomBarProp));
291 RvTestResult(rv, "nsIDOMWindow::GetScrollbars()' rv test", 0);
292 if (!oDomBarProp)
294 AfxMessageBox("Cannot create Dom Window Scroll Bar Object");
295 return;
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);
307 if (!oDomWindow)
309 AfxMessageBox("Cannot create Dom Window Object");
310 return;
312 rv = oDomWindow->GetFrames(getter_AddRefs(oDomWindowCol));
313 RvTestResult(rv, "nsIDOMWindow::GetFrames()' rv test", 0);
314 if (!oDomWindowCol)
316 AfxMessageBox("Cannot create Dom Window Collection Object");
317 return;
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);
328 if (!oDomWindow)
330 AfxMessageBox("Cannot create Dom Window Object");
331 return;
334 rv = oDomWindow->GetDocument(getter_AddRefs(oDomDocument));
335 RvTestResult(rv, "nsIDOMWindow::GetDocument()' rv test",0);
336 if (!oDomDocument)
338 AfxMessageBox("Cannot create Dom Document Object");
339 return;
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);
351 if (!oDomWindow)
353 AfxMessageBox("Cannot create Dom Window Object");
354 return;
357 rv = oDomWindow->GetSelection(getter_AddRefs(oSelection));
358 RvTestResult(rv, "nsIDOMWindow::GetSelection()' rv test", 0);
359 if (!oSelection)
361 AfxMessageBox("Cannot get the Selection Object");
362 return;
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);
373 if (!oDomWindow)
375 AfxMessageBox("Cannot create Dom Window Object");
376 return;
378 rv = oDomWindow->GetTextZoom(&fTextZoom);
379 RvTestResult(rv, "nsIDOMWindow::GetTextZoom()' rv test", 0);
382 void CDomWindow::SetTextZoom()
384 float fTextZoom = 0.0 ;
386 fTextZoom = 12.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);
398 if (!oDomWindow)
400 AfxMessageBox("Cannot create Dom Window Object");
401 return;
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);
414 if (!oDomWindow)
416 AfxMessageBox("Cannot create Dom Window Object");
417 return;
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);
429 if (!oDomWindow)
431 AfxMessageBox("Cannot create Dom Window Object");
432 return;
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);
445 if (!oDomWindow)
447 AfxMessageBox("Cannot create Dom Window Object");
448 return;
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);
460 if (!oDomWindow)
462 AfxMessageBox("Cannot create Dom Window Object");
463 return;
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);
476 if (!oDomWindow)
478 AfxMessageBox("Cannot create Dom Window Object");
479 return;
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);
491 if (!oDomWindow)
493 AfxMessageBox("Cannot create Dom Window Object");
494 return;
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));
505 if (!oDomWindow)
506 AfxMessageBox("Cannot create Dom Window Object");
507 return oDomWindow;