8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javafx.scene.control.test.textinput;
26
27 import client.test.ScreenshotCheck;
28 import com.sun.javafx.scene.control.skin.TextInputControlSkin;
29 import java.lang.reflect.Field;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36 import javafx.beans.property.BooleanProperty;
37 import javafx.scene.Node;
38 import javafx.scene.Scene;
39 import javafx.scene.control.Button;
40 import javafx.scene.control.Control;
41 import javafx.scene.control.MenuItem;
42 import javafx.scene.control.PasswordField;
43 import javafx.scene.control.TextInputControl;
44 import javafx.scene.control.test.Change;
45 import javafx.scene.control.test.mix.PopupMenuTest;
46 import javafx.scene.control.test.textinput.TextInputBaseApp.Pages;
47 import javafx.scene.control.test.textinput.TextInputChanger.TextInputControlWrapInterface;
48 import javafx.scene.control.test.textinput.TextInputChanger.TextInputPages;
65 import org.junit.Assert;
66 import static org.junit.Assert.*;
67 import org.junit.Test;
68 import org.junit.runner.RunWith;
69 import test.javaclient.shared.FilteredTestRunner;
70 import test.javaclient.shared.TestBase;
71 import test.javaclient.shared.Utils;
72 import test.javaclient.shared.screenshots.ScreenshotUtils;
73
74 /**
75 * @author Oleg Barbashov
76 */
77 @RunWith(FilteredTestRunner.class)
78 public class TextInputBase extends TestBase {
79
80 {
81 ScreenshotUtils.setComparatorDistance(0.003f);
82 }
83 private Wrap<? extends TextInputControl> taTesting = null;
84
85 static final KeyboardModifiers CTRL = Utils.isMacOS() ? KeyboardModifiers.META_DOWN_MASK : KeyboardModifiers.CTRL_DOWN_MASK;
86 // /**
87 // * Test for TextInput setMaximumLength API
88 // */
89 // @ScreenshotCheck
90 // @Test(timeout=300000)
91 // public void maximumLengthTest() throws InterruptedException, Throwable {
92 // openPage(Pages.MaximumLength.name());
93 //
94 // verifyFailures();
95 //
96 // Parent<Node> parent = scene.as(Parent.class, Node.class);
97 // Lookup lookup = parent.lookup(TextInput.class);
98 // for (int i = 0; i < lookup.size(); i++) {
99 // final Wrap<? extends TextInput> wrap = lookup.wrap(i);
100 // final Integer maximumLength = new GetAction<Integer>() {
101 // @Override
102 // public void run(Object... parameters) {
103 // setResult(wrap.getControl().getMaximumLength());
104 // }
105 // }.dispatch(Root.ROOT.getEnvironment());
506 @Test(timeout = 300000)
507 public void contextMenuTest() throws InterruptedException {
508 openPage(Pages.InputTest.name());
509
510 final Wrap<? extends TextInputControl> wrap = getScene().as(Parent.class, Node.class).lookup(TextInputControl.class).wrap();
511 final Text text = wrap.as(Text.class);
512
513 initContext();
514 boolean password = PasswordField.class.isAssignableFrom(wrap.getControl().getClass());
515 if (!password) {
516 getMenuItem("Select All").mouse().move();
517 getMenuItem("Copy").mouse().click();
518 checkClipboard(SAMPLE_STRING);
519
520 getMenuItem("Cut").mouse().click();
521 checkClipboard(SAMPLE_STRING);
522 checkText(text, "");
523 } else {
524 checkState("Copy", true);
525 checkState("Cut", true);
526 }
527
528 initContext();
529 getMenuItem("Delete").mouse().click();
530 checkText(text, "");
531
532 initContext();
533 getMenuItem("Select All").mouse().click();
534 getScene().waitState(new State() {
535 public Object reached() {
536 return wrap.getControl().getSelection().getLength() == SAMPLE_STRING.length() ? true : null;
537 }
538 });
539
540 initContext();
541 final Map<DataFormat, Object> data_map = new HashMap<DataFormat, Object>();
542 data_map.put(DataFormat.PLAIN_TEXT, SAMPLE_STRING);
543
544 new GetAction() {
545 @Override
594 click(btn);
595 ctrlDeleteTest();
596 }
597
598 @ScreenshotCheck
599 @Test
600 public void ctrlDeleteRandomSymbolsTest() {
601 openPage(Pages.CtrlDeleteTest.name());
602 Wrap<? extends Button> btn = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<Button>(TextAreaApp.RANDOM_TEXT_BTN_ID + Pages.CtrlDeleteTest.name())).wrap();
603 click(btn);
604 ctrlDeleteTest();
605 }
606
607 private void ctrlBackspaceTest() {
608 taTesting = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<TextInputControl>(TextAreaApp.INPUT_AREA_ID + Pages.CtrlBackspaceTest.name())).wrap();
609 click(taTesting);
610 end();
611
612 String text = getTextFromControl();
613 final String initialText = text;
614 while (!"".equals(text)) {
615 text = deleteLastWord(text);
616 taTesting.keyboard().pushKey(Keyboard.KeyboardButtons.BACK_SPACE, CTRL);
617 if (isPasswordField()) {
618 Assert.assertEquals(initialText, getTextFromControl());
619 } else {
620 if (!text.equals(getTextFromControl())) {
621 out(initialText, text);
622 }
623 Assert.assertEquals(text, getTextFromControl());
624 }
625 }
626 }
627
628 private void ctrlDeleteTest() {
629 taTesting = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<TextInputControl>(TextAreaApp.INPUT_AREA_ID + Pages.CtrlDeleteTest.name())).wrap();
630
631 click(taTesting);
632 home();
633 String text = getTextFromControl();
634 final String initialText = text;
635 while (!"".equals(text)) {
636 text = deleteFirstWord(text, true);
637 taTesting.keyboard().pushKey(Keyboard.KeyboardButtons.DELETE, CTRL);
638 if (isPasswordField()) {
639 Assert.assertEquals(initialText, getTextFromControl());
640 } else {
641 if (!text.equals(getTextFromControl())) {
642 out(initialText, text);
643 }
644 Assert.assertEquals(text, getTextFromControl());
645 }
646 }
647 }
648
649 private void out(String initial, String text) {
650 System.out.println("Initial text : ");
651 System.out.println(initial);
652 System.out.println("Control's text : ");
653 System.out.println(getTextFromControl());
654 System.out.println("Text : ");
655 System.out.println(text);
656 System.out.println("END");
657 }
658
659 private String deleteLastWord(String text) {
660 String reverce = new StringBuffer(text).reverse().toString();
661 reverce = deleteFirstWord(reverce, false);
662 return new StringBuffer(reverce).reverse().toString();
663 }
664
665 /*
666 * Deletes first word according to specific rules.
667 * Behavior depend on whether deleting is made
668 * using Ctrl + Delete in the beginning of the string or
669 * using Ctrl + Backspace in the end of the string.
670 * <code>deleteFromBeginning</code> flag separates these cases.
671 *
672 * @param text initial string
673 * @param deleteFromBeginning flag which shows how deletion is performed.
674 * @return string without first word.
675 */
676 private String deleteFirstWord(String text, boolean deleteFromBeginning) {
677 final String[] punctuation = new String[]{" ", "\n", "\t", "/", ",", ";", "!", "@", "#", "$", "%", "^", "*", "(", ")", "&", "."};
678 if (!deleteFromBeginning) {
679 while (startsWithAnyOf(text, punctuation)) {
680 text = text.substring(1);
681 }
682 text = removeLeadingChars(text, punctuation);
683 } else {
684 if (!Utils.isWindows()) {
685 if (' ' == text.charAt(0)) {
686 int pos = 0;
687 while(' ' == text.charAt(pos)) ++pos;
688 text = text.substring(pos);
689 } else if (startsWithAnyOf(text, punctuation)) {
690 text = text.substring(1);
691 }
692 }
693
694 text = removeLeadingChars(text, punctuation);
695
696 while (startsWithAnyOf(text, punctuation)) {
697 if (!Utils.isWindows()) {
698 break;
699 }
700 text = text.substring(1);
701 }
702 }
703 return text;
704 }
705
706 /*
707 For each charachter from <code>toRemove</code> finds which occurs first and deletes it.
708 If none is found then returns empty string.
709 */
710 String removeLeadingChars(String str, String[] toRemove) {
711 int idx = Integer.MAX_VALUE;
712 for (String ch : toRemove) {
713 if (str.indexOf(ch) >= 0) {
714 idx = Math.min(str.indexOf(ch), idx);
715 }
716 }
717 idx = idx == Integer.MAX_VALUE ? -1 : idx;
718 return (idx < 0) ? "" : str.substring(idx);
719 }
720
721 protected boolean startsWithAnyOf(String str, String[] symbols) {
722 for (String sym : symbols) {
723 if (str.startsWith(sym)) {
724 return true;
725 }
726 }
727 return false;
728 }
729
730 protected void click(Wrap<? extends Control> control) {
731 Point p = control.getClickPoint();
732 control.mouse().move(p);
733 control.mouse().click();
734 }
735
736 protected void initContext() {
737 final Wrap<? extends TextInputControl> wrap = getScene().as(Parent.class, Node.class).lookup(TextInputControl.class).wrap();
738 wrap.as(Text.class).clear();
739 wrap.as(Text.class).type(SAMPLE_STRING);
740 wrap.keyboard().pushKey(KeyboardButtons.A, Utils.isMacOS() ? KeyboardModifiers.META_DOWN_MASK : CTRL);
741 new GetAction() {
742 @Override
743 public void run(Object... os) throws Exception {
744 Clipboard.getSystemClipboard().clear();
745 }
746 }.dispatch(Root.ROOT.getEnvironment());
747 }
748
749 protected void checkState(final String menu, boolean disabled) {
750 Wrap<? extends Node> wrap = getMenuItem(menu);
751 MenuItem menu_item = ((MenuItem) wrap.getControl().getProperties().get(MenuItem.class));
752 assertEquals(menu_item.isDisable(), disabled);
753 }
754
755 protected void checkText(final Text text, final String str) {
756 getScene().waitState(new State() {
757 public Object reached() {
758 return text.text().contentEquals(str) ? true : null;
759 }
760 });
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javafx.scene.control.test.textinput;
26
27 import client.test.ScreenshotCheck;
28 import javafx.scene.control.skin.TextInputControlSkin;
29 import java.lang.reflect.Field;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
36 import javafx.beans.property.BooleanProperty;
37 import javafx.scene.Node;
38 import javafx.scene.Scene;
39 import javafx.scene.control.Button;
40 import javafx.scene.control.Control;
41 import javafx.scene.control.MenuItem;
42 import javafx.scene.control.PasswordField;
43 import javafx.scene.control.TextInputControl;
44 import javafx.scene.control.test.Change;
45 import javafx.scene.control.test.mix.PopupMenuTest;
46 import javafx.scene.control.test.textinput.TextInputBaseApp.Pages;
47 import javafx.scene.control.test.textinput.TextInputChanger.TextInputControlWrapInterface;
48 import javafx.scene.control.test.textinput.TextInputChanger.TextInputPages;
65 import org.junit.Assert;
66 import static org.junit.Assert.*;
67 import org.junit.Test;
68 import org.junit.runner.RunWith;
69 import test.javaclient.shared.FilteredTestRunner;
70 import test.javaclient.shared.TestBase;
71 import test.javaclient.shared.Utils;
72 import test.javaclient.shared.screenshots.ScreenshotUtils;
73
74 /**
75 * @author Oleg Barbashov
76 */
77 @RunWith(FilteredTestRunner.class)
78 public class TextInputBase extends TestBase {
79
80 {
81 ScreenshotUtils.setComparatorDistance(0.003f);
82 }
83 private Wrap<? extends TextInputControl> taTesting = null;
84
85 static final KeyboardModifiers CTRL = Utils.isMacOS() ? KeyboardModifiers.ALT_DOWN_MASK : KeyboardModifiers.CTRL_DOWN_MASK;
86 // /**
87 // * Test for TextInput setMaximumLength API
88 // */
89 // @ScreenshotCheck
90 // @Test(timeout=300000)
91 // public void maximumLengthTest() throws InterruptedException, Throwable {
92 // openPage(Pages.MaximumLength.name());
93 //
94 // verifyFailures();
95 //
96 // Parent<Node> parent = scene.as(Parent.class, Node.class);
97 // Lookup lookup = parent.lookup(TextInput.class);
98 // for (int i = 0; i < lookup.size(); i++) {
99 // final Wrap<? extends TextInput> wrap = lookup.wrap(i);
100 // final Integer maximumLength = new GetAction<Integer>() {
101 // @Override
102 // public void run(Object... parameters) {
103 // setResult(wrap.getControl().getMaximumLength());
104 // }
105 // }.dispatch(Root.ROOT.getEnvironment());
506 @Test(timeout = 300000)
507 public void contextMenuTest() throws InterruptedException {
508 openPage(Pages.InputTest.name());
509
510 final Wrap<? extends TextInputControl> wrap = getScene().as(Parent.class, Node.class).lookup(TextInputControl.class).wrap();
511 final Text text = wrap.as(Text.class);
512
513 initContext();
514 boolean password = PasswordField.class.isAssignableFrom(wrap.getControl().getClass());
515 if (!password) {
516 getMenuItem("Select All").mouse().move();
517 getMenuItem("Copy").mouse().click();
518 checkClipboard(SAMPLE_STRING);
519
520 getMenuItem("Cut").mouse().click();
521 checkClipboard(SAMPLE_STRING);
522 checkText(text, "");
523 } else {
524 checkState("Copy", true);
525 checkState("Cut", true);
526 getScene().keyboard().pushKey(KeyboardButtons.ESCAPE);
527 }
528
529 initContext();
530 getMenuItem("Delete").mouse().click();
531 checkText(text, "");
532
533 initContext();
534 getMenuItem("Select All").mouse().click();
535 getScene().waitState(new State() {
536 public Object reached() {
537 return wrap.getControl().getSelection().getLength() == SAMPLE_STRING.length() ? true : null;
538 }
539 });
540
541 initContext();
542 final Map<DataFormat, Object> data_map = new HashMap<DataFormat, Object>();
543 data_map.put(DataFormat.PLAIN_TEXT, SAMPLE_STRING);
544
545 new GetAction() {
546 @Override
595 click(btn);
596 ctrlDeleteTest();
597 }
598
599 @ScreenshotCheck
600 @Test
601 public void ctrlDeleteRandomSymbolsTest() {
602 openPage(Pages.CtrlDeleteTest.name());
603 Wrap<? extends Button> btn = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<Button>(TextAreaApp.RANDOM_TEXT_BTN_ID + Pages.CtrlDeleteTest.name())).wrap();
604 click(btn);
605 ctrlDeleteTest();
606 }
607
608 private void ctrlBackspaceTest() {
609 taTesting = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<TextInputControl>(TextAreaApp.INPUT_AREA_ID + Pages.CtrlBackspaceTest.name())).wrap();
610 click(taTesting);
611 end();
612
613 String text = getTextFromControl();
614 final String initialText = text;
615 if (isPasswordField()) {
616 taTesting.keyboard().pushKey(Keyboard.KeyboardButtons.BACK_SPACE, CTRL);
617 if (Utils.isMacOS()) {
618 Assert.assertEquals("", getTextFromControl());
619 } else {
620 Assert.assertEquals(initialText, getTextFromControl());
621 }
622 } else {
623 while (!text.isEmpty()) {
624 text = deleteLastWord(text);
625 taTesting.keyboard().pushKey(Keyboard.KeyboardButtons.BACK_SPACE, CTRL);
626 if (!text.equals(getTextFromControl())) {
627 out(initialText, text);
628 }
629 Assert.assertEquals(text, getTextFromControl());
630 }
631 }
632 }
633
634 private void ctrlDeleteTest() {
635 taTesting = getScene().as(org.jemmy.interfaces.Parent.class, Node.class).lookup(new ByID<TextInputControl>(TextAreaApp.INPUT_AREA_ID + Pages.CtrlDeleteTest.name())).wrap();
636
637 click(taTesting);
638 home();
639 String text = getTextFromControl();
640 final String initialText = text;
641 while (!"".equals(text)) {
642 text = deleteFirstWord(text, Utils.isMacOS() ? false : true);
643 taTesting.keyboard().pushKey(Keyboard.KeyboardButtons.DELETE, CTRL);
644 if (isPasswordField()) {
645 Assert.assertEquals(initialText, getTextFromControl());
646 } else {
647 if (!text.equals(getTextFromControl())) {
648 out(initialText, text);
649 }
650 Assert.assertEquals(text, getTextFromControl());
651 }
652 }
653 }
654
655 private void out(String initial, String text) {
656 System.out.println("Initial text : ");
657 System.out.println(initial);
658 System.out.println("Control's text : ");
659 System.out.println(getTextFromControl());
660 System.out.println("Text : ");
661 System.out.println(text);
662 System.out.println("END");
663 }
664
665 private String deleteLastWord(String text) {
666 String reverce = new StringBuffer(text).reverse().toString();
667 reverce = deleteFirstWord(reverce, false);
668 return new StringBuffer(reverce).reverse().toString();
669 }
670
671 /*
672 * Deletes first word according to specific rules.
673 * Behavior depend on whether deleting is made
674 * using Ctrl + Delete in the beginning of the string or
675 * using Ctrl + Backspace in the end of the string.
676 * <code>deleteFromBeginning</code> flag separates these cases.
677 *
678 * @param text initial string
679 * @param deleteFromBeginning flag which shows how deletion is performed.
680 * @return string without first word.
681 */
682 private String deleteFirstWord(String text, boolean deleteFromBeginning) {
683 final String[] punctuation = new String[] {" ", "\n", "\t", "/", ",", ";", "!", "@", "#", "$", "%", "^", "*", "(", ")", "&", "."};
684
685 if (!deleteFromBeginning) {
686 while (startsWithAnyOf(text, punctuation)) {
687 text = text.substring(1);
688 }
689 text = removeLeadingChars(text, punctuation);
690 } else {
691 if (Utils.isLinux()) {
692 if (' ' == text.charAt(0)) {
693 int pos = 0;
694 while(' ' == text.charAt(pos)) ++pos;
695 text = text.substring(pos);
696 } else if (startsWithAnyOf(text, punctuation)) {
697 text = text.substring(1);
698 }
699 }
700
701 if ('\n' == text.charAt(0)) {
702 text = text.substring(1);
703 return text;
704 }
705
706 text = removeLeadingChars(text, punctuation);
707
708 if ('\n' == text.charAt(0)) {
709 return text;
710 }
711 if (Utils.isLinux()) {
712 return text;
713 }
714 while (startsWithAnyOf(text, punctuation)) {
715 text = text.substring(1);
716 }
717 }
718 return text;
719 }
720
721 /*
722 For each charachter from <code>toRemove</code> finds which occurs first and deletes it.
723 If none is found then returns empty string.
724 */
725 String removeLeadingChars(String str, String[] toRemove) {
726 int idx = Integer.MAX_VALUE;
727 for (String ch : toRemove) {
728 if (str.indexOf(ch) >= 0) {
729 idx = Math.min(str.indexOf(ch), idx);
730 }
731 }
732 idx = idx == Integer.MAX_VALUE ? -1 : idx;
733 return (idx < 0) ? "" : str.substring(idx);
734 }
735
736 protected boolean startsWithAnyOf(String str, String[] symbols) {
737 for (String sym : symbols) {
738 if (str.startsWith(sym)) {
739 return true;
740 }
741 }
742 return false;
743 }
744
745 protected void click(Wrap<? extends Control> control) {
746 Point p = control.getClickPoint();
747 control.mouse().move(p);
748 control.mouse().click();
749 }
750
751 protected void initContext() {
752 final Wrap<? extends TextInputControl> wrap = getScene().as(Parent.class, Node.class).lookup(TextInputControl.class).wrap();
753 wrap.as(Text.class).clear();
754 wrap.as(Text.class).type(SAMPLE_STRING);
755 wrap.keyboard().pushKey(KeyboardButtons.A, Utils.isMacOS() ? KeyboardModifiers.META_DOWN_MASK : KeyboardModifiers.CTRL_DOWN_MASK);
756 new GetAction() {
757 @Override
758 public void run(Object... os) throws Exception {
759 Clipboard.getSystemClipboard().clear();
760 }
761 }.dispatch(Root.ROOT.getEnvironment());
762 }
763
764 protected void checkState(final String menu, boolean disabled) {
765 Wrap<? extends Node> wrap = getMenuItem(menu);
766 MenuItem menu_item = ((MenuItem) wrap.getControl().getProperties().get(MenuItem.class));
767 assertEquals(menu_item.isDisable(), disabled);
768 }
769
770 protected void checkText(final Text text, final String str) {
771 getScene().waitState(new State() {
772 public Object reached() {
773 return text.text().contentEquals(str) ? true : null;
774 }
775 });
|