Author: vpakan(a)redhat.com
Date: 2010-11-03 05:12:36 -0400 (Wed, 03 Nov 2010)
New Revision: 26209
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextEditingActionsTest.java
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java
Log:
Added TextEditingActionsTest test.
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java 2010-11-03
09:11:09 UTC (rev 26208)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java 2010-11-03
09:12:36 UTC (rev 26209)
@@ -109,7 +109,11 @@
KeyboardHelper.robot.delay(Timing.time1S());
}
}
-
+ /**
+ * Gets AWT Key Code for specified character ch
+ * @param ch
+ * @return
+ */
public static int getAWTKeyCode (char ch){
int result = KeyEvent.VK_UNDEFINED;
try {
@@ -124,4 +128,27 @@
}
return result;
}
+ /**
+ * Selects text from current cursor position and selectionLength length. Selection
direction is specified
+ * by forward parameter
+ * @param forward
+ * @param selectionLength
+ */
+ public static void selectTextUsingAWTKeyBoard (boolean forward , int selectionLength)
{
+ int arrowCode = forward ? KeyEvent.VK_RIGHT : KeyEvent.VK_LEFT;
+ for (int index = 0 ; index < selectionLength; index ++){
+ typeKeyCodeUsingAWT(arrowCode,KeyEvent.VK_SHIFT);
+ }
+ }
+ /***
+ * Simulate typing of key with keyCode via AWT repeating numOfRepeats times
+ * @param awtKeyCode
+ * @param numOfRepeats
+ * @param modifiers
+ */
+ public static void typeKeyCodeUsingAWTRepeately (int awtKeyCode , int numOfRepeats,
int... modifiers) {
+ for (int index = 0 ; index < numOfRepeats ; index++){
+ KeyboardHelper.typeKeyCodeUsingAWT(awtKeyCode, modifiers);
+ }
+ }
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java 2010-11-03
09:11:09 UTC (rev 26208)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/SWTBotEditorExt.java 2010-11-03
09:12:36 UTC (rev 26209)
@@ -22,6 +22,7 @@
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCTabItem;
import org.eclipse.ui.IEditorReference;
+import org.jboss.tools.ui.bot.ext.Timing;
public class SWTBotEditorExt extends SWTBotEclipseEditor {
@@ -63,6 +64,17 @@
} catch (WidgetNotFoundException wnfe){
// do nothing there is no tabfolder in editor
}
- }
+ }
+ /**
+ * Deselect current selection and set cursor position to specified line and column
+ * @param line
+ * @param column
+ */
+ public void deselectAndSetCursorPosition (int line, int column){
+ selectRange(0, 0, 0);
+ insertText(line, column, "");
+ save();
+ bot.sleep(Timing.time2S());
+ }
}
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2010-11-03
09:11:09 UTC (rev 26208)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2010-11-03
09:12:36 UTC (rev 26209)
@@ -7,6 +7,7 @@
import org.jboss.tools.vpe.ui.bot.test.editor.BlockCommentTest;
import org.jboss.tools.vpe.ui.bot.test.editor.EditingActionsTest;
import org.jboss.tools.vpe.ui.bot.test.editor.InsertActionsTest;
+import org.jboss.tools.vpe.ui.bot.test.editor.TextEditingActionsTest;
import org.jboss.tools.vpe.ui.bot.test.editor.ToggleCommentTest;
import org.jboss.tools.vpe.ui.bot.test.editor.VerificationOfNameSpacesTest;
import org.jboss.tools.vpe.ui.bot.test.editor.JspFileEditingTest;
@@ -70,7 +71,7 @@
suite.addTestSuite(VisualEditorContextMenuTest.class);
suite.addTestSuite(InsertActionsTest.class);
suite.addTestSuite(EditingActionsTest.class);
-
+ suite.addTestSuite(TextEditingActionsTest.class);
return new TestSetup(suite);
}
}
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextEditingActionsTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextEditingActionsTest.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextEditingActionsTest.java 2010-11-03
09:12:36 UTC (rev 26209)
@@ -0,0 +1,216 @@
+/*******************************************************************************
+
+ * Copyright (c) 2007-2010 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.ui.bot.test.editor;
+
+import java.awt.event.KeyEvent;
+
+import org.eclipse.swtbot.swt.finder.utils.Position;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.helper.KeyboardHelper;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.vpe.ui.bot.test.tools.SWTBotWebBrowser;
+import org.mozilla.interfaces.nsIDOMNode;
+/**
+ * Tests JSP file Cut, Copy, Paste actions through Visual Editor Menu for Text selection
+ * @author vlado pakan
+ *
+ */
+public class TextEditingActionsTest extends VPEEditorTestCase {
+
+ private SWTBotExt botExt = null;
+
+ private static final String TEXT_TO_EDIT = "Text to edit";
+
+ private static final String PAGE_TEXT = "<%@ taglib
uri=\"http://java.sun.com/jsf/core\" prefix=\"f\"%>\n" +
+ "<%@ taglib
uri=\"http://java.sun.com/jsf/html\"
prefix=\"h\"%>\n" +
+ "<html>\n" +
+ " <head>\n" +
+ " <title>Input User Name Page</title>\n" +
+ " </head>\n" +
+ " <body>\n" +
+ " <f:view>\n" +
+ " <h:outputText value=\"" +
TextEditingActionsTest.TEXT_TO_EDIT + "\"/>\n" +
+ " </f:view>\n" +
+ " </body>\n" +
+ "</html>";
+
+ private static final String TEST_PAGE_NAME = "TextEditingActionsTest.jsp";
+
+ private SWTBotEditorExt jspEditor;
+ private SWTBotWebBrowser webBrowser;
+
+ public TextEditingActionsTest() {
+ super();
+ botExt = new SWTBotExt();
+ }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ eclipse.maximizeActiveShell();
+ createJspPage(TextEditingActionsTest.TEST_PAGE_NAME);
+ jspEditor = botExt.swtBotEditorExtByTitle(TextEditingActionsTest.TEST_PAGE_NAME);
+ webBrowser = new SWTBotWebBrowser(TextEditingActionsTest.TEST_PAGE_NAME,botExt);
+
+ }
+ /**
+ * Tests Cut Copy Paste Operations on Blank Page
+ */
+ public void testCutCopyPasteBlankPage(){
+
+ jspEditor.setText("");
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ jspEditor.setText(TextEditingActionsTest.TEXT_TO_EDIT);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ // Check Copy Functionality
+ String textToCutCopy = TextEditingActionsTest.TEXT_TO_EDIT.substring(0,4);
+ nsIDOMNode node = webBrowser.getDomNodeByTagName("SPAN", 0);
+ webBrowser.selectDomNode(node, 0);
+ jspEditor.deselectAndSetCursorPosition(0, 0);
+ webBrowser.setFocus();
+ KeyboardHelper.selectTextUsingAWTKeyBoard(true,textToCutCopy.length());
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.COPY_MENU_LABEL);
+ jspEditor.deselectAndSetCursorPosition(0,
TextEditingActionsTest.TEXT_TO_EDIT.length());
+ webBrowser.setFocus();
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.PASTE_MENU_LABEL);
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ String textToContain = TextEditingActionsTest.TEXT_TO_EDIT + textToCutCopy;
+ assertSourceEditorContains(jspEditor.getText(),
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ // Check Cut Functionality
+ webBrowser.selectDomNode(node, 0);
+ jspEditor.deselectAndSetCursorPosition(0, 0);
+ webBrowser.setFocus();
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT,
textToContain.length());
+ KeyboardHelper.selectTextUsingAWTKeyBoard(false, textToCutCopy.length());
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.CUT_MENU_LABEL);
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ jspEditor.deselectAndSetCursorPosition(0, 0);
+ assertSourceEditorIs(jspEditor.getText(),
+ TextEditingActionsTest.TEXT_TO_EDIT,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ TextEditingActionsTest.TEXT_TO_EDIT,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ webBrowser.setFocus();
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.PASTE_MENU_LABEL);
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ textToContain = textToCutCopy + TextEditingActionsTest.TEXT_TO_EDIT;
+ assertSourceEditorContains(jspEditor.getText(),
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ }
+
+ @Override
+ protected void closeUnuseDialogs() {
+
+ }
+
+ @Override
+ protected boolean isUnuseDialogOpened() {
+ return false;
+ }
+ @Override
+ protected void tearDown() throws Exception {
+ jspEditor.close();
+ super.tearDown();
+ }
+ /**
+ * Tests Cut Copy Paste Operations on Value Attribute
+ */
+ public void testCutCopyPasteValueAttribute(){
+
+ jspEditor.setText(TextEditingActionsTest.PAGE_TEXT);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ nsIDOMNode node = webBrowser.getDomNodeByTagName("SPAN", 0);
+ webBrowser.selectDomNode(node, 0);
+ bot.sleep(Timing.time1S());
+ // Check Copy Functionality
+ Position cursorPosition = jspEditor.cursorPosition();
+ jspEditor.deselectAndSetCursorPosition(cursorPosition.line, cursorPosition.column);
+ webBrowser.setFocus();
+ String textToCutCopy = TextEditingActionsTest.TEXT_TO_EDIT.substring(0,4);
+ KeyboardHelper.selectTextUsingAWTKeyBoard(true,textToCutCopy.length());
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.COPY_MENU_LABEL);
+ webBrowser.setFocus();
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT,
+ TextEditingActionsTest.TEXT_TO_EDIT.length() - textToCutCopy.length());
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.PASTE_MENU_LABEL);
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ String textToContain = TextEditingActionsTest.TEXT_TO_EDIT + textToCutCopy;
+ assertSourceEditorContains(jspEditor.getText(),
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ // Check Cut Functionality
+ webBrowser.selectDomNode(node, 0);
+ bot.sleep(Timing.time2S());
+ jspEditor.deselectAndSetCursorPosition(cursorPosition.line, cursorPosition.column);
+ webBrowser.setFocus();
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT,
textToContain.length());
+ KeyboardHelper.selectTextUsingAWTKeyBoard(false, textToCutCopy.length());
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.CUT_MENU_LABEL);
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ assertSourceEditorContains(jspEditor.getText(),
+ "\"" + TextEditingActionsTest.TEXT_TO_EDIT + "\"",
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ TextEditingActionsTest.TEXT_TO_EDIT,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ bot.sleep(Timing.time2S());
+ webBrowser.selectDomNode(node, 0);
+ bot.sleep(Timing.time2S());
+ jspEditor.deselectAndSetCursorPosition(cursorPosition.line, cursorPosition.column);
+ bot.sleep(Timing.time2S());
+ webBrowser.setFocus();
+ bot.sleep(Timing.time2S());
+ KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_RIGHT);
+ bot.sleep(Timing.time2S());
+ KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_LEFT);
+ webBrowser.clickContextMenu(node,
+ SWTBotWebBrowser.PASTE_MENU_LABEL);
+ bot.sleep(Timing.time2S());
+ jspEditor.save();
+ bot.sleep(Timing.time2S());
+ textToContain = textToCutCopy + TextEditingActionsTest.TEXT_TO_EDIT;
+ assertSourceEditorContains(jspEditor.getText(),
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ textToContain,
+ TextEditingActionsTest.TEST_PAGE_NAME);
+ }
+}
Property changes on:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextEditingActionsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java 2010-11-03
09:11:09 UTC (rev 26208)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/VPEEditorTestCase.java 2010-11-03
09:12:36 UTC (rev 26209)
@@ -99,11 +99,26 @@
assertTrue("File " + fileName
+ " has to contain string '"
+ textToContain
- + "' but it doesn't.\nIt contains: " + sourceEditorText,
+ + "' but it doesn't.\nIt is: " + sourceEditorText,
sourceEditorText.contains(textToContain));
}
/**
+ * Asserts if sourceEditorText of file with fileName equals to expectedText
+ * @param sourceEditorText
+ * @param expectedText
+ * @param fileName
+ */
+ protected static void assertSourceEditorIs (String sourceEditorText, String
expectedText, String fileName){
+
+ assertTrue("File " + fileName
+ + " has to be '"
+ + expectedText
+ + "' but it doesn't.\nIt is: " + sourceEditorText,
+ sourceEditorText.equals(expectedText));
+
+ }
+ /**
* Asserts if Visual Editor contains node with particular attributes
* @param webBrowser
* @param nodeNameToContain
@@ -127,7 +142,7 @@
}
/**
- * Asserts if Visual Editor contains node nodeNameToContain at least numOccurrencies
times
+ * Asserts if Visual Editor contains node nodeNameToContain exactly numOccurrencies
times
* @param webBrowser
* @param nodeNameToContain
* @param numOccurrences
@@ -147,5 +162,23 @@
webBrowser.getDomNodeOccurenciesByTagName(nodeNameToContain) == numOccurrences);
}
-
+ /**
+ * Asserts if Visual Editor contains node with value valueToContain
+ * @param webBrowser
+ * @param valueToContain
+ * @param fileName
+ */
+ protected static void assertVisualEditorContainsNodeWithValue (SWTBotWebBrowser
webBrowser,
+ String valueToContain,
+ String fileName){
+
+ assertTrue("Visual Representation of file " + fileName
+ + " has to contain noide with "
+ + valueToContain
+ + " value but it doesn't",
+ webBrowser.containsNodeWithValue(webBrowser.getMozillaEditor().getDomDocument(),
+ valueToContain));
+
+ }
+
}