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 ***** */
41 // nsIEditSession.cpp : test implementations for nsIEditingSession interface
45 #include "testembed.h"
46 #include "nsIEditSession.h"
48 #include "BrowserFrm.h"
49 #include "BrowserImpl.h"
50 #include "BrowserView.h"
52 #include "nsIEditor.h"
57 static char THIS_FILE
[] = __FILE__
;
60 /////////////////////////////////////////////////////////////////////////////
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.");
80 return (editingSession
);
83 void CnsIEditSession::InitTest(PRInt16 displayMode
)
85 editingSession
= GetEditSessionObject();
86 domWindow
= GetTheDOMWindow(qaWebBrowser
);
88 rv
= editingSession
->Init(domWindow
);
89 RvTestResult(rv
, "Init() test", displayMode
);
91 RvTestResultDlg(rv
, "Init() test", true);
93 QAOutput("Didn't get domWindow object for InitTest() test. Test failed.", displayMode
);
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
,
106 RvTestResult(rv
, "MakeWindowEditable() test", displayMode
);
107 if (displayMode
== 1)
108 RvTestResultDlg(rv
, "MakeWindowEditable() test");
110 QAOutput("Didn't get domWindow object for MakeWindowEditable() test. Test failed.", displayMode
);
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");
126 QAOutput("Didn't get domWindow object for WindowIsEditable() test. Test failed.", displayMode
);
127 FormatAndPrintOutput("the outIsEditable boolean = ", outIsEditable
, displayMode
);
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");
145 QAOutput("Didn't get domWindow object for GetEditorForWindow() test. Test failed.", displayMode
);
148 QAOutput("Didn't get the Editor object.");
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");
164 QAOutput("Didn't get domWindow object for SetupEditorOnWindow() test. Test failed.", displayMode
);
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");
180 QAOutput("Didn't get domWindow object for TearDownEditorOnWindow() test. Test failed.", displayMode
);
183 QAOutput("Didn't get object(s) for TearEditorWinTest() test. Test failed.", 1);
186 void CnsIEditSession::OnStartTests(UINT nMenuID
)
190 case ID_INTERFACES_NSIEDITINGSESSION_RUNALLTESTS
:
193 case ID_INTERFACES_NSIEDITINGSESSION_INIT
:
196 case ID_INTERFACES_NSIEDITINGSESSION_MAKEWINDOWEDITABLE
:
197 MakeWinEditTest(PR_FALSE
, 2);
199 case ID_INTERFACES_NSIEDITINGSESSION_WINDOWISEDITABLE
:
200 WinIsEditTest(PR_TRUE
, 2);
202 case ID_INTERFACES_NSIEDITINGSESSION_GETEDITORFORWINDOW
:
205 case ID_INTERFACES_NSIEDITINGSESSION_SETUPEDITORONWINDOW
:
208 case ID_INTERFACES_NSIEDITINGSESSION_TEARDOWNEDITORONWINDOW
:
209 TearEditorWinTest(2);
214 void CnsIEditSession::RunAllTests()
217 MakeWinEditTest(PR_FALSE
, 1);
218 WinIsEditTest(PR_TRUE
, 1);
220 // SetEditorWinTest(1);
221 TearEditorWinTest(1);
224 /////////////////////////////////////////////////////////////////////////////
225 // CnsIEditSession message handlers