functional/ControlsTests/test/javafx/scene/control/test/combobox/ComboBoxTest.java

Print this page




  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.combobox;
  26 
  27 import client.test.ScreenshotCheck;
  28 import client.test.Smoke;
  29 import java.text.Format;
  30 import java.text.MessageFormat;
  31 import java.util.ArrayList;
  32 import java.util.EnumSet;
  33 import java.util.HashMap;
  34 import java.util.List;
  35 import java.util.Map;

  36 import javafx.collections.FXCollections;
  37 import javafx.collections.ObservableList;
  38 import javafx.commons.SortValidator;
  39 import javafx.event.Event;
  40 import javafx.event.EventHandler;
  41 import javafx.geometry.Orientation;
  42 import javafx.scene.Node;
  43 import javafx.scene.control.ComboBox;
  44 import javafx.scene.control.Label;
  45 import javafx.scene.control.ListCell;
  46 import javafx.scene.control.ListView;
  47 import javafx.scene.control.ScrollBar;
  48 import javafx.scene.control.TextField;
  49 import static javafx.scene.control.test.combobox.ComboBoxApp.*;
  50 import static javafx.scene.control.test.combobox.TestBase.ITER;
  51 import javafx.scene.control.test.combobox.TestBase.Properties;
  52 import static javafx.scene.control.test.combobox.TestBase.testedControl;
  53 import javafx.scene.control.test.util.PropertyTest;
  54 import javafx.scene.control.test.utils.CustomMultipleSelectionModel;
  55 import javafx.scene.control.test.utils.CustomStringConverter;
  56 import static javafx.scene.control.test.utils.CustomStringConverter.FROM_STRING_PREFIX;
  57 import static javafx.scene.control.test.utils.CustomStringConverter.TO_STRING_PREFIX;
  58 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType;
  59 import javafx.scene.shape.Polygon;
  60 import javafx.scene.shape.Rectangle;
  61 import javafx.util.Callback;
  62 import javafx.util.StringConverter;
  63 import javafx.util.converter.FormatStringConverter;

  64 import org.jemmy.action.GetAction;
  65 import org.jemmy.control.Wrap;
  66 import org.jemmy.fx.ByStyleClass;
  67 import org.jemmy.fx.ByText;
  68 import org.jemmy.fx.NodeWrap;
  69 import org.jemmy.fx.Root;
  70 import org.jemmy.fx.control.ChoiceBoxWrap;
  71 import org.jemmy.fx.control.ListItemWrap.ListItemByObjectLookup;
  72 import org.jemmy.input.AbstractScroll;
  73 import org.jemmy.interfaces.Keyboard.KeyboardButton;
  74 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  75 import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
  76 import org.jemmy.interfaces.Parent;
  77 import org.jemmy.interfaces.Selectable;
  78 import org.jemmy.interfaces.Text;
  79 import org.jemmy.lookup.Lookup;
  80 import org.jemmy.lookup.LookupCriteria;
  81 import org.jemmy.resources.StringComparePolicy;
  82 import org.jemmy.timing.State;
  83 import static org.junit.Assert.*;
  84 import org.junit.Test;
  85 import org.junit.runner.RunWith;
  86 import test.javaclient.shared.FilteredTestRunner;
  87 
  88 /**
  89  * @author Alexander Kirov
  90  *
  91  * Specification:
  92  * http://xdesign.us.oracle.com/projects/javaFX/fxcontrols-ue/specifications/combobox/combobox.html
  93  */
  94 @RunWith(FilteredTestRunner.class)
  95 public class ComboBoxTest extends TestBase {
  96 
  97     @ScreenshotCheck
  98     @Test(timeout = 300000)
  99     public void editablePropertyTest() throws Throwable {
 100         assertEquals((new ComboBox()).editableProperty().getValue(), false);
 101 
 102         testedControl.getEnvironment().setTimeout(Wrap.WAIT_STATE_TIMEOUT, 2000);
 103 
 104         for (SettingType btype : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) {
 105             for (int i = 0; i < 4; i++) {
 106                 setPropertyByToggleClick(btype, Properties.editable);
 107                 checkEditable(i % 2 == 0 ? true : false);
 108                 checkScreenshot("ComboBox_editable_[" + (i % 2 == 0 ? true : false) + "]", testedControl);
 109             }
 110         }
 111 
 112         throwScreenshotError();


 146         checkPopupShowing(true);
 147     }
 148 
 149     @Smoke
 150     @Test(timeout = 300000)
 151     public void armedTest() {
 152         assertEquals((new ComboBox()).armedProperty().getValue(), false);
 153 
 154         testedControl.mouse().move();
 155         testedControl.mouse().press();
 156 
 157         checkTextFieldText(Properties.armed, "true");
 158 
 159         testedControl.mouse().release();
 160 
 161         checkTextFieldText(Properties.armed, "false");
 162         checkTextFieldText(Properties.showing, "true");
 163 
 164         testedControl.mouse().press();
 165 
 166         checkTextFieldText(Properties.armed, "false");
 167         checkTextFieldText(Properties.showing, "false");
 168 
 169         testedControl.mouse().release();
 170 
 171         checkTextFieldText(Properties.armed, "false");
 172         checkTextFieldText(Properties.showing, "false");






 173     }
 174 
 175     @Smoke
 176     @Test(timeout = 300000)//RT-18945
 177     public void valuePropertyTest() throws InterruptedException {
 178         assertEquals((new ComboBox()).getValue(), null);
 179 
 180         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 181 
 182         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.value, NEW_VALUE_1);
 183         checkTextFieldText(Properties.value, NEW_VALUE_1);
 184         assertEquals(getTextFieldText(), NEW_VALUE_1);
 185 
 186         setPropertyByTextField(SettingType.UNIDIRECTIONAL, Properties.value, NEW_VALUE_2);
 187         checkTextFieldText(Properties.value, NEW_VALUE_2);
 188         assertEquals(getTextFieldText(), NEW_VALUE_2);
 189 
 190         setPropertyByTextField(SettingType.SETTER, Properties.value, NEW_VALUE_1);
 191         checkTextFieldText(Properties.value, NEW_VALUE_1);
 192         assertEquals(getTextFieldText(), NEW_VALUE_1);


 202             assertEquals(getValue(), String.valueOf(i));
 203         }
 204 
 205         testedControl.as(Selectable.class).selector().select(String.valueOf(ITER - 1));
 206 
 207         //Do some actions to change state of control and verify value
 208         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 209         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 210         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.promptText, "some text");
 211         clickDropDownButton();
 212         applyCustomSelectionModel();
 213         applyCustomStringConverter();
 214 
 215         assertEquals(getValue().toString(), "null");
 216         assertEquals(getTextFieldText(), "");
 217     }
 218 
 219     @ScreenshotCheck
 220     @Test(timeout = 300000)//RT-19225
 221     public void promptPropertyTest() throws Throwable {
 222         assertEquals((new ComboBox()).promptTextProperty().getValue(), "");
 223 
 224         //move focus from control. otherwise, we will not see prompt.
 225         requestFocusOnControl(testedControl);
 226         testedControl.keyboard().pushKey(KeyboardButtons.TAB);
 227 
 228         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 229 
 230         for (SettingType btype : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) {
 231             setPropertyByTextField(btype, Properties.promptText, btype.name());
 232             checkTextFieldText(Properties.promptText, btype.name());
 233             assertEquals(btype.name(), getTextFieldPrompt());
 234             checkScreenshot("ComboBox_PromptText_[" + btype.name() + "]", testedControl);
 235         }
 236         throwScreenshotError();
 237     }
 238 
 239     @ScreenshotCheck
 240     @Test(timeout = 300000)
 241     public void visibleRowCountPropertyTest() throws InterruptedException, Throwable {
 242         assertEquals((long) (new ComboBox()).visibleRowCountProperty().getValue(), 10);


 318         String element2 = "Random element 2";
 319         addElement(element2, 1);
 320         testedControl.as(Selectable.class).selector().select(element2);
 321         checkSimpleListenerValue(Properties.selectedItem, element2);
 322         assertEquals(getTextFieldText(), element2);
 323 
 324         applyCustomStringConverter();
 325 
 326         assertTrue(new GetAction<Object>() {
 327             @Override
 328             public void run(Object... os) throws Exception {
 329                 setResult(((ComboBox) os[0]).converterProperty().getValue());
 330             }
 331         }.dispatch(Root.ROOT.getEnvironment(),
 332                 testedControl.getControl()) instanceof CustomStringConverter);
 333 
 334         String element3 = "Random element 3";
 335         addElement(element3, 2);
 336         testedControl.as(Selectable.class).selector().select(element3);
 337         checkSimpleListenerValue(Properties.selectedItem, element3);
 338         assertEquals(getTextFieldText(), TO_STRING_PREFIX + "1");
 339 
 340         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 341         testedControl.as(Selectable.class).selector().select(element2);
 342         checkSimpleListenerValue(Properties.selectedItem, element2);
 343     }
 344 
 345     @Smoke
 346     @Test(timeout = 300000)
 347     public void itemsPropertyTest() throws InterruptedException {
 348         assertNotSame((new ComboBox()).getItems(), null);
 349         assertTrue((new ComboBox()).getItems() instanceof ObservableList);
 350 
 351         checkListsEquality();
 352         for (int i = 0; i < 5; i++) {
 353             for (int j = 0; j < 5; j++) {
 354                 addElement(String.valueOf(j), j);
 355                 checkListsEquality();
 356             }
 357 
 358             for (int j = 0; j < 5; j++) {


 406 
 407         addElements(1, 2, 3);
 408         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 0);
 409         testedControl.mouse().click();
 410         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 0);
 411         testedControl.as(Selectable.class).selector().select("2");
 412         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 1);
 413         testedControl.keyboard().pushKey(KeyboardButtons.UP);
 414         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 2);
 415         testedControl.keyboard().pushKey(KeyboardButtons.DOWN);
 416         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 3);
 417         testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK);
 418         testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK);
 419         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 3);
 420         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 421 
 422         testedControl.mouse().click();
 423         testedControl.mouse().click();
 424 
 425         testedControl.keyboard().pushKey(KeyboardButtons.A);
 426         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 4);
 427         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
 428         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 5);
 429         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.value, NEW_VALUE_1);
 430         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 7);
 431         setPropertyByTextField(SettingType.UNIDIRECTIONAL, Properties.value, NEW_VALUE_2);
 432         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 9);
 433     }
 434 
 435     @Smoke
 436     @Test(timeout = 300000)//RT-19227
 437     public void selectionTest() throws InterruptedException, Exception {
 438         final int number = 10;
 439         for (int i = 0; i < number; i++) {
 440             addElement(String.valueOf(i), i);
 441         }
 442         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 4);
 443 
 444         for (int i = 0; i < number * 2; i++) {
 445             testedControl.as(Selectable.class).selector().select(String.valueOf(i % number));
 446             try {
 447                 checkSelectionState(i % number, i % number);
 448             } catch (Exception e) {
 449                 System.out.println("Exception was thrown on step " + i);
 450                 throw e;
 451             }
 452         }


 624         testedControl.mouse().click();
 625         checkTextFieldText(Properties.showing, "true");
 626         testedControl.mouse().click();
 627         checkTextFieldText(Properties.showing, "false");
 628 
 629         //drop down button test
 630         clickDropDownButton();
 631         checkTextFieldText(Properties.showing, "true");
 632         clickDropDownButton();
 633         checkTextFieldText(Properties.showing, "false");
 634 
 635         //select test
 636         addElement("0", 0);
 637         testedControl.as(Selectable.class).selector().select("0");
 638         assertEquals("0", getCurrentValue());
 639 
 640         //scrollbar interaction test
 641         addElements(1, 2, 3, 4, 5, 6);
 642         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 5);
 643         clickDropDownButton();
 644         Wrap<? extends ScrollBar> sb = findScrollBar(((Wrap<? extends ListView>) getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap()).as(Parent.class, Node.class), Orientation.VERTICAL, true);


 645         sb.as(AbstractScroll.class).caret().to(1);
 646         checkTextFieldText(Properties.showing, "true");
 647         testedControl.as(Selectable.class).selector().select("6");
 648         checkTextFieldText(Properties.showing, "false");
 649 
 650         //selection in editable state
 651         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 652         requestFocusOnControl(testedControl);
 653         testedControl.as(Text.class).type("a");
 654         assertEquals(getTextFieldText(), "a");
 655 
 656         //drop down in editable state
 657         clickDropDownButton();
 658         testedControl.as(Selectable.class).selector().select("3");
 659         checkTextFieldText(Properties.value, "3");
 660     }
 661 
 662     @ScreenshotCheck
 663     @Smoke
 664     @Test(timeout = 300000)//RT-19227


 682         clickDropDownButton();
 683         checkScreenshot("ComboBox_combobox_noneditable[6_is_selected]", testedControl);
 684         Wrap wrap = getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap();
 685 
 686         checkScreenshot("ComboBox_popup_noneditable[6_is_selected]", wrap);
 687         throwScreenshotError();
 688     }
 689 
 690     @ScreenshotCheck
 691     @Smoke
 692     @Test(timeout = 300000)
 693     public void commonEditableTest() throws InterruptedException, Throwable {
 694         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 695         addElements(1, 2, 3, 4, 5, 6);
 696         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 4);
 697 
 698         testedControl.as(Selectable.class).selector().select("6");
 699         checkSelectionState(5, 6);
 700         assertEquals(getTextFieldText(), "6");
 701         checkTextFieldText(Properties.value, "6");

 702 
 703         testedControl.mouse().click();
 704         testedControl.as(Text.class).type("abc");
 705         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
 706 
 707         checkSimpleListenerValue(Properties.selectedIndex, 5);
 708         checkSimpleListenerValue(Properties.selectedItem, "6abc");
 709         checkTextFieldText(Properties.value, "6abc");
 710 
 711         clickDropDownButton();
 712 
 713         checkScreenshot("ComboBox_combobox_editable", testedControl);
 714         checkScreenshot("ComboBox_popup_editable", getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap());
 715         throwScreenshotError();
 716     }
 717 
 718     @ScreenshotCheck
 719     @Test(timeout = 300000)
 720     public void initialAndFinalSizeTest() throws Throwable {
 721         String commonScreenShotName = "ComboBox_initial";
 722         //checkScreenshot(commonScreenShotName, testedControl);//Removed, as size of empty is different.
 723 
 724         int size = 10;
 725         for (int i = 0; i < size; i++) {
 726             addElement(String.valueOf(i), i);
 727             checkScreenshot(commonScreenShotName, testedControl);


1256     /**
1257      * Test different cell rendering of ComboBox button and list (pop up) Button
1258      * height must remain the same. Height of cells of ComboBox must increase.
1259      *
1260      * http://javafx-jira.kenai.com/browse/RT-24528
1261      */
1262     @Smoke
1263     @Test(timeout = 300000)
1264     public void testCellRenderingHeight() throws Throwable {
1265 
1266         clickButtonForTestPurpose(POPULATE_COMBOBOX_WITH_FONT_SIZES);
1267 
1268         for (boolean isEditable : new boolean[]{false, true}) {
1269 
1270             if (!isEditable) {
1271                 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable, false);
1272             } else {
1273                 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable);
1274             }
1275 
1276             Wrap<? extends javafx.scene.text.Text> textFieldWrap = testedControl.as(Parent.class, Node.class)
1277                     .lookup(javafx.scene.text.Text.class).wrap();
1278             final double initialButtonHeight = testedControl.getScreenBounds().getHeight();
1279             double prevCellTextHeight = 0f;
1280 
1281             for (int fontSize = INITIAL_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize += 2) {
1282                 String testVal = String.valueOf(fontSize);
1283 
1284                 testedControl.as(Selectable.class).selector().select(String.valueOf(fontSize));
1285 
1286                 /* check heighgt of the button */
1287                 assertEquals(initialButtonHeight, testedControl.getScreenBounds().getHeight(), 0.001);
1288 
1289                 /* text node should be alwas rendered inside ComboBox button */


1290                 assertTrue(textFieldWrap.getScreenBounds().getY() >= testedControl.getScreenBounds().getY());
1291                 assertTrue(textFieldWrap.getScreenBounds().getY() + textFieldWrap.getScreenBounds().getHeight()
1292                         <= testedControl.getScreenBounds().getY() + testedControl.getScreenBounds().getHeight());
1293 
1294                 /* get wraps of cell and cell text node to compare coordinates */
1295                 clickDropDownButton();
1296 
1297                 Wrap<? extends ListView> listWrap = getPopupWrap().as(Parent.class, Node.class)
1298                         .lookup(ListView.class).wrap();
1299 
1300                 Wrap<? extends ListCell> cellWrap = listWrap.as(Parent.class, Node.class)
1301                         .lookup(ListCell.class, new ByText(testVal, StringComparePolicy.EXACT)).wrap();
1302 
1303                 Wrap<? extends javafx.scene.text.Text> cellTextWrap = cellWrap.as(Parent.class, Node.class)
1304                         .lookup(javafx.scene.text.Text.class).wrap();
1305 
1306                 /* cell text should be always inside cell */
1307                 assertTrue(cellTextWrap.getScreenBounds().getY() >= cellWrap.getScreenBounds().getY());
1308                 assertTrue(cellWrap.getScreenBounds().getY() + cellWrap.getScreenBounds().getHeight()
1309                         >= cellTextWrap.getScreenBounds().getY() + cellTextWrap.getScreenBounds().getHeight());


1405     }
1406 
1407     /**
1408      * This test checks that a custom string converter fromString() method is
1409      * called only once when some value is entered in the editable ComboBox
1410      */
1411     @Smoke
1412     @Test(timeout = 300000)
1413     public void testStringConvertersFromStringMethod() throws InterruptedException {
1414         setPropertyBySlider(SettingType.SETTER, Properties.prefWidth, 150);
1415 
1416         applyCustomStringConverter();
1417 
1418         setPropertyByToggleClick(SettingType.SETTER, Properties.editable, true);
1419 
1420         final String testString = "test";
1421         setPropertyByTextField(SettingType.SETTER, Properties.text, testString);
1422 
1423         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
1424 
1425         checkTextFieldText(Properties.value, FROM_STRING_PREFIX + "1");
1426     }
1427 
1428     /**
1429      * Tests format string converter and checks that transformation is performed
1430      * properly
1431      */
1432     @Smoke
1433     @Test(timeout = 300000)
1434     public void testFormatStringConverter() throws InterruptedException {
1435         setPropertyBySlider(SettingType.SETTER, Properties.prefWidth, 150);
1436 
1437         int itemsCount = 3;
1438         String prefix = "value #";
1439 
1440         final List<String> testedValues = new ArrayList<String>(itemsCount);
1441         for (int i = 0; i < itemsCount; i++) {
1442             testedValues.add(prefix + i);
1443         }
1444 
1445         final String pattern = "Before text. {0} After text.";




  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.combobox;
  26 
  27 import client.test.ScreenshotCheck;
  28 import client.test.Smoke;
  29 import java.text.Format;
  30 import java.text.MessageFormat;
  31 import java.util.ArrayList;
  32 import java.util.EnumSet;
  33 import java.util.HashMap;
  34 import java.util.List;
  35 import java.util.Map;
  36 import javafx.beans.value.ObservableValue;
  37 import javafx.collections.FXCollections;
  38 import javafx.collections.ObservableList;
  39 import javafx.commons.SortValidator;
  40 import javafx.event.Event;
  41 import javafx.event.EventHandler;
  42 import javafx.geometry.Orientation;
  43 import javafx.scene.Node;
  44 import javafx.scene.control.ComboBox;
  45 import javafx.scene.control.Label;
  46 import javafx.scene.control.ListCell;
  47 import javafx.scene.control.ListView;
  48 import javafx.scene.control.ScrollBar;
  49 import javafx.scene.control.TextField;
  50 import static javafx.scene.control.test.combobox.ComboBoxApp.*;
  51 import static javafx.scene.control.test.combobox.TestBase.ITER;
  52 import javafx.scene.control.test.combobox.TestBase.Properties;
  53 import static javafx.scene.control.test.combobox.TestBase.testedControl;
  54 import javafx.scene.control.test.util.PropertyTest;
  55 import javafx.scene.control.test.utils.CustomMultipleSelectionModel;
  56 import javafx.scene.control.test.utils.CustomStringConverter;
  57 import static javafx.scene.control.test.utils.CustomStringConverter.FROM_STRING_PREFIX;
  58 import static javafx.scene.control.test.utils.CustomStringConverter.TO_STRING_PREFIX;
  59 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType;
  60 import javafx.scene.shape.Polygon;
  61 import javafx.scene.shape.Rectangle;
  62 import javafx.util.Callback;
  63 import javafx.util.StringConverter;
  64 import javafx.util.converter.FormatStringConverter;
  65 import org.jemmy.Point;
  66 import org.jemmy.action.GetAction;
  67 import org.jemmy.control.Wrap;
  68 import org.jemmy.fx.ByStyleClass;
  69 import org.jemmy.fx.ByText;
  70 import org.jemmy.fx.NodeWrap;
  71 import org.jemmy.fx.Root;
  72 import org.jemmy.fx.control.ChoiceBoxWrap;
  73 import org.jemmy.fx.control.ListItemWrap.ListItemByObjectLookup;
  74 import org.jemmy.input.AbstractScroll;
  75 import org.jemmy.interfaces.Keyboard.KeyboardButton;
  76 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  77 import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
  78 import org.jemmy.interfaces.Parent;
  79 import org.jemmy.interfaces.Selectable;
  80 import org.jemmy.interfaces.Text;
  81 import org.jemmy.lookup.Lookup;
  82 import org.jemmy.lookup.LookupCriteria;
  83 import org.jemmy.resources.StringComparePolicy;
  84 import org.jemmy.timing.State;
  85 import static org.junit.Assert.*;
  86 import org.junit.Test;
  87 import org.junit.runner.RunWith;
  88 import test.javaclient.shared.FilteredTestRunner;
  89 
  90 /**
  91  * @author Alexander Kirov
  92  *


  93  */
  94 @RunWith(FilteredTestRunner.class)
  95 public class ComboBoxTest extends TestBase {
  96 
  97     @ScreenshotCheck
  98     @Test(timeout = 300000)
  99     public void editablePropertyTest() throws Throwable {
 100         assertEquals((new ComboBox()).editableProperty().getValue(), false);
 101 
 102         testedControl.getEnvironment().setTimeout(Wrap.WAIT_STATE_TIMEOUT, 2000);
 103 
 104         for (SettingType btype : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) {
 105             for (int i = 0; i < 4; i++) {
 106                 setPropertyByToggleClick(btype, Properties.editable);
 107                 checkEditable(i % 2 == 0 ? true : false);
 108                 checkScreenshot("ComboBox_editable_[" + (i % 2 == 0 ? true : false) + "]", testedControl);
 109             }
 110         }
 111 
 112         throwScreenshotError();


 146         checkPopupShowing(true);
 147     }
 148 
 149     @Smoke
 150     @Test(timeout = 300000)
 151     public void armedTest() {
 152         assertEquals((new ComboBox()).armedProperty().getValue(), false);
 153 
 154         testedControl.mouse().move();
 155         testedControl.mouse().press();
 156 
 157         checkTextFieldText(Properties.armed, "true");
 158 
 159         testedControl.mouse().release();
 160 
 161         checkTextFieldText(Properties.armed, "false");
 162         checkTextFieldText(Properties.showing, "true");
 163 
 164         testedControl.mouse().press();
 165 
 166         checkTextFieldText(Properties.armed, "true");
 167         checkTextFieldText(Properties.showing, "false");
 168 
 169         testedControl.mouse().release();
 170 
 171         checkTextFieldText(Properties.armed, "false");
 172         checkTextFieldText(Properties.showing, "false");
 173 
 174         testedControl.mouse().press();
 175         org.jemmy.Rectangle bounds = testedControl.getScreenBounds();
 176         testedControl.mouse().move(new Point(bounds.getWidth() + 5, testedControl.getScreenBounds().getHeight() + 5));
 177 
 178         checkTextFieldText(Properties.armed, "false");
 179     }
 180 
 181     @Smoke
 182     @Test(timeout = 300000)//RT-18945
 183     public void valuePropertyTest() throws InterruptedException {
 184         assertEquals((new ComboBox()).getValue(), null);
 185 
 186         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 187 
 188         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.value, NEW_VALUE_1);
 189         checkTextFieldText(Properties.value, NEW_VALUE_1);
 190         assertEquals(getTextFieldText(), NEW_VALUE_1);
 191 
 192         setPropertyByTextField(SettingType.UNIDIRECTIONAL, Properties.value, NEW_VALUE_2);
 193         checkTextFieldText(Properties.value, NEW_VALUE_2);
 194         assertEquals(getTextFieldText(), NEW_VALUE_2);
 195 
 196         setPropertyByTextField(SettingType.SETTER, Properties.value, NEW_VALUE_1);
 197         checkTextFieldText(Properties.value, NEW_VALUE_1);
 198         assertEquals(getTextFieldText(), NEW_VALUE_1);


 208             assertEquals(getValue(), String.valueOf(i));
 209         }
 210 
 211         testedControl.as(Selectable.class).selector().select(String.valueOf(ITER - 1));
 212 
 213         //Do some actions to change state of control and verify value
 214         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 215         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 216         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.promptText, "some text");
 217         clickDropDownButton();
 218         applyCustomSelectionModel();
 219         applyCustomStringConverter();
 220 
 221         assertEquals(getValue().toString(), "null");
 222         assertEquals(getTextFieldText(), "");
 223     }
 224 
 225     @ScreenshotCheck
 226     @Test(timeout = 300000)//RT-19225
 227     public void promptPropertyTest() throws Throwable {
 228         assertEquals((new ComboBox()).promptTextProperty().getValue(), null);
 229 
 230         //move focus from control. otherwise, we will not see prompt.
 231         requestFocusOnControl(testedControl);
 232         testedControl.keyboard().pushKey(KeyboardButtons.TAB);
 233 
 234         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 235 
 236         for (SettingType btype : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) {
 237             setPropertyByTextField(btype, Properties.promptText, btype.name());
 238             checkTextFieldText(Properties.promptText, btype.name());
 239             assertEquals(btype.name(), getTextFieldPrompt());
 240             checkScreenshot("ComboBox_PromptText_[" + btype.name() + "]", testedControl);
 241         }
 242         throwScreenshotError();
 243     }
 244 
 245     @ScreenshotCheck
 246     @Test(timeout = 300000)
 247     public void visibleRowCountPropertyTest() throws InterruptedException, Throwable {
 248         assertEquals((long) (new ComboBox()).visibleRowCountProperty().getValue(), 10);


 324         String element2 = "Random element 2";
 325         addElement(element2, 1);
 326         testedControl.as(Selectable.class).selector().select(element2);
 327         checkSimpleListenerValue(Properties.selectedItem, element2);
 328         assertEquals(getTextFieldText(), element2);
 329 
 330         applyCustomStringConverter();
 331 
 332         assertTrue(new GetAction<Object>() {
 333             @Override
 334             public void run(Object... os) throws Exception {
 335                 setResult(((ComboBox) os[0]).converterProperty().getValue());
 336             }
 337         }.dispatch(Root.ROOT.getEnvironment(),
 338                 testedControl.getControl()) instanceof CustomStringConverter);
 339 
 340         String element3 = "Random element 3";
 341         addElement(element3, 2);
 342         testedControl.as(Selectable.class).selector().select(element3);
 343         checkSimpleListenerValue(Properties.selectedItem, element3);
 344         assertEquals(getTextFieldText(), TO_STRING_PREFIX + "3");
 345 
 346         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 347         testedControl.as(Selectable.class).selector().select(element2);
 348         checkSimpleListenerValue(Properties.selectedItem, element2);
 349     }
 350 
 351     @Smoke
 352     @Test(timeout = 300000)
 353     public void itemsPropertyTest() throws InterruptedException {
 354         assertNotSame((new ComboBox()).getItems(), null);
 355         assertTrue((new ComboBox()).getItems() instanceof ObservableList);
 356 
 357         checkListsEquality();
 358         for (int i = 0; i < 5; i++) {
 359             for (int j = 0; j < 5; j++) {
 360                 addElement(String.valueOf(j), j);
 361                 checkListsEquality();
 362             }
 363 
 364             for (int j = 0; j < 5; j++) {


 412 
 413         addElements(1, 2, 3);
 414         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 0);
 415         testedControl.mouse().click();
 416         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 0);
 417         testedControl.as(Selectable.class).selector().select("2");
 418         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 1);
 419         testedControl.keyboard().pushKey(KeyboardButtons.UP);
 420         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 2);
 421         testedControl.keyboard().pushKey(KeyboardButtons.DOWN);
 422         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 3);
 423         testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK);
 424         testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK);
 425         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 3);
 426         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 427 
 428         testedControl.mouse().click();
 429         testedControl.mouse().click();
 430 
 431         testedControl.keyboard().pushKey(KeyboardButtons.A);
 432         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 3);
 433         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
 434         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 4);
 435         setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.value, NEW_VALUE_1);
 436         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 6);
 437         setPropertyByTextField(SettingType.UNIDIRECTIONAL, Properties.value, NEW_VALUE_2);
 438         checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 8);
 439     }
 440 
 441     @Smoke
 442     @Test(timeout = 300000)//RT-19227
 443     public void selectionTest() throws InterruptedException, Exception {
 444         final int number = 10;
 445         for (int i = 0; i < number; i++) {
 446             addElement(String.valueOf(i), i);
 447         }
 448         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 4);
 449 
 450         for (int i = 0; i < number * 2; i++) {
 451             testedControl.as(Selectable.class).selector().select(String.valueOf(i % number));
 452             try {
 453                 checkSelectionState(i % number, i % number);
 454             } catch (Exception e) {
 455                 System.out.println("Exception was thrown on step " + i);
 456                 throw e;
 457             }
 458         }


 630         testedControl.mouse().click();
 631         checkTextFieldText(Properties.showing, "true");
 632         testedControl.mouse().click();
 633         checkTextFieldText(Properties.showing, "false");
 634 
 635         //drop down button test
 636         clickDropDownButton();
 637         checkTextFieldText(Properties.showing, "true");
 638         clickDropDownButton();
 639         checkTextFieldText(Properties.showing, "false");
 640 
 641         //select test
 642         addElement("0", 0);
 643         testedControl.as(Selectable.class).selector().select("0");
 644         assertEquals("0", getCurrentValue());
 645 
 646         //scrollbar interaction test
 647         addElements(1, 2, 3, 4, 5, 6);
 648         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 5);
 649         clickDropDownButton();
 650         Wrap<? extends ScrollBar> sb = findScrollBar(
 651                 ((Parent<Node>) ((Wrap<? extends ListView>) ((Parent<Node>) getPopupWrap().as(Parent.class, Node.class))
 652                 .lookup(ListView.class).wrap()).as(Parent.class, Node.class)), Orientation.VERTICAL, true);
 653         sb.as(AbstractScroll.class).caret().to(1);
 654         checkTextFieldText(Properties.showing, "true");
 655         testedControl.as(Selectable.class).selector().select("6");
 656         checkTextFieldText(Properties.showing, "false");
 657 
 658         //selection in editable state
 659         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 660         requestFocusOnControl(testedControl);
 661         testedControl.as(Text.class).type("a");
 662         assertEquals(getTextFieldText(), "a");
 663 
 664         //drop down in editable state
 665         clickDropDownButton();
 666         testedControl.as(Selectable.class).selector().select("3");
 667         checkTextFieldText(Properties.value, "3");
 668     }
 669 
 670     @ScreenshotCheck
 671     @Smoke
 672     @Test(timeout = 300000)//RT-19227


 690         clickDropDownButton();
 691         checkScreenshot("ComboBox_combobox_noneditable[6_is_selected]", testedControl);
 692         Wrap wrap = getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap();
 693 
 694         checkScreenshot("ComboBox_popup_noneditable[6_is_selected]", wrap);
 695         throwScreenshotError();
 696     }
 697 
 698     @ScreenshotCheck
 699     @Smoke
 700     @Test(timeout = 300000)
 701     public void commonEditableTest() throws InterruptedException, Throwable {
 702         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable);
 703         addElements(1, 2, 3, 4, 5, 6);
 704         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 4);
 705 
 706         testedControl.as(Selectable.class).selector().select("6");
 707         checkSelectionState(5, 6);
 708         assertEquals(getTextFieldText(), "6");
 709         checkTextFieldText(Properties.value, "6");
 710         checkSimpleListenerValue(Properties.selectedIndex, 5);
 711 
 712         testedControl.mouse().click();
 713         testedControl.as(Text.class).type("abc");
 714         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
 715 

 716         checkSimpleListenerValue(Properties.selectedItem, "6abc");
 717         checkTextFieldText(Properties.value, "6abc");
 718 
 719         clickDropDownButton();
 720 
 721         checkScreenshot("ComboBox_combobox_editable", testedControl);
 722         checkScreenshot("ComboBox_popup_editable", getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap());
 723         throwScreenshotError();
 724     }
 725 
 726     @ScreenshotCheck
 727     @Test(timeout = 300000)
 728     public void initialAndFinalSizeTest() throws Throwable {
 729         String commonScreenShotName = "ComboBox_initial";
 730         //checkScreenshot(commonScreenShotName, testedControl);//Removed, as size of empty is different.
 731 
 732         int size = 10;
 733         for (int i = 0; i < size; i++) {
 734             addElement(String.valueOf(i), i);
 735             checkScreenshot(commonScreenShotName, testedControl);


1264     /**
1265      * Test different cell rendering of ComboBox button and list (pop up) Button
1266      * height must remain the same. Height of cells of ComboBox must increase.
1267      *
1268      * http://javafx-jira.kenai.com/browse/RT-24528
1269      */
1270     @Smoke
1271     @Test(timeout = 300000)
1272     public void testCellRenderingHeight() throws Throwable {
1273 
1274         clickButtonForTestPurpose(POPULATE_COMBOBOX_WITH_FONT_SIZES);
1275 
1276         for (boolean isEditable : new boolean[]{false, true}) {
1277 
1278             if (!isEditable) {
1279                 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable, false);
1280             } else {
1281                 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable);
1282             }
1283 


1284             final double initialButtonHeight = testedControl.getScreenBounds().getHeight();
1285             double prevCellTextHeight = 0f;
1286 
1287             for (int fontSize = INITIAL_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize += 2) {
1288                 String testVal = String.valueOf(fontSize);
1289 
1290                 testedControl.as(Selectable.class).selector().select(String.valueOf(fontSize));
1291 
1292                 /* check heighgt of the button */
1293                 assertEquals(initialButtonHeight, testedControl.getScreenBounds().getHeight(), 0.001);
1294 
1295                 /* text node should be alwas rendered inside ComboBox button */
1296                 Wrap<? extends javafx.scene.text.Text> textFieldWrap = testedControl.as(Parent.class, Node.class)
1297                     .lookup(javafx.scene.text.Text.class).wrap();
1298                 assertTrue(textFieldWrap.getScreenBounds().getY() >= testedControl.getScreenBounds().getY());
1299                 assertTrue(textFieldWrap.getScreenBounds().getY() + textFieldWrap.getScreenBounds().getHeight()
1300                         <= testedControl.getScreenBounds().getY() + testedControl.getScreenBounds().getHeight());
1301 
1302                 /* get wraps of cell and cell text node to compare coordinates */
1303                 clickDropDownButton();
1304 
1305                 Wrap<? extends ListView> listWrap = getPopupWrap().as(Parent.class, Node.class)
1306                         .lookup(ListView.class).wrap();
1307 
1308                 Wrap<? extends ListCell> cellWrap = listWrap.as(Parent.class, Node.class)
1309                         .lookup(ListCell.class, new ByText(testVal, StringComparePolicy.EXACT)).wrap();
1310 
1311                 Wrap<? extends javafx.scene.text.Text> cellTextWrap = cellWrap.as(Parent.class, Node.class)
1312                         .lookup(javafx.scene.text.Text.class).wrap();
1313 
1314                 /* cell text should be always inside cell */
1315                 assertTrue(cellTextWrap.getScreenBounds().getY() >= cellWrap.getScreenBounds().getY());
1316                 assertTrue(cellWrap.getScreenBounds().getY() + cellWrap.getScreenBounds().getHeight()
1317                         >= cellTextWrap.getScreenBounds().getY() + cellTextWrap.getScreenBounds().getHeight());


1413     }
1414 
1415     /**
1416      * This test checks that a custom string converter fromString() method is
1417      * called only once when some value is entered in the editable ComboBox
1418      */
1419     @Smoke
1420     @Test(timeout = 300000)
1421     public void testStringConvertersFromStringMethod() throws InterruptedException {
1422         setPropertyBySlider(SettingType.SETTER, Properties.prefWidth, 150);
1423 
1424         applyCustomStringConverter();
1425 
1426         setPropertyByToggleClick(SettingType.SETTER, Properties.editable, true);
1427 
1428         final String testString = "test";
1429         setPropertyByTextField(SettingType.SETTER, Properties.text, testString);
1430 
1431         testedControl.keyboard().pushKey(KeyboardButtons.ENTER);
1432 
1433         checkTextFieldText(Properties.value, FROM_STRING_PREFIX);
1434     }
1435 
1436     /**
1437      * Tests format string converter and checks that transformation is performed
1438      * properly
1439      */
1440     @Smoke
1441     @Test(timeout = 300000)
1442     public void testFormatStringConverter() throws InterruptedException {
1443         setPropertyBySlider(SettingType.SETTER, Properties.prefWidth, 150);
1444 
1445         int itemsCount = 3;
1446         String prefix = "value #";
1447 
1448         final List<String> testedValues = new ArrayList<String>(itemsCount);
1449         for (int i = 0; i < itemsCount; i++) {
1450             testedValues.add(prefix + i);
1451         }
1452 
1453         final String pattern = "Before text. {0} After text.";