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 java.awt.Component;
045: import java.awt.Container;
046: import javax.swing.JEditorPane;
047: import javax.swing.text.Document;
048: import org.netbeans.jellytools.EditorOperator;
049: import org.netbeans.jellytools.nodes.Node;
050: import org.netbeans.jellytools.nodes.SourcePackagesNode;
051:
052: import org.netbeans.jemmy.operators.ComponentOperator;
053: import org.netbeans.jemmy.operators.JPopupMenuOperator;
054:
055: /**
056: * Test of opening files.
057: *
058: * @author mmirilovic@netbeans.org
059: */
060: public class OpenFiles extends
061: org.netbeans.performance.test.utilities.PerformanceTestCase {
062:
063: private static final Object EDITOR_REFS = new Object();
064:
065: /** Node to be opened/edited */
066: public static Node openNode;
067:
068: /** Folder with data */
069: public static String fileProject;
070:
071: /** Folder with data */
072: public static String filePackage;
073:
074: /** Name of file to open */
075: public static String fileName;
076:
077: /** Menu item name that opens the editor */
078: public static String menuItem;
079:
080: protected static String OPEN = org.netbeans.jellytools.Bundle
081: .getStringTrimmed("org.openide.actions.Bundle", "Open");
082:
083: protected static String EDIT = org.netbeans.jellytools.Bundle
084: .getStringTrimmed("org.openide.actions.Bundle", "Edit");
085:
086: /**
087: * Creates a new instance of OpenFiles
088: * @param testName the name of the test
089: */
090: public OpenFiles(String testName) {
091: super (testName);
092: expectedTime = WINDOW_OPEN;
093: }
094:
095: /**
096: * Creates a new instance of OpenFiles
097: * @param testName the name of the test
098: * @param performanceDataName measured values will be saved under this name
099: */
100: public OpenFiles(String testName, String performanceDataName) {
101: super (testName, performanceDataName);
102: expectedTime = WINDOW_OPEN;
103: }
104:
105: public void testOpening20kBJavaFile() {
106: WAIT_AFTER_OPEN = 6000;
107: setJavaEditorCaretFilteringOn();
108: fileProject = "PerformanceTestData";
109: filePackage = "org.netbeans.test.performance";
110: fileName = "Main20kB.java";
111: menuItem = OPEN;
112: doMeasurement();
113: }
114:
115: public void testOpening20kBTxtFile() {
116: WAIT_AFTER_OPEN = 1500;
117: setPlainTextEditorCaretFilteringOn();
118: fileProject = "PerformanceTestData";
119: filePackage = "org.netbeans.test.performance";
120: fileName = "textfile20kB.txt";
121: menuItem = OPEN;
122: doMeasurement();
123: }
124:
125: public void testOpening20kBXmlFile() {
126: WAIT_AFTER_OPEN = 3000;
127: setXMLEditorCaretFilteringOn();
128: fileProject = "PerformanceTestData";
129: filePackage = "org.netbeans.test.performance";
130: fileName = "xmlfile20kB.xml";
131: menuItem = EDIT;
132: doMeasurement();
133: }
134:
135: protected void initialize() {
136: EditorOperator.closeDiscardAll();
137: repaintManager()
138: .addRegionFilter(repaintManager().EDITOR_FILTER);
139: }
140:
141: public void prepare() {
142: this .openNode = new Node(new SourcePackagesNode(fileProject),
143: filePackage + '|' + fileName);
144: log("========== Open file path =" + this .openNode.getPath());
145: }
146:
147: public ComponentOperator open() {
148: JPopupMenuOperator popup = this .openNode.callPopup();
149: if (popup == null) {
150: throw new Error("Cannot get context menu for node ["
151: + openNode.getPath() + "] in project ["
152: + fileProject + "]");
153: }
154: log("------------------------- after popup invocation ------------");
155:
156: try {
157: popup.pushMenu(this .menuItem);
158: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
159: tee.printStackTrace(getLog());
160: throw new Error("Cannot push menu item [" + this .menuItem
161: + "] of node [" + openNode.getPath()
162: + "] in project [" + fileProject + "]");
163: }
164: log("------------------------- after open ------------");
165: return new EditorOperator(this .fileName);
166: }
167:
168: public void close() {
169: if (testedComponentOperator != null) {
170: hookEditorDocument(testedComponentOperator.getSource());
171: ((EditorOperator) testedComponentOperator).closeDiscard();
172: } else {
173: throw new Error("no component to close");
174: }
175: }
176:
177: protected void shutdown() {
178: testedComponentOperator = null; // allow GC of editor and documents
179: EditorOperator.closeDiscardAll();
180: repaintManager().resetRegionFilters();
181: }
182:
183: private void hookEditorDocument(Component comp) {
184: if (comp instanceof Container) {
185: Container cont = (Container) comp;
186: for (Component c : cont.getComponents()) {
187: hookEditorDocument(c);
188: }
189: if ("org.openide.text.QuietEditorPane".equals(comp
190: .getClass().getName())) {
191: JEditorPane pane = (JEditorPane) comp;
192: Document doc = pane.getDocument();
193: if (doc != null)
194: reportReference("Editor document from test "
195: + getName(), doc, EDITOR_REFS);
196: }
197: }
198: }
199:
200: /** Tests if created and later dclosed projects can be GCed from memory.
201: */
202: public void testGC() throws Exception {
203: Thread.sleep(60 * 1000);
204: runTestGC(EDITOR_REFS);
205: }
206:
207: }
|