001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui.menu;
043:
044: import gui.Utilities;
045:
046: import org.netbeans.performance.test.guitracker.ActionTracker;
047:
048: import javax.swing.JMenuItem;
049:
050: import org.netbeans.jellytools.TopComponentOperator;
051: import org.netbeans.jellytools.MainWindowOperator;
052:
053: import org.netbeans.jemmy.drivers.MouseDriver;
054: import org.netbeans.jemmy.operators.ComponentOperator;
055: import org.netbeans.jemmy.operators.JMenuItemOperator;
056: import org.netbeans.jemmy.operators.JMenuOperator;
057:
058: /**
059: * Performance test of application main menu.</p>
060: * <p>Each test method reads the label of tested menu and pushes it (using mouse).
061: * The menu is then close using escape key.
062: * @author Radim Kubacki, mmirilovic@netbeans.org
063: */
064: public class MainSubMenus extends
065: org.netbeans.performance.test.utilities.PerformanceTestCase {
066:
067: protected static String mainMenuPath;
068: protected static JMenuOperator testedMainMenu;
069: protected static String subMenuPath;
070:
071: private TopComponentOperator editor;
072:
073: private JMenuItemOperator mio;
074: private MouseDriver mdriver;
075:
076: private static final int repeat_original = Integer.getInteger(
077: "org.netbeans.performance.repeat", 1).intValue(); // initialize original value
078:
079: /** Creates a new instance of MainSubMenus */
080: public MainSubMenus(String testName) {
081: super (testName);
082: expectedTime = 250;
083: WAIT_AFTER_OPEN = 500;
084: track_mouse_event = ActionTracker.TRACK_MOUSE_MOVED;
085: }
086:
087: /** Creates a new instance of MainSubMenus */
088: public MainSubMenus(String testName, String performanceDataName) {
089: this (testName);
090: expectedTime = 250;
091: WAIT_AFTER_OPEN = 500;
092: track_mouse_event = ActionTracker.TRACK_MOUSE_MOVED;
093: setTestCaseName(testName, performanceDataName);
094: }
095:
096: //TODO open more than one project (nice to have open 10 projects) and close 5 projects
097: public void testFileOpenRecentProjectMenu() {
098: testSubMenu("org.netbeans.core.Bundle", "Menu/File",
099: "org.netbeans.modules.project.ui.actions.Bundle",
100: "LBL_RecentProjectsAction_Name");
101: }
102:
103: //TODO open more than one project (nice to have open 10 projects)
104: public void testFileSetMainProjectMenu() {
105: testSubMenu("org.netbeans.core.Bundle", "Menu/File",
106: "org.netbeans.modules.project.ui.actions.Bundle",
107: "LBL_SetMainProjectAction_Name");
108: }
109:
110: public void testViewDocumentationIndicesMenu() {
111: testSubMenu("org.netbeans.core.Bundle", "Menu/View",
112: "org.netbeans.modules.javadoc.search.Bundle",
113: "CTL_INDICES_MenuItem");
114: }
115:
116: public void testViewCodeFoldsMenu() {
117: editor = Utilities.openFile("PerformanceTestData",
118: "org.netbeans.test.performance", "Main20kB.java", true);
119: waitNoEvent(5000);
120: testSubMenu("org.netbeans.core.Bundle", "Menu/View",
121: "org.netbeans.modules.editor.Bundle",
122: "Menu/View/CodeFolds");
123: }
124:
125: public void testViewEditorsMenu() {
126: editor = Utilities.openFile("PerformanceTestData",
127: "org.netbeans.test.performance", "Main20kB.java", true);
128: waitNoEvent(10000);
129: testSubMenu("org.netbeans.core.Bundle", "Menu/View",
130: "org.netbeans.core.multiview.Bundle",
131: "CTL_EditorsAction");
132: }
133:
134: public void testViewToolbarsMenu() {
135: testSubMenu("org.netbeans.core.Bundle", "Menu/View",
136: "org.netbeans.core.windows.actions.Bundle",
137: "CTL_ToolbarsListAction");
138: }
139:
140: public void testRunStackMenu() {
141: testSubMenu("org.netbeans.modules.project.ui.Bundle",
142: "Menu/RunProject", "Stack"); // this can't be localized
143: }
144:
145: public void testRunRunFileMenu() {
146: testSubMenu("org.netbeans.modules.project.ui.Bundle",
147: "Menu/RunProject",
148: "org.netbeans.modules.project.ui.Bundle",
149: "Menu/RunProject/RunOther");
150: }
151:
152: public void testVersLocalHistoryMenu() {
153: testSubMenu("org.netbeans.modules.versioning.Bundle",
154: "Menu/Versioning",
155: "org.netbeans.modules.localhistory.Bundle",
156: "CTL_MainMenuItem");
157: }
158:
159: public void testVersSubversionMenu() {
160: testSubMenu("org.netbeans.modules.versioning.Bundle",
161: "Menu/Versioning",
162: "org.netbeans.modules.subversion.Bundle",
163: "CTL_Subversion_MainMenu");
164: }
165:
166: public void testToolsPaletteMenu() {
167: testSubMenu("org.netbeans.core.Bundle", "Menu/Tools",
168: "org.netbeans.modules.palette.Bundle",
169: "CTL_PaletteAction");
170: }
171:
172: public void testToolsI18nMenu() {
173: testSubMenu("org.netbeans.core.Bundle", "Menu/Tools",
174: "org.netbeans.modules.i18n.Bundle",
175: "LBL_I18nGroupActionName");
176: }
177:
178: public void testWinDebuggingMenu() {
179: testSubMenu("org.netbeans.core.Bundle", "Menu/Window",
180: "org.netbeans.modules.debugger.resources.Bundle",
181: "Menu/Window/Debug");
182: }
183:
184: public void testWinVersioningMenu() {
185: testSubMenu("org.netbeans.core.Bundle", "Menu/Window",
186: "org.netbeans.modules.versioning.Bundle",
187: "Menu/Window/Versioning");
188: }
189:
190: public void testWinProfilingMenu() {
191: testSubMenu("org.netbeans.core.Bundle", "Menu/Window",
192: "org.netbeans.modules.profiler.actions.Bundle",
193: "Menu/Window/Profile");
194: }
195:
196: public void testHelpTutorials() {
197: testSubMenu("org.netbeans.core.Bundle", "Menu/Help",
198: "org.netbeans.modules.url.Bundle",
199: "Menu/Help/Tutorials");
200: }
201:
202: public void testHelpJavadoc() {
203: testSubMenu("org.netbeans.core.Bundle", "Menu/Help",
204: "org.netbeans.modules.javadoc.search.Bundle",
205: "CTL_INDICES_MenuItem");
206: }
207:
208: private void testSubMenu(String mainMenu, String subMenu) {
209: mainMenuPath = mainMenu;
210: subMenuPath = subMenu;
211: doMeasurement();
212: }
213:
214: private void testSubMenu(String bundle, String mainMenu,
215: String subMenu) {
216: testSubMenu(getFromBundle(bundle, mainMenu), subMenu);
217: }
218:
219: private void testSubMenu(String bundle, String mainMenu,
220: String bundle_2, String subMenu) {
221: testSubMenu(getFromBundle(bundle, mainMenu), getFromBundle(
222: bundle_2, subMenu));
223: }
224:
225: private String getFromBundle(String bundle, String key) {
226: return org.netbeans.jellytools.Bundle.getStringTrimmed(bundle,
227: key);
228: }
229:
230: public void prepare() {
231: MainWindowOperator.getDefault().menuBar().pushMenu(
232: mainMenuPath, "|");
233: testedMainMenu = new JMenuOperator(MainWindowOperator
234: .getDefault());
235:
236: JMenuItem submenu = testedMainMenu.findJMenuItem(testedMainMenu
237: .getContainers()[0], subMenuPath, false, false);
238: assertNotNull("Can not find " + subMenuPath + " menu item in "
239: + mainMenuPath + " menu", submenu);
240: mio = new JMenuItemOperator(submenu);
241:
242: mdriver = org.netbeans.jemmy.drivers.DriverManager
243: .getMouseDriver(mio);
244: }
245:
246: public ComponentOperator open() {
247: mdriver.moveMouse(mio, mio.getCenterXForClick(), mio
248: .getCenterYForClick());
249: // mio.pushKey(java.awt.event.KeyEvent.VK_RIGHT);
250: return mio;
251: }
252:
253: public void close() {
254: testedComponentOperator
255: .pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
256: testedComponentOperator
257: .pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
258: }
259:
260: public void shutdown() {
261: if (editor != null) {
262: editor.close();
263: editor = null;
264: }
265: }
266:
267: public void setUp() {
268: super .setUp();
269: repeat = 1; // only first use is interesting
270: }
271:
272: public void tearDown() {
273: super .tearDown();
274: repeat = repeat_original; // initialize original value
275: }
276:
277: /** Test could be executed internaly in IDE without XTest
278: * @param args arguments from command line
279: */
280: public static void main(String[] args) {
281: junit.textui.TestRunner.run(new MainSubMenus(
282: "testRunRunFileMenu"));
283: }
284:
285: }
|