Author: vpakan(a)redhat.com
Date: 2011-01-04 12:58:21 -0500 (Tue, 04 Jan 2011)
New Revision: 27878
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextSelectionTest.java
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/tools/SWTBotWebBrowser.java
Log:
Added TextSelectionTest
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 2011-01-04
17:38:09 UTC (rev 27877)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/VPEAllBotTests.java 2011-01-04
17:58:21 UTC (rev 27878)
@@ -10,6 +10,7 @@
import org.jboss.tools.vpe.ui.bot.test.editor.MinMaxPanesTest;
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;
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;
@@ -94,7 +95,7 @@
suite.addTestSuite(GlobalELVariablesTest.class);
suite.addTestSuite(IncludedCssFilesJSPTest.class);
suite.addTestSuite(StylesOnThePageTest.class);
-
+ suite.addTestSuite(TextSelectionTest.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/TextSelectionTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextSelectionTest.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextSelectionTest.java 2011-01-04
17:58:21 UTC (rev 27878)
@@ -0,0 +1,181 @@
+/*******************************************************************************
+
+ * 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.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.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.vpe.ui.bot.test.tools.SWTBotWebBrowser;
+/**
+ * Tests JSP file Editing and Cut, Copy, Paste actions through Visual Editor Menu for
Text selection
+ * @author vlado pakan
+ *
+ */
+public class TextSelectionTest extends VPEEditorTestCase {
+
+ private SWTBotExt botExt = null;
+
+ private static final String TEXT_TO_SELECT = "select";
+ private static final String TEXT_TO_TEST = "Text " +
TextSelectionTest.TEXT_TO_SELECT +" test";
+ private static final int SELECTION_START_LINE = 8;
+ private static final int SELECTION_START_COLUMN = 32;
+
+ 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=\"" + TextSelectionTest.TEXT_TO_TEST +
"\"/>\n" +
+ " </f:view>\n" +
+ " </body>\n" +
+ "</html>";
+
+ private static final String TEST_PAGE_NAME = "TextSelectionTest.jsp";
+
+ private SWTBotEditorExt jspEditor;
+ private SWTBotWebBrowser webBrowser;
+
+ public TextSelectionTest() {
+ super();
+ botExt = new SWTBotExt();
+ }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ eclipse.maximizeActiveShell();
+ createJspPage(TextSelectionTest.TEST_PAGE_NAME);
+ jspEditor = botExt.swtBotEditorExtByTitle(TextSelectionTest.TEST_PAGE_NAME);
+ webBrowser = new SWTBotWebBrowser(TextSelectionTest.TEST_PAGE_NAME,botExt);
+ }
+ /**
+ * Tests Text Selection
+ */
+ public void ttestTextSelection(){
+
+ jspEditor.setText(TextSelectionTest.PAGE_TEXT);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ // select text in Source Pane
+ jspEditor.selectRange(TextSelectionTest.SELECTION_START_LINE,
TextSelectionTest.SELECTION_START_COLUMN, TextSelectionTest.TEXT_TO_SELECT.length());
+ webBrowser.setFocus();
+ bot.sleep(Timing.time3S());
+ String selectedText = webBrowser.getSelectionText();
+ // check selected text in Visual Pane
+ assertTrue("Selected text in Visual Pane has to be '" +
TextSelectionTest.TEXT_TO_SELECT + "'" +
+ "\nBut is '" + selectedText+ "'",
+ TextSelectionTest.TEXT_TO_SELECT.equals(selectedText));
+ String newText = "newText";
+ // Type text replacing selected text in Visual Pane and check Source Pane content
+ KeyboardHelper.typeBasicStringUsingAWT(newText);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ assertSourceEditorContains(jspEditor.getText(), " " + newText + "
", TextSelectionTest.TEST_PAGE_NAME);
+ jspEditor.setText(TextSelectionTest.PAGE_TEXT);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ // select text in Visual Page
+ jspEditor.deselectAndSetCursorPosition(TextSelectionTest.SELECTION_START_LINE,
TextSelectionTest.SELECTION_START_COLUMN);
+ webBrowser.setFocus();
+ bot.sleep(Timing.time1S());
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT, 5);
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT,
TextSelectionTest.TEXT_TO_SELECT.length(),KeyEvent.VK_SHIFT);
+ bot.sleep(Timing.time1S());
+ // check selected text in Source Pane
+ selectedText = jspEditor.getSelection();
+ assertTrue("Selected text in Source Pane has to be '" +
TextSelectionTest.TEXT_TO_SELECT + "'" +
+ "\nBut is '" + selectedText+ "'",
+ TextSelectionTest.TEXT_TO_SELECT.equals(selectedText));
+ jspEditor.setFocus();
+ // type text replacing selected text in Source Pane and check Visual Pane content
+ KeyboardHelper.typeBasicStringUsingAWT(newText);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ TextSelectionTest.TEXT_TO_TEST.replaceFirst(TextSelectionTest.TEXT_TO_SELECT,
newText),
+ TextSelectionTest.TEST_PAGE_NAME);
+ // check if selection made on Source tab appears on Visual/Source tab Visual Pane
+ jspEditor.setText(TextSelectionTest.PAGE_TEXT);
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ SWTBotEditorExt botEditorExt = new
SWTBotExt().swtBotEditorExtByTitle(TextSelectionTest.TEST_PAGE_NAME);
+ botEditorExt.selectPage(IDELabel.VisualPageEditor.SOURCE_TAB_LABEL);
+ jspEditor.selectRange(TextSelectionTest.SELECTION_START_LINE,
TextSelectionTest.SELECTION_START_COLUMN, TextSelectionTest.TEXT_TO_SELECT.length());
+ botEditorExt.selectPage(IDELabel.VisualPageEditor.VISUAL_SOURCE_TAB_LABEL);
+ webBrowser.setFocus();
+ bot.sleep(Timing.time3S());
+ selectedText = webBrowser.getSelectionText();
+ // check selected text in Visual Pane
+ assertTrue("Selected text in Visual Pane has to be '" +
TextSelectionTest.TEXT_TO_SELECT + "'" +
+ "\nBut is '" + selectedText+ "'",
+ TextSelectionTest.TEXT_TO_SELECT.equals(selectedText));
+ }
+
+ /**
+ * Tests Text Selection of Special Symbols
+ */
+ public void testTextSelectionOfSpecialSymbols(){
+
+ jspEditor.setText("©2007 Exposure. All Rights Reserved." +
+ "•" +
+ "Design by <a
href=\"http://www.freecsstemplates.org/\">Free
CSS Templates</a>" +
+ "•" +
+ "Icons by <a
href=\"http://famfamfam.com/\">FAMFAMFAM</a>.");
+ jspEditor.save();
+ bot.sleep(Timing.time3S());
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ "©2007 Exposure. All Rights Reserved.•Design by ",
+ TextSelectionTest.TEST_PAGE_NAME);
+ assertVisualEditorContainsNodeWithValue(webBrowser,
+ "•Icons by ",
+ TextSelectionTest.TEST_PAGE_NAME);
+ jspEditor.deselectAndSetCursorPosition(0, 0);
+ webBrowser.setFocus();
+ KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_RIGHT,KeyEvent.VK_SHIFT);
+ String selectedText = jspEditor.getSelection();
+ String copySymbol = "©";
+ assertTrue("Selected text in Source Pane has to be '" + copySymbol +
"'" +
+ "\nBut is '" + selectedText+ "'",
+ copySymbol.equals(selectedText));
+ jspEditor.deselectAndSetCursorPosition(0, 0);
+ webBrowser.setFocus();
+ KeyboardHelper.typeKeyCodeUsingAWTRepeately(KeyEvent.VK_RIGHT, 36);
+ KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_RIGHT,KeyEvent.VK_SHIFT);
+ selectedText = jspEditor.getSelection();
+ String bullSymbol = "•";
+ assertTrue("Selected text in Source Pane has to be '" + bullSymbol +
"'" +
+ "\nBut is '" + selectedText+ "'",
+ bullSymbol.equals(selectedText));
+
+ }
+
+
+ @Override
+ protected void closeUnuseDialogs() {
+
+ }
+
+ @Override
+ protected boolean isUnuseDialogOpened() {
+ return false;
+ }
+ @Override
+ protected void tearDown() throws Exception {
+ jspEditor.close();
+ super.tearDown();
+ }
+}
Property changes on:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/editor/TextSelectionTest.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/tools/SWTBotWebBrowser.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2011-01-04
17:38:09 UTC (rev 27877)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/tools/SWTBotWebBrowser.java 2011-01-04
17:58:21 UTC (rev 27878)
@@ -61,6 +61,7 @@
import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
+import org.mozilla.interfaces.nsIDOMRange;
import org.mozilla.interfaces.nsIDOMWindow;
import org.mozilla.interfaces.nsIEditor;
import org.mozilla.interfaces.nsISelection;
@@ -748,5 +749,38 @@
}
return result;
}
+ /**
+ * Returns selected text in first selection range.
+ * Works correctly only when single node is selected.
+ * @return
+ */
+ public String getSelectionText (){
+ String result = null;
+
+ nsISelection selection = getSelection();
+ if (selection != null && selection.getRangeCount() > 0){
+ nsIDOMRange firstSelectedRange = selection.getRangeAt(0);
+ nsIDOMNode selectedNode = getSelectedDomNode();
+ if (selectedNode.getNodeName().equals("#text")){
+ int startOffset = firstSelectedRange.getStartOffset();
+ int endOffset = firstSelectedRange.getEndOffset();
+ int beginIndex, endIndex;
+ if (startOffset > endOffset){
+ beginIndex = endOffset;
+ endIndex = startOffset;
+ }
+ else{
+ beginIndex = startOffset;
+ endIndex = endOffset;
+ }
+ result = selectedNode
+ .getNodeValue()
+ .substring(beginIndex, endIndex);
+ }
+ }
+
+ return result;
+
+ }
}