Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / nsIEditSession.cpp
bloba674544958581a43dbb61a314a716de3869039fc
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 ***** */
39 // File Overview....
41 // nsIEditSession.cpp : test implementations for nsIEditingSession interface
44 #include "stdafx.h"
45 #include "testembed.h"
46 #include "nsIEditSession.h"
47 #include "QaUtils.h"
48 #include "BrowserFrm.h"
49 #include "BrowserImpl.h"
50 #include "BrowserView.h"
51 #include "Tests.h"
52 #include "nsIEditor.h"
54 #ifdef _DEBUG
55 #define new DEBUG_NEW
56 #undef THIS_FILE
57 static char THIS_FILE[] = __FILE__;
58 #endif
60 /////////////////////////////////////////////////////////////////////////////
61 // nsIEditSession
63 CnsIEditSession::CnsIEditSession(nsIWebBrowser *mWebBrowser)
65 qaWebBrowser = mWebBrowser;
68 CnsIEditSession::~CnsIEditSession()
72 nsIEditingSession * CnsIEditSession::GetEditSessionObject()
74 editingSession = do_GetInterface(qaWebBrowser);
75 if (!editingSession) {
76 QAOutput("Didn't get nsIEditingSession object.");
77 return nsnull;
80 return (editingSession);
83 void CnsIEditSession::InitTest(PRInt16 displayMode)
85 editingSession = GetEditSessionObject();
86 domWindow = GetTheDOMWindow(qaWebBrowser);
87 if (editingSession) {
88 rv = editingSession->Init(domWindow);
89 RvTestResult(rv, "Init() test", displayMode);
90 if (displayMode == 1)
91 RvTestResultDlg(rv, "Init() test", true);
92 if (!domWindow)
93 QAOutput("Didn't get domWindow object for InitTest() test. Test failed.", displayMode);
95 else
96 QAOutput("Didn't get editingSession object for InitTest() test. Test failed.", displayMode);
99 void CnsIEditSession::MakeWinEditTest(PRBool afterUriLoad, PRInt16 displayMode)
101 editingSession = GetEditSessionObject();
102 domWindow = GetTheDOMWindow(qaWebBrowser);
103 if (editingSession) {
104 rv= editingSession->MakeWindowEditable(domWindow, "text", afterUriLoad,
105 PR_TRUE, PR_FALSE);
106 RvTestResult(rv, "MakeWindowEditable() test", displayMode);
107 if (displayMode == 1)
108 RvTestResultDlg(rv, "MakeWindowEditable() test");
109 if (!domWindow)
110 QAOutput("Didn't get domWindow object for MakeWindowEditable() test. Test failed.", displayMode);
112 else
113 QAOutput("Didn't get editingSession object for MakeWindowEditable() test. Test failed.", 1);
116 void CnsIEditSession::WinIsEditTest(PRBool outIsEditable, PRInt16 displayMode)
118 editingSession = GetEditSessionObject();
119 domWindow = GetTheDOMWindow(qaWebBrowser);
120 if (editingSession) {
121 rv = editingSession->WindowIsEditable(domWindow, &outIsEditable);
122 RvTestResult(rv, "WindowIsEditable() test", displayMode);
123 if (displayMode == 1)
124 RvTestResultDlg(rv, "WindowIsEditable() test");
125 if (!domWindow)
126 QAOutput("Didn't get domWindow object for WindowIsEditable() test. Test failed.", displayMode);
127 FormatAndPrintOutput("the outIsEditable boolean = ", outIsEditable, displayMode);
129 else
130 QAOutput("Didn't get object(s) for WinIsEditTest() test. Test failed.", 1);
133 void CnsIEditSession::GetEditorWinTest(PRInt16 displayMode)
135 nsCOMPtr<nsIEditor> theEditor;
136 // nsIEditor *theEditor = nsnull;
137 editingSession = GetEditSessionObject();
138 domWindow = GetTheDOMWindow(qaWebBrowser);
139 if (editingSession) {
140 rv = editingSession->GetEditorForWindow(domWindow, getter_AddRefs(theEditor));
141 RvTestResult(rv, "GetEditorForWindow() test", displayMode);
142 if (displayMode == 1)
143 RvTestResultDlg(rv, "GetEditorForWindow() test");
144 if (!domWindow)
145 QAOutput("Didn't get domWindow object for GetEditorForWindow() test. Test failed.", displayMode);
147 if (!theEditor)
148 QAOutput("Didn't get the Editor object.");
150 else
151 QAOutput("Didn't get object(s) for WinIsEditTest() test. Test failed.", 1);
154 void CnsIEditSession::SetEditorWinTest(PRInt16 displayMode)
156 editingSession = GetEditSessionObject();
157 domWindow = GetTheDOMWindow(qaWebBrowser);
158 if (editingSession) {
159 rv = editingSession->SetupEditorOnWindow(domWindow);
160 RvTestResult(rv, "SetupEditorOnWindow() test", displayMode);
161 if (displayMode == 1)
162 RvTestResultDlg(rv, "SetupEditorOnWindow() test");
163 if (!domWindow)
164 QAOutput("Didn't get domWindow object for SetupEditorOnWindow() test. Test failed.", displayMode);
166 else
167 QAOutput("Didn't get object(s) for SetEditorWinTest() test. Test failed.", 1);
170 void CnsIEditSession::TearEditorWinTest(PRInt16 displayMode)
172 editingSession = GetEditSessionObject();
173 domWindow = GetTheDOMWindow(qaWebBrowser);
174 if (editingSession) {
175 rv = editingSession->TearDownEditorOnWindow(domWindow);
176 RvTestResult(rv, "TearDownEditorOnWindow() test", displayMode);
177 if (displayMode == 1)
178 RvTestResultDlg(rv, "TearDownEditorOnWindow() test");
179 if (!domWindow)
180 QAOutput("Didn't get domWindow object for TearDownEditorOnWindow() test. Test failed.", displayMode);
182 else
183 QAOutput("Didn't get object(s) for TearEditorWinTest() test. Test failed.", 1);
186 void CnsIEditSession::OnStartTests(UINT nMenuID)
188 switch(nMenuID)
190 case ID_INTERFACES_NSIEDITINGSESSION_RUNALLTESTS :
191 RunAllTests();
192 break;
193 case ID_INTERFACES_NSIEDITINGSESSION_INIT :
194 InitTest(2);
195 break;
196 case ID_INTERFACES_NSIEDITINGSESSION_MAKEWINDOWEDITABLE :
197 MakeWinEditTest(PR_FALSE, 2);
198 break;
199 case ID_INTERFACES_NSIEDITINGSESSION_WINDOWISEDITABLE :
200 WinIsEditTest(PR_TRUE, 2);
201 break;
202 case ID_INTERFACES_NSIEDITINGSESSION_GETEDITORFORWINDOW :
203 GetEditorWinTest(2);
204 break;
205 case ID_INTERFACES_NSIEDITINGSESSION_SETUPEDITORONWINDOW :
206 SetEditorWinTest(2);
207 break;
208 case ID_INTERFACES_NSIEDITINGSESSION_TEARDOWNEDITORONWINDOW :
209 TearEditorWinTest(2);
210 break;
214 void CnsIEditSession::RunAllTests()
216 InitTest(1);
217 MakeWinEditTest(PR_FALSE, 1);
218 WinIsEditTest(PR_TRUE, 1);
219 GetEditorWinTest(1);
220 // SetEditorWinTest(1);
221 TearEditorWinTest(1);
224 /////////////////////////////////////////////////////////////////////////////
225 // CnsIEditSession message handlers