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-2006 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.jellytools.EditorOperator;
045: import org.netbeans.jellytools.EditorWindowOperator;
046: import org.netbeans.jellytools.ProjectsTabOperator;
047: import org.netbeans.jellytools.actions.OpenAction;
048: import org.netbeans.jemmy.operators.ComponentOperator;
049: import org.netbeans.performance.test.guitracker.LoggingRepaintManager.RegionFilter;
050:
051: import org.netbeans.jellytools.modules.editor.CompletionJListOperator;
052: import org.netbeans.jellytools.nodes.Node;
053:
054: /**
055: *
056: * @author mkhramov@netbeans.org
057: */
058: public class ScriptingCodeCompletionInEditor extends
059: org.netbeans.performance.test.utilities.PerformanceTestCase {
060:
061: private int lineNumber = 39;
062: private String ccText = "";
063: private EditorOperator editorOperator;
064: private char completionChar;
065:
066: protected Node fileToBeOpened;
067: protected String testProject;
068: protected String fileName;
069: protected String nodePath;
070:
071: protected static ProjectsTabOperator projectsTab = null;
072:
073: public ScriptingCodeCompletionInEditor(String testName) {
074: super (testName);
075: expectedTime = WINDOW_OPEN;
076: }
077:
078: public ScriptingCodeCompletionInEditor(String testName,
079: String performanceDataName) {
080: super (testName, performanceDataName);
081: expectedTime = WINDOW_OPEN;
082: completionChar = '.';
083: }
084:
085: @Override
086: public void initialize() {
087: String path = nodePath + "|" + fileName;
088: log("attempting to open: " + path);
089:
090: fileToBeOpened = new Node(getProjectNode(testProject), path);
091: new OpenAction().performAPI(fileToBeOpened);
092:
093: editorOperator = EditorWindowOperator.getEditor(fileName);
094:
095: }
096:
097: protected Node getProjectNode(String projectName) {
098: if (projectsTab == null)
099: projectsTab = new ProjectsTabOperator();
100:
101: return projectsTab.getProjectRootNode(projectName);
102: }
103:
104: private void setCompletionForMeasureOn() {
105: repaintManager().addRegionFilter(COMPLETION_FILTER);
106: }
107:
108: private void setCompletionForMeasuringOff() {
109: repaintManager().resetRegionFilters();
110: }
111:
112: @Override
113: public void prepare() {
114: // measure only paint events from QuietEditorPane
115: repaintManager().addRegionFilter(COMPLETION_FILTER);
116: setCompletionForMeasureOn();
117: editorOperator.setCaretPositionToEndOfLine(lineNumber);
118: }
119:
120: @Override
121: public ComponentOperator open() {
122: editorOperator.txtEditorPane().typeKey(completionChar);
123: return new CompletionJListOperator();
124: }
125:
126: @Override
127: public void close() {
128: log("close");
129: super .close();
130: setCompletionForMeasuringOff();
131: editorOperator.setCaretPositionRelative(-1);
132: editorOperator.delete(1);
133: }
134:
135: @Override
136: public void shutdown() {
137: // set default values after measuring
138: setCompletionForMeasuringOff();
139:
140: editorOperator.closeDiscard();
141: super .shutdown();
142: }
143:
144: public void testCC_InRubyEditor() {
145: lineNumber = 5;
146: ccText = "";
147: completionChar = '.'; // Set point character after "Hello world" string. Expected code completion list appears
148:
149: /*
150: * org-netbeans-modules-ruby.jar
151: * kitClass = org.netbeans.modules.css.editor.CssEditorKit.class;
152: * optionsClass = org.netbeans.modules.ruby.options.RubyOptions.class;
153: */
154: doMeasurement();
155: }
156:
157: public void testCC_InRHTMLEditor() {
158: lineNumber = 39;
159: ccText = "";
160: completionChar = '.';
161: // optionsClass = org.netbeans.modules.rhtml.editor.RhtmlOptions.class;
162: doMeasurement();
163: }
164:
165: public void testCC_InJavaScriptEditor() {
166: lineNumber = 39;
167: ccText = "";
168: completionChar = '.';
169:
170: doMeasurement();
171: }
172:
173: public void testCC_InCSSEditor() {
174: lineNumber = 39;
175: ccText = "";
176: completionChar = '.';
177: /*
178: * org-netbeans-modules-css-visual.jar
179: * kitClass = org.netbeans.modules.css.editor.CssEditorKit.class;
180: * optionsClass = org.netbeans.modules.css.options.CssOptions.class;
181: */
182: doMeasurement();
183: }
184:
185: private static final RegionFilter COMPLETION_FILTER = new RegionFilter() {
186:
187: public boolean accept(javax.swing.JComponent c) {
188: return c
189: .getClass()
190: .getName()
191: .equals(
192: "org.netbeans.modules.editor.completion.CompletionScrollPane")
193: || c.getClass().getName().equals(
194: "org.openide.text.QuietEditorPane");
195: }
196:
197: public String getFilterName() {
198: return "Accept paints from org.netbeans.modules.editor.completion.CompletionScrollPane || org.openide.text.QuietEditorPane";
199: }
200: };
201:
202: }
|