Author: dmaliarevich
Date: 2012-06-22 06:08:03 -0400 (Fri, 22 Jun 2012)
New Revision: 42172
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/SelectionSynchronizationTest.java
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java
Log:
https://issues.jboss.org/browse/JBIDE-12114 - BotTest to check selection in visual pane
via left arrow + shift key.
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 2012-06-22
09:59:16 UTC (rev 42171)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/KeyboardHelper.java 2012-06-22
10:08:03 UTC (rev 42172)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.ui.bot.ext.helper;
import java.awt.AWTException;
@@ -13,34 +23,64 @@
public class KeyboardHelper {
private static Robot robot = null;
+
+ public static void keyPressedEvent (Display display, int keyCode) {
+ Event keyPressed = new Event();
+ keyPressed.keyCode = keyCode;
+ keyPressed.type = SWT.KeyDown;
+ display.post(keyPressed);
+ }
+
+ public static void keyReleasedEvent (Display display, int keyCode) {
+ Event keyReleased = new Event();
+ keyReleased.keyCode = keyCode;
+ keyReleased.type = SWT.KeyUp;
+ display.post(keyReleased);
+ }
+
/**
* Simulate pressing of key with keyCode via SWT
* @param display
* @param keyCode
*/
- public static void pressKeyCode (Display display , int keyCode){
-
- Event keyPressed = new Event();
- keyPressed.keyCode = keyCode;
- keyPressed.type = SWT.KeyDown;
- display.post(keyPressed);
- Event keyReleased = new Event();
- keyReleased.keyCode = keyCode;
- keyReleased.type = SWT.KeyUp;
- display.post(keyReleased);
-
+ public static void pressKeyCode (Display display, int keyCode) {
+ keyPressedEvent(display, keyCode);
+ keyReleasedEvent(display, keyCode);
}
+
/**
* Simulate pressing of keys with keyCodes via SWT
* @param display
* @param keyCodes
*/
- public static void pressKeyCodes (Display display , byte[] keyCodes){
- for (byte keyCode : keyCodes){
- KeyboardHelper.pressKeyCode(display,keyCode);
- SWTUtils.sleep(Timing.time1S());
- }
+ public static void pressKeyCodes (Display display, byte[] keyCodes){
+ for (byte keyCode : keyCodes){
+ KeyboardHelper.pressKeyCode(display,keyCode);
+ SWTUtils.sleep(Timing.time1S());
+ }
}
+
+ public static void typeKeyCodeUsingSWT (Display display, int swtKeyCode , int...
modifiers){
+ if (modifiers != null){
+ for (int modifierCode : modifiers){
+ KeyboardHelper.keyPressedEvent(display, modifierCode);
+ }
+ }
+ KeyboardHelper.pressKeyCode(display, swtKeyCode);
+ if (modifiers != null){
+ for (int modifierCode : modifiers){
+ KeyboardHelper.keyReleasedEvent(display, modifierCode);
+ }
+ }
+ }
+
+ public static void selectTextUsingSWTEvents (Display display, boolean forward, int
selectionLength) {
+ int arrowCode = forward ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT;
+ for (int index = 0 ; index < selectionLength; index ++){
+ typeKeyCodeUsingSWT(display, arrowCode, SWT.SHIFT);
+ }
+ }
+
/**
* Simulate pressing of key with keyCode via AWT
* @param awtKeyCode
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 2012-06-22
09:59:16 UTC (rev 42171)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2012-06-22
10:08:03 UTC (rev 42172)
@@ -18,6 +18,7 @@
import org.jboss.tools.vpe.ui.bot.test.editor.InsertActionsTest;
import org.jboss.tools.vpe.ui.bot.test.editor.MinMaxPanesTest;
import org.jboss.tools.vpe.ui.bot.test.editor.MultiSelectionTest;
+import org.jboss.tools.vpe.ui.bot.test.editor.SelectionSynchronizationTest;
import org.jboss.tools.vpe.ui.bot.test.editor.StylesOnThePageTest;
import org.jboss.tools.vpe.ui.bot.test.editor.TextEditingActionsTest;
import org.jboss.tools.vpe.ui.bot.test.editor.TextSelectionTest;
@@ -216,7 +217,8 @@
UnicodeCharacterDisplayingTest.class,
ExternalEditingTest.class,
VpeToolbarTest.class,
- MultiSelectionTest.class
+ MultiSelectionTest.class,
+ SelectionSynchronizationTest.class
})
public class VPEAllBotTests extends SWTBotTestCase{
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/SelectionSynchronizationTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/SelectionSynchronizationTest.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/SelectionSynchronizationTest.java 2012-06-22
10:08:03 UTC (rev 42172)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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 org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+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;
+
+public class SelectionSynchronizationTest extends VPEEditorTestCase {
+
+ private SWTBotExt botExt = null;
+ private SWTBotEditorExt jspTextEditor;
+ private SWTBotWebBrowser webBrowser;
+ private final String SIMPLE_TEXT = "Some Plain Text Here"; //$NON-NLS-1$
+ private final int SELECTION_LENGTH = 7;
+
+ public SelectionSynchronizationTest() {
+ super();
+ botExt = new SWTBotExt();
+ }
+
+ public void testSelectionSynchronization() throws Throwable {
+ /*
+ * Open test page
+ */
+ openPage();
+ jspTextEditor = botExt.swtBotEditorExtByTitle(TEST_PAGE);
+ setEditor(jspTextEditor);
+ webBrowser = new SWTBotWebBrowser(TEST_PAGE, botExt);
+ setEditorText(getEditor().getText());
+ getEditor().setFocus();
+ Display d = bot.getDisplay();
+
+ jspTextEditor.setFocus();
+ jspTextEditor.navigateTo(13,0);
+ jspTextEditor.typeText(SIMPLE_TEXT);
+ jspTextEditor.navigateTo(13,0);
+
+ KeyboardHelper.selectTextUsingSWTEvents(d, true, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ String selectionText = webBrowser.getSelectionText();
+ assertEquals("Step 1. Selected text in the Visual Part is wrong: ",
"Some Pl", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+ KeyboardHelper.selectTextUsingSWTEvents(d, false, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ selectionText = webBrowser.getSelectionText();
+ assertEquals("Step 2. Selected text in the Visual Part is wrong: ", "me
Plai", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+ /*
+ * Select text in Web Browser
+ */
+ webBrowser.setFocus();
+ nsIDOMNode node = webBrowser.getDomNodeByTagName("SPAN", 1); //$NON-NLS-1$
+ webBrowser.setFocus();
+ webBrowser.selectDomNode(node, 0);
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+
+ KeyboardHelper.selectTextUsingSWTEvents(d, true, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ selectionText = jspTextEditor.getSelection();
+ assertEquals("Step 3. Selected text in the Source Part is wrong: ", "ome
Pla", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+ KeyboardHelper.pressKeyCode(d, SWT.ARROW_RIGHT);
+ KeyboardHelper.selectTextUsingSWTEvents(d, false, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ selectionText = jspTextEditor.getSelection();
+ assertEquals("Step 4. Selected text in the Source Part is wrong: ", "e
Plain", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+
+ /*
+ * Navigate to the text
+ */
+ jspTextEditor.setFocus();
+ jspTextEditor.navigateTo(11, 38);
+ util.sleep(TIME_1S);
+ jspTextEditor.navigateTo(11, 39);
+ util.sleep(TIME_1S);
+ /*
+ * Select some text to the right
+ */
+ KeyboardHelper.selectTextUsingSWTEvents(d, true, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ selectionText = webBrowser.getSelectionText();
+ assertEquals("Step 5. Selected text in the Visual Part is wrong: ", "llo
Dem", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+ jspTextEditor.navigateTo(11, 46);
+ util.sleep(TIME_1S);
+ jspTextEditor.navigateTo(11, 51);
+ util.sleep(TIME_1S);
+ KeyboardHelper.selectTextUsingSWTEvents(d, false, SELECTION_LENGTH);
+ util.sleep(TIME_1S);
+ selectionText = webBrowser.getSelectionText();
+ assertEquals("Step 6. Selected text in the Visual Part is wrong: ", "emo
App", selectionText); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}