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 gui.VWPUtilities;
045: import java.awt.Component;
046: import javax.swing.JButton;
047: import org.netbeans.jellytools.EditorOperator;
048: import org.netbeans.jellytools.NbDialogOperator;
049: import org.netbeans.jellytools.ProjectsTabOperator;
050: import org.netbeans.jellytools.TopComponentOperator;
051: import org.netbeans.jellytools.actions.ActionNoBlock;
052: import org.netbeans.jellytools.nodes.Node;
053: import org.netbeans.jemmy.ComponentChooser;
054: import org.netbeans.jemmy.JemmyProperties;
055: import org.netbeans.jemmy.operators.ComponentOperator;
056: import org.netbeans.jemmy.operators.JButtonOperator;
057: import org.netbeans.jemmy.operators.JComboBoxOperator;
058: import org.netbeans.jemmy.operators.JTabbedPaneOperator;
059: import org.netbeans.jemmy.operators.JTextComponentOperator;
060:
061: /**
062: *
063: * @author mkhramov@netbeans.org
064: */
065: public class CSSRuleAddTest extends
066: org.netbeans.performance.test.utilities.PerformanceTestCase {
067:
068: private String fileName;
069: private String projectName = "VisualWebProject";
070: private String styledocfolder = VWPUtilities.WEB_PAGES + "|"
071: + "resources"; // NOI18N
072: //private String styledocfolder = "Web Pages"+"|"+"resources"; // NOI18N
073:
074: /** Node to be opened/edited */
075: private static Node openNode;
076: protected static String OPEN = org.netbeans.jellytools.Bundle
077: .getStringTrimmed("org.openide.actions.Bundle", "Open");
078: //protected static String OPEN = "Open";
079:
080: private TopComponentOperator cssEditor = null;
081: private NbDialogOperator createRuleDialog = null;
082:
083: public CSSRuleAddTest(String testName) {
084: super (testName);
085: expectedTime = WINDOW_OPEN;
086: WAIT_AFTER_OPEN = 4000;
087: }
088:
089: public CSSRuleAddTest(String testName, String performanceDataName) {
090: super (testName, performanceDataName);
091: expectedTime = WINDOW_OPEN;
092: WAIT_AFTER_OPEN = 4000;
093: }
094:
095: @Override
096: public void initialize() {
097: log("::initialize");
098: fileName = "stylesheet.css"; //NO18N
099: EditorOperator.closeDiscardAll();
100:
101: }
102:
103: public void prepare() {
104: Node projectRoot = null;
105: projectRoot = new ProjectsTabOperator()
106: .getProjectRootNode(projectName);
107: projectRoot.select();
108: openNode = new Node(projectRoot, styledocfolder + "|"
109: + fileName);
110: openNode.performPopupActionNoBlock(OPEN);
111: cssEditor = findCSSEditor();
112: if (cssEditor != null) {
113: log("css editor found");
114: }
115:
116: }
117:
118: private void invokeAddRuleEditor() {
119: JButtonOperator addRuleButton;
120: long oldTimeout = JemmyProperties
121: .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
122: JemmyProperties.setCurrentTimeout(
123: "ComponentOperator.WaitComponentTimeout", 90000);
124: {
125: addRuleButton = new JButtonOperator(cssEditor,
126: new ComponentChooser() {
127:
128: public boolean checkComponent(
129: Component component) {
130: log("looking for component: "
131: + component.toString());
132: if ((((JButton) component).getToolTipText() != null)) {
133: if (((JButton) component)
134: .getToolTipText().equals(
135: "Create Rule")) {
136: return true;
137: } else
138: return false;
139: } else
140: return false;
141: }
142:
143: public String getDescription() {
144: return "Add CSS Rule button";
145: }
146: });
147: }
148: JemmyProperties.setCurrentTimeout(
149: "ComponentOperator.WaitComponentTimeout", oldTimeout);
150: log("add Rule Button obtained");
151: addRuleButton.pushNoBlock();
152: }
153:
154: public ComponentOperator open() {
155: log("::open");
156:
157: invokeAddRuleEditor();
158: String dialogTitle = org.netbeans.jellytools.Bundle.getString(
159: "org.netbeans.modules.css.actions.Bundle",
160: "STYLE_RULE_EDITOR_TITLE");
161: createRuleDialog = new NbDialogOperator(dialogTitle);
162: processAddRule();
163: changeRuleValueOne();
164: changeRuleValueTwo();
165: return cssEditor;
166: }
167:
168: @Override
169: public void close() {
170: log("::close");
171: EditorOperator.closeDiscardAll();
172: }
173:
174: @Override
175: protected void shutdown() {
176: log("::shutdown");
177: EditorOperator.closeDiscardAll();
178: }
179:
180: private TopComponentOperator findCSSEditor() {
181: TopComponentOperator cssEditorToFind;
182: long oldTimeout = JemmyProperties.getCurrentTimeouts()
183: .getTimeout("ComponentOperator.WaitComponentTimeout");
184: JemmyProperties.getCurrentTimeouts().setTimeout(
185: "ComponentOperator.WaitComponentTimeout", 120000);
186: cssEditorToFind = new TopComponentOperator(fileName);
187: JemmyProperties.getCurrentTimeouts().setTimeout(
188: "ComponentOperator.WaitComponentTimeout", oldTimeout);
189: return cssEditorToFind;
190: }
191:
192: private TopComponentOperator findStyleBuilder() {
193: return new TopComponentOperator(org.netbeans.jellytools.Bundle
194: .getString("org.netbeans.modules.css.visual.ui.Bundle",
195: "CTL_CSSStyleBuilderTopComponent"));
196: }
197:
198: private void processAddRule() {
199: JButtonOperator addButton = new JButtonOperator(
200: createRuleDialog, ">");
201:
202: JTextComponentOperator textb = new JTextComponentOperator(
203: createRuleDialog, 1);
204: textb.typeText("ZZZ");
205: addButton.pushNoBlock();
206: createRuleDialog.ok();
207: createRuleDialog.waitClosed();
208: }
209:
210: private void changeRuleValueOne() {
211: TopComponentOperator builder = findStyleBuilder();
212: JTabbedPaneOperator styleParts = new JTabbedPaneOperator(
213: builder, 0);
214: styleParts.selectPage("Background");
215: JComboBoxOperator bkColorCombo = new JComboBoxOperator(
216: styleParts, BACKCOLOR_COMBO_INDEX);
217: bkColorCombo.selectItem("teal");
218:
219: }
220:
221: private void changeRuleValueTwo() {
222: TopComponentOperator builder = findStyleBuilder();
223: JTabbedPaneOperator styleParts = new JTabbedPaneOperator(
224: builder, 0);
225: styleParts.selectPage("Position");
226: JComboBoxOperator modeCombo = new JComboBoxOperator(styleParts,
227: POSITION_COMBO_INDEX);
228: modeCombo.selectItem("relative");
229: System.out.println(modeCombo.getSelectedIndex());
230:
231: }
232:
233: private void OpenPreviewPane() {
234: String CSSPreviewItem = org.netbeans.jellytools.Bundle
235: .getString(
236: "org.netbeans.modules.css.visual.ui.preview.Bundle",
237: "CTL_CssPreviewAction");
238: new ActionNoBlock("Window" + "|" + "Other" + CSSPreviewItem,
239: null).performMenu(); // NOI18N
240: }
241:
242: private void OpenBuilderPane() {
243: String CSSBuilderItem = org.netbeans.jellytools.Bundle
244: .getString("org.netbeans.modules.css.visual.ui.Bundle",
245: "CTL_CSSStyleBuilderAction");
246: new ActionNoBlock("Window" + "|" + "Other" + CSSBuilderItem,
247: null).performMenu(); // NOI18N
248:
249: }
250:
251: private static final int BACKCOLOR_COMBO_INDEX = 6;
252: private static final int POSITION_COMBO_INDEX = 16;
253:
254: public static void main(String[] args) {
255: junit.textui.TestRunner
256: .run(new CSSRuleAddTest("doMeasurement"));
257: }
258:
259: }
|