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 org.netbeans.jellytools.MainWindowOperator;
049: import org.netbeans.jellytools.EditorOperator;
050:
051: import org.netbeans.jemmy.operators.ComponentOperator;
052: import org.netbeans.jemmy.operators.JMenuBarOperator;
053: import org.netbeans.jemmy.operators.JMenuOperator;
054:
055: import org.netbeans.junit.NbTestSuite;
056:
057: /**
058: * Performance test of application main menu.</p>
059: * <p>Each test method reads the label of tested menu and pushes it (using mouse).
060: * The menu is then close using escape key.
061: * @author mmirilovic@netbeans.org
062: */
063: public class MainMenu extends
064: org.netbeans.performance.test.utilities.PerformanceTestCase {
065:
066: protected static String menuPath;
067:
068: private JMenuBarOperator menuBar;
069:
070: private JMenuOperator testedMenu;
071:
072: private EditorOperator editor;
073:
074: /** Creates a new instance of MainMenu */
075: public MainMenu(String testName) {
076: super (testName);
077: expectedTime = UI_RESPONSE;
078: WAIT_AFTER_OPEN = 100;
079: track_mouse_event = ActionTracker.TRACK_MOUSE_PRESS;
080: }
081:
082: /** Creates a new instance of MainMenu */
083: public MainMenu(String testName, String performanceDataName) {
084: this (testName);
085: expectedTime = UI_RESPONSE;
086: WAIT_AFTER_OPEN = 100;
087: track_mouse_event = ActionTracker.TRACK_MOUSE_PRESS;
088: setTestCaseName(testName, performanceDataName);
089: }
090:
091: public static NbTestSuite suite() {
092: NbTestSuite suite = new NbTestSuite();
093: suite.addTest(new MainMenu("testFileMenu", "File main menu"));
094: suite.addTest(new MainMenu("testEditMenu", "Edit main menu"));
095: suite.addTest(new MainMenu("testViewMenu", "View main menu"));
096: suite.addTest(new MainMenu("testNavigateMenu",
097: "Navigate main menu"));
098: suite
099: .addTest(new MainMenu("testSourceMenu",
100: "Source main menu"));
101: suite.addTest(new MainMenu("testBuildMenu", "Build main menu"));
102: suite.addTest(new MainMenu("testRunMenu", "Run main menu"));
103: suite.addTest(new MainMenu("testRefactorMenu",
104: "Refactor main menu"));
105: suite.addTest(new MainMenu("testVersioningMenu",
106: "CVS main menu"));
107: suite
108: .addTest(new MainMenu("testWindowMenu",
109: "Window main menu"));
110: suite.addTest(new MainMenu("testHelpMenu", "Help main menu"));
111: return suite;
112: }
113:
114: public void testFileMenu() {
115: WAIT_AFTER_PREPARE = 15000;
116: testMenu("org.netbeans.core.Bundle", "Menu/File");
117: }
118:
119: public void testEditMenu() {
120: testMenuWithJava("org.netbeans.core.Bundle", "Menu/Edit");
121: }
122:
123: public void testViewMenu() {
124: testMenuWithJava("org.netbeans.core.Bundle", "Menu/View");
125: }
126:
127: public void testNavigateMenu() {
128: testMenuWithJava("org.netbeans.core.Bundle", "Menu/GoTo");
129: }
130:
131: public void testSourceMenu() {
132: testMenuWithJava("org.netbeans.core.Bundle", "Menu/Source");
133: }
134:
135: public void testBuildMenu() {
136: testMenuWithJava("org.netbeans.modules.project.ui.Bundle",
137: "Menu/BuildProject");
138: }
139:
140: public void testRunMenu() {
141: testMenuWithJava("org.netbeans.modules.project.ui.Bundle",
142: "Menu/RunProject");
143: }
144:
145: public void testRefactoringMenu() {
146: testMenuWithJava(
147: "org.netbeans.modules.refactoring.spi.impl.Bundle",
148: "Menu/Refactoring");
149: }
150:
151: public void testVersioningMenu() {
152: testMenuWithJava("org.netbeans.modules.versioning.Bundle",
153: "Menu/Versioning");
154: }
155:
156: public void testProfileMenu() {
157: testMenuWithJava(
158: "org.netbeans.modules.profiler.actions.Bundle",
159: "Menu/Profile");
160: }
161:
162: public void testWindowMenu() {
163: testMenu("org.netbeans.core.Bundle", "Menu/Window");
164: }
165:
166: public void testHelpMenu() {
167: testMenu("org.netbeans.core.Bundle", "Menu/Help");
168: }
169:
170: protected void testMenu(String menu) {
171: menuPath = menu;
172: doMeasurement();
173: }
174:
175: protected void testMenuWithJava(String bundle, String menu) {
176: if (editor == null) {
177: editor = Utilities.openFile("jEdit", "bsh", "Parser.java",
178: true);
179: waitNoEvent(5000);
180: }
181: testMenu(bundle, menu);
182: }
183:
184: protected void testMenu(String bundle, String menu) {
185: menuPath = org.netbeans.jellytools.Bundle.getStringTrimmed(
186: bundle, menu);
187: doMeasurement();
188: }
189:
190: public void prepare() {
191: }
192:
193: public ComponentOperator open() {
194: menuBar.pushMenu(menuPath, "|");
195: return testedMenu;
196: }
197:
198: public void close() {
199: super .close();
200:
201: if (editor != null)
202: editor.close();
203: }
204:
205: /**
206: * Prepare method have to contain everything that needs to be done prior to
207: * repeated invocation of test.
208: * Default implementation is empty.
209: */
210: protected void initialize() {
211: menuBar = MainWindowOperator.getDefault().menuBar();
212: testedMenu = new JMenuOperator(MainWindowOperator.getDefault());
213: }
214:
215: /** Test could be executed internaly in IDE without XTest
216: * @param args arguments from command line
217: */
218: public static void main(String[] args) {
219: junit.textui.TestRunner.run(new MainMenu("testGoToMenu"));
220: junit.textui.TestRunner.run(new MainMenu("testSourceMenu"));
221: }
222:
223: }
|