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.action;
043:
044: import org.netbeans.modules.editor.options.BaseOptions;
045:
046: import org.netbeans.jellytools.EditorOperator;
047: import org.netbeans.jellytools.EditorWindowOperator;
048: import org.netbeans.jellytools.actions.OpenAction;
049: import org.netbeans.jellytools.nodes.Node;
050: import org.netbeans.jellytools.nodes.SourcePackagesNode;
051: import org.netbeans.jellytools.modules.web.nodes.WebPagesNode;
052:
053: import org.netbeans.jemmy.operators.ComponentOperator;
054:
055: import org.netbeans.junit.NbTestSuite;
056:
057: /**
058: * Test of typing in opened source editor.
059: *
060: * @author anebuzelsky@netbeans.org, mmirilovic@netbeans.org
061: */
062: public class TypingInEditor extends
063: org.netbeans.performance.test.utilities.PerformanceTestCase {
064:
065: private EditorOperator editorOperator;
066:
067: private int fontSize, caretBlinkRate;
068: protected String fileName;
069: protected int caretPositionX, caretPositionY;
070:
071: protected Class kitClass, optionsClass;
072:
073: Node fileToBeOpened;
074:
075: /** Creates a new instance of TypingInEditor */
076: public TypingInEditor(String testName) {
077: super (testName);
078: HEURISTIC_FACTOR = -1; // use default WaitAfterOpen for all iterations
079: }
080:
081: /** Creates a new instance of TypingInEditor */
082: public TypingInEditor(String testName, String performanceDataName) {
083: super (testName, performanceDataName);
084: HEURISTIC_FACTOR = -1; // use default WaitAfterOpen for all iterations
085: }
086:
087: public static NbTestSuite suite() {
088: NbTestSuite suite = new NbTestSuite();
089: suite.addTest(new TypingInEditor("testJavaEditor",
090: "Type a character in Java Editor"));
091: suite.addTest(new TypingInEditor("testTxtEditor",
092: "Type a character in Txt Editor"));
093: // suite.addTest(new TypingInEditor("testJspEditor", "Type a character in Jsp Editor"));
094: return suite;
095: }
096:
097: public void testTxtEditor() {
098: fileName = "textfile.txt";
099: caretPositionX = 2;
100: caretPositionY = 1;
101: kitClass = org.netbeans.modules.editor.plain.PlainKit.class;
102: optionsClass = org.netbeans.modules.editor.plain.options.PlainOptions.class;
103: fileToBeOpened = new Node(new SourcePackagesNode(
104: "PerformanceTestData"),
105: "org.netbeans.test.performance|" + fileName);
106: doMeasurement();
107: }
108:
109: public void testJavaEditor() {
110: fileName = "Main.java";
111: caretPositionX = 38;
112: caretPositionY = 19;
113: kitClass = org.netbeans.modules.editor.java.JavaKit.class;
114: optionsClass = org.netbeans.modules.java.editor.options.JavaOptions.class;
115: fileToBeOpened = new Node(new SourcePackagesNode(
116: "PerformanceTestData"),
117: "org.netbeans.test.performance|" + fileName);
118: doMeasurement();
119: }
120:
121: /*
122: public void testJspEditor() {
123: fileName = "Test.jsp";
124: caretPositionX = 6;
125: caretPositionY = 9;
126: kitClass = org.netbeans.modules.web.core.syntax.JSPKit.class;
127: optionsClass = org.netbeans.modules.web.core.syntax.settings.JSPOptions.class;
128: fileToBeOpened = new Node(new WebPagesNode("PerformanceTestWebApplication"), fileName);
129: doMeasurement();
130: }
131: */
132: public void initialize() {
133: // open a java file in the editor
134: new OpenAction().performAPI(fileToBeOpened);
135: editorOperator = EditorWindowOperator.getEditor(fileName);
136:
137: //wait painting pf folds in the editor
138: waitNoEvent(2000);
139:
140: // go to the right place
141: editorOperator.setCaretPosition(caretPositionX, caretPositionY);
142:
143: setEditorForMeasuringOn();
144: }
145:
146: public void prepare() {
147: }
148:
149: public ComponentOperator open() {
150: //new Action(null, null, new Shortcut(KeyEvent.VK_A)).perform(editorOperator);
151: editorOperator.typeKey('a');
152: return null;
153: }
154:
155: public void close() {
156: // do nothing
157: }
158:
159: public void shutdown() {
160: setEditorForMeasuringOff();
161: editorOperator.closeDiscard();
162: super .shutdown();
163: }
164:
165: private void setEditorForMeasuringOn() {
166: // measure only paint events from QuietEditorPane
167: repaintManager()
168: .addRegionFilter(repaintManager().EDITOR_FILTER);
169:
170: // set large font size for Editor
171: /* BaseOptions options = BaseOptions.getOptions(kitClass);
172: if (options.getClass().isInstance(optionsClass)) {
173: fontSize = options.getFontSize();
174: options.setFontSize(20);
175: }
176:
177: caretBlinkRate = options.getCaretBlinkRate();
178: //disable caret blinkering
179: options.setCaretBlinkRate(0);
180: */}
181:
182: private void setEditorForMeasuringOff() {
183: // measure only paint events from QuietEditorPane
184: repaintManager().resetRegionFilters();
185:
186: // set back the original font size for Editor
187: /* BaseOptions options = BaseOptions.getOptions(kitClass);
188: if (options.getClass().isInstance(optionsClass)) {
189: options.setFontSize(fontSize);
190: }
191:
192: // set back the original blink rate
193: options.setCaretBlinkRate(caretBlinkRate);
194: */}
195:
196: public static void main(java.lang.String[] args) {
197: repeat = 3;
198: junit.textui.TestRunner.run(new TypingInEditor("testJspEditor",
199: "Type a character in Jsp Editor"));
200: }
201: }
|