1 // nsICommandMgr.cpp : implementation file
3 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
25 * David Epstein <depstein@netscape.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
43 // nsICommandMgr.cpp : test implementations for nsICommandManager interface
46 #include "testembed.h"
47 #include "nsICommandMgr.h"
48 #include "nsICmdParams.h"
50 #include "BrowserFrm.h"
51 #include "BrowserImpl.h"
52 #include "BrowserView.h"
58 static char THIS_FILE
[] = __FILE__
;
61 /////////////////////////////////////////////////////////////////////////////
64 CnsICommandMgr::CnsICommandMgr(nsIWebBrowser
*mWebBrowser
)
66 qaWebBrowser
= mWebBrowser
;
69 CnsICommandMgr::~CnsICommandMgr()
73 // 1st column: command; 2nd column: DoCommand state, 3rd column: CmdParam state;
74 CommandTest CommandTable
[] = {
75 {"cmd_bold", "", "state_all", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
76 {"cmd_italic", "", "state_all", PR_TRUE
, 10000000, 2.27, "This is a complete sentence", "This isn't!"},
77 {"cmd_underline", "", "state_all", PR_TRUE
, 17, 7839.3480, "A longer string than the previous one.", "Shorter string, but still pretty long."},
78 {"cmd_indent", "", "state_enabled", PR_TRUE
, 7480, -1.487, "Another string input for testing ...", "How about them Giants?!"},
79 {"cmd_outdent", "", "state_enabled", PR_FALSE
, 0, 24987.2465, "A few numbers: 1 2 3, A few letters: C A B, A few characters: Mickey Goofy $%*&@", "nothing here"},
80 {"cmd_increaseFont", "", "state_enabled", PR_TRUE
, 500000000, 16, "hi", "HI"},
81 {"cmd_undo", "", "state_enabled", PR_TRUE
, 987352487, 36.489, "x ", "x"},
82 {"cmd_redo", "", "state_enabled", PR_FALSE
, 90, -24, "", " "},
83 {"cmd_decreaseFont", "", "", PR_TRUE
, 0.0, 0.0, "hello", "HELLO"},
84 {"cmd_fontColor", "state_attribute", "state_attribute", PR_TRUE
, 25, 100, "#FF0000", "#000000"},
85 {"cmd_backgroundColor", "state_attribute", "state_attribute", PR_TRUE
, -35871678, 15.345363645, "#FF1234", "#001234"},
86 {"cmd_fontFace", "state_attribute", "state_attribute", PR_TRUE
, 50000, 5.798, "Times New Roman, Times, serif", "Courier New, Courier, monospace"},
87 {"cmd_align", "state_attribute", "state_attribute", PR_TRUE
, 10000, 5.798, "right", "center"},
88 {"cmd_charSet", "state_attribute", "state_attribute", PR_TRUE
, 20000, 5.798, "hello", "HELLO"},
89 {"cmd_copy", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
90 {"cmd_delete", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
91 {"cmd_deleteCharBackward", "", "state_enabled", PR_TRUE
, 30000, 245.2323, "hello", "HELLO"},
92 {"cmd_deleteCharForward", "", "state_enabled", PR_TRUE
, 50000, -24235.2346, "a very very very very very very very very looooooooooooooooooooong stringgggggggggggggggggggggggggggggggggggggggggggg!!!", "HELLO"},
93 {"cmd_deleteWordForward", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
94 {"cmd_deleteWordBackward", "", "state_enabled", PR_TRUE
, 6034600, 5.798, "hello", "HELLO"},
95 {"cmd_deleteToBeginningOfLine", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
96 {"cmd_deleteToEndOfLine", "", "state_enabled", PR_TRUE
, -5434, 5.798, "hello", "HELLO"},
97 {"cmd_scrollTop", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
98 {"cmd_scrollBottom", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
99 {"cmd_scrollPageUp", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
100 {"cmd_scrollPageDown", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
101 {"cmd_movePageUp", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
102 {"cmd_movePageDown", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
103 {"cmd_moveTop", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
104 {"cmd_moveBottom", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
105 {"cmd_selectTop", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
106 {"cmd_selectBottom", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
107 {"cmd_lineNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
108 {"cmd_linePrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
109 {"cmd_selectLineNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
110 {"cmd_selectLinePrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
111 {"cmd_charPrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
112 {"cmd_charNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
113 {"cmd_selectCharPrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
114 {"cmd_selectCharNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
115 {"cmd_beginLine", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
116 {"cmd_endLine", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
117 {"cmd_selectBeginLine", "", "state_enabled", PR_FALSE
, 50000, 5.798, "hello", "HELLO"},
118 {"cmd_selectEndLine", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
119 {"cmd_wordPrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
120 {"cmd_wordNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
121 {"cmd_selectWordPrevious", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
122 {"cmd_selectWordNext", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
123 {"cmd_cut", "", "state_enabled", PR_TRUE
, 50000, 5.798, "hello", "HELLO"},
124 {"cmd_cutOrDelete", "", "state_enabled", PR_FALSE
, 50000, 5.798, "hello", "HELLO"},
127 nsICommandManager
* CnsICommandMgr::GetCommandMgrObject(nsIWebBrowser
*aWebBrowser
, PRInt16 displayMethod
)
129 nsCOMPtr
<nsIWebBrowser
> wb(aWebBrowser
);
130 nsCOMPtr
<nsICommandManager
> cmdMgrObj
= do_GetInterface(wb
, &rv
);
131 RvTestResult(rv
, "GetCommandMgrObject() test", displayMethod
);
133 QAOutput("Didn't get nsICommandManager object.");
139 nsICommandManager
* CnsICommandMgr::GetCommandMgrWithContractIDObject(PRInt16 displayMethod
)
141 nsCOMPtr
<nsICommandManager
> cmdMgrObj
= do_CreateInstance(NS_COMMAND_MANAGER_CONTRACTID
, &rv
);
142 RvTestResult(rv
, "GetCommandMgrWithContractIDObject() test", 1);
144 QAOutput("Didn't get nsICommandManager object.");
150 void CnsICommandMgr::IsCommandSupportedTest(const char *aCommandName
, PRInt16 displayMethod
)
154 FormatAndPrintOutput("the Command input = ", aCommandName
, displayMethod
);
155 cmdMgrObj
= GetCommandMgrObject(qaWebBrowser
, displayMethod
);
157 QAOutput("Didn't get nsICommandManager object. Test failed.");
160 rv
= cmdMgrObj
->IsCommandSupported(aCommandName
, nsnull
, &isSupported
);
161 RvTestResult(rv
, "IsCommandSupported() test", displayMethod
);
162 if (displayMethod
== 1)
163 RvTestResultDlg(rv
, "IsCommandSupported() test", true);
164 FormatAndPrintOutput("isSupported boolean = ", isSupported
, displayMethod
);
167 void CnsICommandMgr::IsCommandEnabledTest(const char *aCommandName
, PRInt16 displayMethod
)
171 FormatAndPrintOutput("the Command input = ", aCommandName
, displayMethod
);
172 cmdMgrObj
= GetCommandMgrObject(qaWebBrowser
, displayMethod
);
174 QAOutput("Didn't get nsICommandManager object.");
177 rv
= cmdMgrObj
->IsCommandEnabled(aCommandName
, nsnull
, &isEnabled
);
178 RvTestResult(rv
, "IsCommandEnabled() test", displayMethod
);
179 if (displayMethod
== 1)
180 RvTestResultDlg(rv
, "IsCommandEnabled() test");
181 FormatAndPrintOutput("isEnabled boolean = ", isEnabled
, displayMethod
);
184 void CnsICommandMgr::GetCommandStateTest(const char *aCommandName
, PRInt16 displayMethod
)
186 PRBool enabled
= PR_FALSE
;
188 FormatAndPrintOutput("the Command input = ", aCommandName
, displayMethod
);
189 cmdMgrObj
= GetCommandMgrObject(qaWebBrowser
, displayMethod
);
190 cmdParamObj
= CnsICmdParams::GetCommandParamObject();
192 QAOutput("Didn't get nsICommandManager object.");
195 rv
= cmdMgrObj
->GetCommandState(aCommandName
, nsnull
, cmdParamObj
);
196 RvTestResult(rv
, "GetCommandState() test", displayMethod
);
197 if (displayMethod
== 1)
198 RvTestResultDlg(rv
, "GetCommandState() test");
200 QAOutput("Didn't get nsICommandParams object for GetCommandStateTest.");
203 void CnsICommandMgr::DoCommandTest(const char *aCommandName
,
204 const char *doCommandState
,
205 PRInt16 displayMethod
)
209 FormatAndPrintOutput("the Command input = ", aCommandName
, displayMethod
);
210 cmdMgrObj
= GetCommandMgrObject(qaWebBrowser
, displayMethod
);
211 cmdParamObj
= CnsICmdParams::GetCommandParamObject();
213 QAOutput("Didn't get nsICommandManager object. Tests fail");
217 if (strcmp(doCommandState
, "state_attribute") == 0)
219 if (strcmp(aCommandName
,"cmd_fontColor") == 0 ||
220 strcmp(aCommandName
,"cmd_backgroundColor") == 0)
222 else if (strcmp(aCommandName
,"cmd_fontFace") == 0)
223 value
= "Helvetica, Ariel, san-serif";
228 cmdParamObj
->SetCStringValue("state_attribute", value
.get());
230 QAOutput("Didn't get nsICommandParam object for nsICommandMgr test.");
232 rv
= cmdMgrObj
->DoCommand(aCommandName
, cmdParamObj
, nsnull
);
233 RvTestResult(rv
, "DoCommand() test", displayMethod
);
234 if (displayMethod
== 1)
235 RvTestResultDlg(rv
, "DoCommand() test");
239 void CnsICommandMgr::OnStartTests(UINT nMenuID
)
243 case ID_INTERFACES_NSICOMMANDMANAGER_RUNALLTESTS
:
246 case ID_INTERFACES_NSICOMMANDMANAGER_ADDCOMMANDOBSERVER
:
247 QAOutput("Not implemented yet.", 2);
249 case ID_INTERFACES_NSICOMMANDMANAGER_REMOVECOMMANDOBSERVER
:
250 QAOutput("Not implemented yet.", 2);
252 case ID_INTERFACES_NSICOMMANDMANAGER_ISCOMMANDESUPPORTED
:
253 IsCommandSupportedTest("cmd_bold", 2);
255 case ID_INTERFACES_NSICOMMANDMANAGER_ISCOMMANDENABLED
:
256 IsCommandEnabledTest("cmd_bold", 2);
258 case ID_INTERFACES_NSICOMMANDMANAGER_GETCOMMANDSTATE
:
259 GetCommandStateTest("cmd_charSet", 2);
261 case ID_INTERFACES_NSICOMMANDMANAGER_DOCOMMAND
:
262 DoCommandTest("cmd_fontColor", "state_attribute", 2);
267 void CnsICommandMgr::RunAllTests()
271 QAOutput("Run All nsICommandManager tests. Check C:/Temp/TestOutput.txt for test results.", 2);
272 for (i
=0; i
< 50; i
++)
274 FormatAndPrintOutput("loop cnt = ", i
, 1);
275 IsCommandSupportedTest(CommandTable
[i
].mCmdName
, 1);
276 IsCommandEnabledTest(CommandTable
[i
].mCmdName
, 1);
277 GetCommandStateTest(CommandTable
[i
].mCmdName
, 1);
278 DoCommandTest(CommandTable
[i
].mCmdName
,
279 CommandTable
[i
].mDoCmdState
, 1);
284 /////////////////////////////////////////////////////////////////////////////
285 // CnsICommandMgr message handlers