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-2006Sun
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 java.awt.event.KeyEvent;
045: import javax.swing.JComponent;
046: import javax.swing.KeyStroke;
047: import org.netbeans.jellytools.EditorOperator;
048: import org.netbeans.jellytools.EditorWindowOperator;
049: import org.netbeans.jellytools.ProjectsTabOperator;
050: import org.netbeans.jellytools.nodes.Node;
051: import org.netbeans.jellytools.actions.ActionNoBlock;
052: import org.netbeans.jellytools.actions.OpenAction;
053: import org.netbeans.jemmy.operators.ComponentOperator;
054: import org.netbeans.performance.test.guitracker.LoggingRepaintManager;
055: import org.netbeans.test.web.performance.WebPerformanceTestCase;
056:
057: /**
058: * Test of java completion in opened source editor.
059: *
060: * @author anebuzelsky@netbeans.org, mmirilovic@netbeans.org
061: */
062: public class JavaCompletionInJspEditor extends WebPerformanceTestCase {
063: private String text;
064: private EditorOperator editorOperator;
065: protected LoggingRepaintManager.RegionFilter COMPLETION_DIALOG_FILTER = new LoggingRepaintManager.RegionFilter() {
066: public boolean accept(JComponent comp) {
067: return comp.getClass().getName().startsWith(
068: "org.netbeans.editor.ext.");
069: }
070:
071: public String getFilterName() {
072: return "Completion Dialog Filter (accepts only componenets from"
073: + "'org.netbeans.editor.ext.**' packages";
074: }
075: };
076:
077: /** Creates a new instance of JavaCompletionInEditor */
078: public JavaCompletionInJspEditor(String testName) {
079: super (testName);
080: expectedTime = WINDOW_OPEN;
081: init();
082: }
083:
084: /** Creates a new instance of JavaCompletionInEditor */
085: public JavaCompletionInJspEditor(String testName,
086: String performanceDataName) {
087: super (testName, performanceDataName);
088: expectedTime = WINDOW_OPEN;
089: init();
090: }
091:
092: protected void init() {
093: super .init();
094: WAIT_AFTER_OPEN = 6000;
095: }
096:
097: public void testScriptletCC() {
098: text = "<% ";
099: measureTime();
100: }
101:
102: public void testExpressionCC() {
103: text = "<%= request.";
104: measureTime();
105: }
106:
107: public void testDeclarationCC() {
108: text = "<%! java.";
109: measureTime();
110: }
111:
112: public void testAllTags() {
113: text = "<";
114: measureTime();
115: }
116:
117: public void testTagAttribute1() {
118: text = "<%@page ";
119: measureTime();
120: }
121:
122: public void testTagAttribute2() {
123: text = "<jsp:useBean ";
124: measureTime();
125: }
126:
127: public void testAttributeValue1() {
128: text = "<%@page import=\"";
129: measureTime();
130: }
131:
132: public void testAttributeValue2() {
133: text = "<%@include file=\"";
134: measureTime();
135: }
136:
137: public void testAttributeValue3() {
138: text = "<jsp:useBean id=\"bean\" scope=\"";
139: measureTime();
140: }
141:
142: public void testAttributeValue4() {
143: text = "<jsp:useBean id=\"beanInstanceName\" scope=\"session\" class=\"";
144: measureTime();
145: }
146:
147: public void testAttributeValue5() {
148: text = "<jsp:getProperty name=\"bean\" property=\"";
149: measureTime();
150: }
151:
152: public void testAttributeValue6() {
153: text = "<%@taglib prefix=\"d\" tagdir=\"";
154: measureTime();
155: }
156:
157: protected void initialize() {
158: jspOptions().setCaretBlinkRate(0);
159: // delay between the caret stops and the update of his position in status bar
160: jspOptions().setStatusBarCaretDelay(0);
161: // jspOptions().setCodeFoldingEnable(false);
162: jspOptions().setCompletionAutoPopupDelay(0);
163: jspOptions().setJavaDocAutoPopup(false);
164: javaOptions().setCompletionAutoPopupDelay(0);
165: javaOptions().setJavaDocAutoPopup(false);
166: // turn off the error hightlighting feature
167: /* TODO doesn't work after retouche integration
168: javaSettings().setParsingErrors(0);
169: */
170:
171: new OpenAction().performAPI(new Node(new ProjectsTabOperator()
172: .getProjectRootNode("TestWebProject"),
173: "Web Pages|index.jsp"));
174: editorOperator = EditorWindowOperator.getEditor("index.jsp");
175: eventTool().waitNoEvent(1000);
176: waitNoEvent(2000);
177: }
178:
179: public void prepare() {
180: // scroll to the place where we start
181: editorOperator.makeComponentVisible();
182: clearTestLine();
183: editorOperator.setCaretPositionToLine(8);
184: // insert the initial text
185: editorOperator.insert(text);
186: // wait
187: eventTool().waitNoEvent(500);
188: }
189:
190: public ComponentOperator open() {
191: KeyStroke ctrlSpace = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
192: KeyEvent.CTRL_MASK);
193: repaintManager().addRegionFilter(COMPLETION_DIALOG_FILTER);
194: // invoke the completion dialog
195: new ActionNoBlock(null, null, ctrlSpace)
196: .perform(editorOperator);
197: return null;
198: }
199:
200: public void close() {
201: //repaintManager().setRegionFilter(null);
202: repaintManager().resetRegionFilters();
203:
204: new ActionNoBlock(null, null, KeyStroke.getKeyStroke(
205: KeyEvent.VK_ESCAPE, 0)).perform(editorOperator);
206: clearTestLine();
207: }
208:
209: protected void shutdown() {
210: super .shutdown();
211: editorOperator.closeDiscard();
212: }
213:
214: private void clearTestLine() {
215: int linelength = editorOperator.getText(8).length();
216: if (linelength > 1)
217: editorOperator.delete(8, 1, linelength - 1);
218: }
219: }
|