1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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.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(); 113 } 114 115 @Smoke 116 @Test(timeout = 300000) 117 public void showingPropertyTest() throws InterruptedException { 118 assertEquals((new ComboBox()).showingProperty().getValue(), false); 119 120 clickDropDownButton(); 121 checkPopupShowing(true); 122 clickDropDownButton(); 123 checkPopupShowing(false); 124 testedControl.mouse().click(); 125 checkPopupShowing(true); 126 checkButtonForPopupShowing(KeyboardButtons.F4); 127 checkButtonForPopupShowing(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK); 128 checkButtonForPopupShowing(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK); 129 130 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 131 //We switched property and need to wait, until it will be applied, to click on buttons. 132 Thread.sleep(1000); 133 134 testedControl.mouse().click(); 135 checkPopupShowing(false); 136 clickDropDownButton(); 137 checkPopupShowing(true); 138 clickDropDownButton(); 139 checkPopupShowing(false); 140 } 141 142 private void checkButtonForPopupShowing(KeyboardButtons button, KeyboardModifiers... mdfs) throws InterruptedException { 143 testedControl.keyboard().pushKey(button, mdfs); 144 checkPopupShowing(false); 145 testedControl.keyboard().pushKey(button, mdfs); 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); 193 194 switchOffBinding(SettingType.UNIDIRECTIONAL, Properties.value); 195 196 for (int i = 0; i < ITER; i++) { 197 addElement(String.valueOf(i), i); 198 } 199 200 for (int i = 0; i < ITER; i++) { 201 testedControl.as(Selectable.class).selector().select(String.valueOf(i)); 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); 243 244 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 6); 245 checkTextFieldValue(Properties.visibleRowCount, 6); 246 247 addElements(1, 2, 3, 4, 5, 6, 7); 248 249 clickDropDownButton(); 250 checkScrollBarVisibility(true); 251 252 Wrap<? extends ListView> list = getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap(); 253 Wrap<? extends ListCell> cell = list.as(Parent.class, Node.class).lookup(ListCell.class, new ListItemByObjectLookup<String>("1")).wrap(); 254 assertEquals(cell.getScreenBounds().getHeight() * 6, list.getScreenBounds().getHeight(), 4); 255 256 removeFromPos(2); 257 258 clickDropDownButton(); 259 checkScrollBarVisibility(false); 260 261 setPropertyBySlider(SettingType.SETTER, Properties.visibleRowCount, 5); 262 checkTextFieldValue(Properties.visibleRowCount, 5); 263 264 clickDropDownButton(); 265 checkScrollBarVisibility(true); 266 removeFromPos(5); 267 268 setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.visibleRowCount, 4); 269 checkTextFieldValue(Properties.visibleRowCount, 4); 270 271 testedControl.as(Selectable.class).selector().select("2"); 272 273 clickDropDownButton(); 274 checkScrollBarVisibility(true); 275 276 checkScreenshot("ComboBox_visibleRowCount_4_visible_and_5_elements_and_3_removed", getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap()); 277 throwScreenshotError(); 278 } 279 280 @ScreenshotCheck 281 @Test(timeout = 300000) 282 public void emptyDropDownScreenshotTest() throws InterruptedException, Throwable { 283 clickDropDownButton(); 284 checkPopupShowing(true); 285 checkScreenshot("ComboBox_emptyDropDown", getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap()); 286 throwScreenshotError(); 287 } 288 289 @Smoke 290 @Test(timeout = 300000) 291 public void converterPropertyTest() throws InterruptedException { 292 assertNotSame((new ComboBox()).getConverter(), null); 293 294 assertTrue(new GetAction<Object>() { 295 @Override 296 public void run(Object... os) throws Exception { 297 setResult(((ComboBox) os[0]).getConverter()); 298 } 299 }.dispatch(Root.ROOT.getEnvironment(), 300 testedControl.getControl()) instanceof StringConverter); 301 302 String element = "Random element 1"; 303 addElement(element, 0); 304 305 testedControl.as(Selectable.class).selector().select(element); 306 checkSimpleListenerValue(Properties.selectedItem, element); 307 308 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 309 310 assertTrue(new GetAction<Object>() { 311 @Override 312 public void run(Object... os) throws Exception { 313 setResult(((ComboBox) os[0]).getConverter()); 314 } 315 }.dispatch(Root.ROOT.getEnvironment(), 316 testedControl.getControl()) instanceof StringConverter); 317 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++) { 359 removeFromPos(0); 360 checkListsEquality(); 361 } 362 } 363 364 } 365 366 private void checkListsEquality() throws InterruptedException { 367 //Equality: both are lists, size are equal, elements each by each are equal 368 if (!testedControl.getProperty(Boolean.class, ChoiceBoxWrap.IS_SHOWING_PROP_NAME)) { 369 clickDropDownButton(); 370 } 371 assertEquals(((ListView) getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap().getControl()).getItems(), ((ComboBox) testedControl.getControl()).getItems()); 372 } 373 374 //Test//Jonathan said, that there is no support for multiple 375 // selection model now. So I'll wait until he will write it and check my 376 // customMultipleSelection model class. So to write test now is impossible. 377 public void customMultipleSelectionModelTest() throws InterruptedException { 378 assertNotSame((new ComboBox()).getItems(), null); 379 380 clickDropDownButton(); 381 382 applyCustomSelectionModel(); 383 clickDropDownButton(); 384 385 assertTrue(new GetAction<Object>() { 386 @Override 387 public void run(Object... os) throws Exception { 388 setResult(((ComboBox) os[0]).getSelectionModel()); 389 } 390 }.dispatch(Root.ROOT.getEnvironment(), 391 testedControl.getControl()) instanceof CustomMultipleSelectionModel); 392 393 addElements(1, 2, 3); 394 395 for (int i = 1; i <= 3; i++) { 396 testedControl.as(Selectable.class).selector().select(String.valueOf(i)); 397 } 398 } 399 400 @Smoke 401 @Test(timeout = 300000) 402 public void onActionPropertyTest() { 403 assertTrue((new ComboBox()).getOnAction() == null); 404 assertTrue(testedControl.getControl().getOnAction() instanceof EventHandler); 405 checkCounterValue(ON_ACTION_EVENT_COUNTER_ID, 0); 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 } 453 } 454 455 @Smoke 456 @Test(timeout = 300000) 457 public void selection2Test() throws InterruptedException, Exception { 458 clickDropDownButton(); 459 ListView lw = ((ListView) getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap().getControl()); 460 final int number = 10; 461 for (int i = 0; i < number; i++) { 462 addElement(String.valueOf(i), i); 463 } 464 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 4); 465 466 for (int i = 0; i < number * 3; i++) { 467 testedControl.as(Selectable.class).selector().select(String.valueOf(i % number)); 468 clickDropDownButton(); 469 clickDropDownButton(); 470 try { 471 assertEquals(i % number, lw.getSelectionModel().getSelectedIndex()); 472 assertEquals(String.valueOf(i % number), lw.getSelectionModel().getSelectedItem()); 473 } catch (Exception e) { 474 System.out.println("Exception was thrown on step " + i); 475 throw e; 476 } 477 } 478 } 479 480 @Smoke 481 @Test(timeout = 300000) 482 public void keyboardF4Tests() throws Exception { 483 popupShowingOnKeyPressCommonTest(KeyboardButtons.F4); 484 } 485 486 @Smoke 487 @Test(timeout = 300000)//RT-18176 488 public void keyboardAltUpTest() throws Exception { 489 popupShowingOnKeyPressCommonTest(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK); 490 } 491 492 @Smoke 493 @Test(timeout = 300000)//RT-18176 494 public void keyboardAltDownTest() throws Exception { 495 popupShowingOnKeyPressCommonTest(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK); 496 } 497 498 private void popupShowingOnKeyPressCommonTest(KeyboardButtons button, KeyboardModifiers... mdfs) throws Exception { 499 requestFocusOnControl(testedControl); 500 for (int j = 0; j <= 1; j++) { //to switch editable property 501 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 502 for (int i = 0; i < ITER; i++) { 503 testedControl.keyboard().pushKey(button, mdfs); 504 if (j == 0) {//editable state. 505 assertEquals(getTextFieldText(), ""); 506 } 507 checkTextFieldText(Properties.value, "null"); 508 509 try { 510 checkPopupShowing(i % 2 == 0 ? true : false); 511 } catch (Exception e) { 512 System.out.println("Exception was thrown on step " + i); 513 throw e; 514 } 515 } 516 } 517 } 518 519 @Smoke 520 @Test(timeout = 300000) 521 public void keyboardUpDownTest() throws InterruptedException { 522 final int number = 10; 523 for (int i = 0; i < number; i++) { 524 addElement(String.valueOf(i), i); 525 } 526 527 int currentItem = -1; 528 529 testedControl.mouse().click(); 530 testedControl.mouse().click(); 531 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 532 533 for (int k = 0; k < 3; k++) { 534 for (KeyboardButton key : EnumSet.of(KeyboardButtons.DOWN, KeyboardButtons.UP)) { 535 for (int i = 0; i < ITER; i++) { 536 if (key == KeyboardButtons.UP) { 537 currentItem -= 1; 538 } else { 539 currentItem += 1; 540 } 541 currentItem = (int) Math.round(adjustValue(0, number - 1, currentItem)); 542 543 testedControl.keyboard().pushKey(key); 544 545 checkSelectionState(currentItem, currentItem); 546 } 547 } 548 } 549 } 550 551 @Smoke 552 @Test(timeout = 300000) 553 public void keyboardPopupCloseTest() throws InterruptedException { 554 //According to spec: [Active list is open] close the active list. 555 for (int i = 0; i < 2; i++) { 556 for (KeyboardButton button : EnumSet.of(KeyboardButtons.ENTER, KeyboardButtons.ESCAPE, KeyboardButtons.SPACE)) { 557 clickDropDownButton(); 558 checkPopupShowing(true); 559 560 requestFocusOnControl(testedControl); 561 testedControl.keyboard().pushKey(button); 562 checkPopupShowing(false); 563 } 564 } 565 566 //ANTITEST: 567 requestFocusOnControl(testedControl); 568 for (int i = 0; i < 2; i++) { 569 for (KeyboardButton button : EnumSet.of(KeyboardButtons.ENTER, KeyboardButtons.ESCAPE, KeyboardButtons.SPACE)) { 570 checkPopupShowing(false); 571 testedControl.keyboard().pushKey(button); 572 checkPopupShowing(false); 573 } 574 } 575 } 576 577 @Smoke 578 @Test(timeout = 300000) 579 public void onEscapeNotSelectingTest() throws InterruptedException { 580 selectOnKeyboardCommonTest(KeyboardButtons.ESCAPE); 581 } 582 583 @Smoke 584 @Test(timeout = 300000) 585 public void onEnterSelectTest() throws InterruptedException { 586 selectOnKeyboardCommonTest(KeyboardButtons.ENTER); 587 } 588 589 @Smoke 590 @Test(timeout = 300000) 591 public void onSpaceSelectTest() throws InterruptedException { 592 selectOnKeyboardCommonTest(KeyboardButtons.SPACE); 593 } 594 595 private void selectOnKeyboardCommonTest(KeyboardButtons button) throws InterruptedException { 596 int number = 10; 597 for (int i = 0; i < number; i++) { 598 addElement(String.valueOf(i), i); 599 } 600 601 for (int i = 1; i < number; i++) { 602 testedControl.keyboard().pushKey(KeyboardButtons.F4); 603 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 604 testedControl.keyboard().pushKey(button); 605 checkPopupShowing(false); 606 checkTextFieldText(Properties.value, String.valueOf((i - 1) % number)); 607 } 608 } 609 610 //RT-18064 that would be a feature, so that is not a test//Ok. 611 public void keyboardAnyKeyTest() { 612 addElements("aaa", "bbb", "ccc"); 613 614 requestFocusOnControl(testedControl); 615 testedControl.keyboard().pushKey(KeyboardButtons.B); 616 checkSimpleListenerValue(Properties.selectedItem, "bbb"); 617 } 618 619 @Smoke 620 @Test(timeout = 300000) 621 public void mouseTest() throws InterruptedException { 622 623 //common click 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 665 public void commonNonEditableTest() throws InterruptedException, Throwable { 666 addElements(1, 2, 3, 4, 5, 6); 667 checkScreenshot("ComboBox_initial", testedControl); 668 669 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 3); 670 671 testedControl.mouse().click(); 672 testedControl.mouse().click(); 673 674 testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK); 675 checkScrollBarVisibility(true); 676 checkTextFieldText(Properties.showing, "true"); 677 678 testedControl.as(Selectable.class).selector().select("6"); 679 checkSelectionState(5, 6); 680 checkTextFieldText(Properties.value, "6"); 681 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); 728 } 729 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.visibleRowCount, 5); 730 731 for (int i = 0; i < size; i++) { 732 removeFromPos(0); 733 checkScreenshot(commonScreenShotName, testedControl); 734 } 735 736 checkScreenshot(commonScreenShotName, testedControl); 737 throwScreenshotError(); 738 } 739 740 @Smoke 741 @Test(timeout = 300000) 742 public void consistentAndEmptySelectionTest() { 743 //seems, the only way to do empty selection is using keyboard.UP. 744 int number = 5; 745 for (int i = 0; i < number; i++) { 746 addElement(String.valueOf(i), i); 747 } 748 749 requestFocusOnControl(testedControl); 750 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 751 for (int j = 1; j < number; j++) { 752 for (int k = 0; k < j; k++) { 753 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 754 checkTextFieldText(Properties.value, String.valueOf(k + 1)); 755 } 756 757 for (int k = 0; k < number; k++) { 758 testedControl.keyboard().pushKey(KeyboardButtons.UP); 759 if (k + 1 < j) { 760 checkTextFieldText(Properties.value, String.valueOf(j - k - 1)); 761 } else { 762 checkTextFieldText(Properties.value, String.valueOf(0)); 763 } 764 } 765 766 checkTextFieldText(Properties.value, "0"); 767 } 768 } 769 770 @Smoke 771 @Test(timeout = 300000) 772 public void addElementsInDropDownTest() { 773 addElements(0, 1, 2, 3, 4, 5, 6); 774 775 testedControl.as(Selectable.class).selector().select("3"); 776 checkSelectionState(3, 3); 777 addElement("2,5", 2); 778 checkSelectionState(4, 3); 779 addElement("3,5", 4); 780 checkSelectionState(5, 3); 781 addElement("4,5", 6); 782 checkSelectionState(5, 3); 783 } 784 785 @Smoke 786 @Test(timeout = 300000)//RT-18944, RT-19227 787 public void removeElementsFromDropDownTest() { 788 addElements(0, 1, 2, 3, 4, 5, 6); 789 790 testedControl.as(Selectable.class).selector().select("3"); 791 checkSelectionState(3, 3); 792 removeFromPos(5); 793 checkSelectionState(3, 3); 794 removeFromPos(4); 795 checkSelectionState(3, 3); 796 removeFromPos(2); 797 checkSelectionState(2, 3); 798 removeFromPos(2); 799 checkSimpleListenerValue(Properties.selectedIndex, -1); 800 checkTextFieldText(Properties.value, "null"); 801 } 802 803 @Smoke 804 @Test(timeout = 300000)//RT-18972 805 public void editingChangeModeText() { 806 currentSettingOption = SettingOption.MANUAL;//That is needed because otherwise test fails 807 addElements(1, 2, 3); 808 //initial state is uneditable 809 testedControl.as(Selectable.class).selector().select("3"); 810 checkValue("3"); 811 812 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 813 //editable 814 checkValue("null"); 815 assertEquals(getTextFieldText(), ""); 816 testedControl.as(Text.class).type(NEW_VALUE_1); 817 checkValue("null"); 818 testedControl.keyboard().pushKey(KeyboardButtons.ENTER); 819 checkValue(NEW_VALUE_1); 820 testedControl.as(Selectable.class).selector().select("1"); 821 assertEquals(getTextFieldText(), "1"); 822 checkValue("1"); 823 testedControl.as(Text.class).type(NEW_VALUE_2); 824 testedControl.keyboard().pushKey(KeyboardButtons.ENTER); 825 checkValue(NEW_VALUE_2 + "1"); 826 827 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 828 //non-editable 829 checkValue("null"); 830 testedControl.as(Selectable.class).selector().select("2"); 831 checkValue("2"); 832 833 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 834 //editable 835 checkValue("null"); 836 testedControl.as(Selectable.class).selector().select("1"); 837 checkValue("1"); 838 } 839 840 @ScreenshotCheck 841 @Test(timeout = 300000) 842 public void customCellAPIApplying() throws Throwable { 843 assertTrue((new ComboBox()).getCellFactory() == null); 844 assertTrue(testedControl.getControl().getCellFactory() == null); 845 applyCustomCellAPI(); 846 assertTrue(testedControl.getControl().getCellFactory() instanceof Callback); 847 addElements(1, 2, 3); 848 849 testedControl.as(Selectable.class).selector().select("3"); 850 checkValue("3"); 851 852 testedControl.mouse().click(); 853 854 checkScreenshot("ComboBox_Custom_CellAPI_[3]", testedControl); 855 Wrap wrap = getPopupWrap().as(Parent.class, Node.class).lookup(ListView.class).wrap(); 856 857 checkScreenshot("ComboBox_Custom_CellAPI_[Custom3]", wrap); 858 throwScreenshotError(); 859 } 860 //add cell factory testing 861 static private final String NEW_VALUE_1 = "new value 1"; 862 static private final String NEW_VALUE_2 = "new value 2"; 863 864 @Smoke 865 @Test(timeout = 300000) 866 public void testOnShowingEvent() throws Throwable { 867 testEvents(new CheckFunctor.IdCounter("SET_ON_SHOWING_COUNTER"), 868 new CheckFunctor.NullCounter()); 869 } 870 871 @Smoke 872 @Test(timeout = 300000) 873 public void testOnShownEvent() throws Throwable { 874 testEvents(new CheckFunctor.IdCounter("SET_ON_SHOWN_COUNTER"), 875 new CheckFunctor.NullCounter()); 876 } 877 878 @Smoke 879 @Test(timeout = 300000) 880 public void testOnHiding() throws Throwable { 881 testEvents(new CheckFunctor.NullCounter(), 882 new CheckFunctor.IdCounter("SET_ON_HIDING_COUNTER")); 883 } 884 885 @Smoke 886 @Test(timeout = 300000) 887 public void testOnHidden() throws Throwable { 888 testEvents(new CheckFunctor.NullCounter(), 889 new CheckFunctor.IdCounter("SET_ON_HIDEN_COUNTER")); 890 } 891 892 @Smoke 893 @Test(timeout = 300000) 894 public void testEventsSequence() throws Throwable { 895 896 /** 897 * Save default event handlers 898 */ 899 final EventHandler<Event> onShowing = new GetAction<EventHandler<Event>>() { 900 @Override 901 public void run(Object... os) throws Exception { 902 setResult(testedControl.getControl().getOnShowing()); 903 } 904 }.dispatch(Root.ROOT.getEnvironment()); 905 906 final EventHandler<Event> onShown = new GetAction<EventHandler<Event>>() { 907 @Override 908 public void run(Object... os) throws Exception { 909 setResult(testedControl.getControl().getOnShown()); 910 } 911 }.dispatch(Root.ROOT.getEnvironment()); 912 913 final EventHandler<Event> onHiding = new GetAction<EventHandler<Event>>() { 914 @Override 915 public void run(Object... os) throws Exception { 916 setResult(testedControl.getControl().getOnHiding()); 917 } 918 }.dispatch(Root.ROOT.getEnvironment()); 919 920 final EventHandler<Event> onHidden = new GetAction<EventHandler<Event>>() { 921 @Override 922 public void run(Object... os) throws Exception { 923 setResult(testedControl.getControl().getOnHidden()); 924 } 925 }.dispatch(Root.ROOT.getEnvironment()); 926 927 final Map<EventHandler<Event>, Long> timestampsOfEvents = 928 new HashMap<EventHandler<Event>, Long>(); 929 930 /** 931 * Assing new event handlers to get timestamps 932 */ 933 new GetAction<Object>() { 934 @Override 935 public void run(Object... os) throws Exception { 936 testedControl.getControl().setOnShowing(new EventHandler() { 937 public void handle(Event t) { 938 timestampsOfEvents.put(onShowing, System.nanoTime()); 939 } 940 }); 941 942 testedControl.getControl().setOnShown(new EventHandler() { 943 public void handle(Event t) { 944 timestampsOfEvents.put(onShown, System.nanoTime()); 945 } 946 }); 947 948 testedControl.getControl().setOnHiding(new EventHandler() { 949 public void handle(Event t) { 950 timestampsOfEvents.put(onHiding, System.nanoTime()); 951 } 952 }); 953 954 testedControl.getControl().setOnHidden(new EventHandler() { 955 public void handle(Event t) { 956 timestampsOfEvents.put(onHidden, System.nanoTime()); 957 } 958 }); 959 } 960 }.dispatch(Root.ROOT.getEnvironment()); 961 962 testEvents(new CheckFunctor.NullCounter(), 963 new CheckFunctor() { 964 @Override 965 public void call(int conterVal) throws Throwable { 966 /** 967 * Compare timestamps of events 968 */ 969 Long onShowingTime = timestampsOfEvents.get(onShowing); 970 Long onShownTime = timestampsOfEvents.get(onShown); 971 Long onHidingTime = timestampsOfEvents.get(onHiding); 972 Long onHiddenTime = timestampsOfEvents.get(onHidden); 973 974 assertEquals(true, onShowingTime < onShownTime); 975 assertEquals(true, onShownTime < onHidingTime); 976 assertEquals(true, onHidingTime < onHiddenTime); 977 } 978 }); 979 /** 980 * Restore default event handlers 981 */ 982 new GetAction<Object>() { 983 @Override 984 public void run(Object... os) throws Exception { 985 testedControl.getControl().setOnShowing(onShowing); 986 testedControl.getControl().setOnShown(onShown); 987 testedControl.getControl().setOnHiding(onHiding); 988 testedControl.getControl().setOnHidden(onHidden); 989 } 990 }.dispatch(Root.ROOT.getEnvironment()); 991 } 992 993 /** 994 * Method sets four counters to zero 995 */ 996 private void clearCounters() { 997 final String counterInitVal = "0"; 998 changeTextFieldText("SET_ON_SHOWING_COUNTER_COUNTER_TEXT_FIELD_ID", counterInitVal); 999 changeTextFieldText("SET_ON_SHOWN_COUNTER_COUNTER_TEXT_FIELD_ID", counterInitVal); 1000 changeTextFieldText("SET_ON_HIDING_COUNTER_COUNTER_TEXT_FIELD_ID", counterInitVal); 1001 changeTextFieldText("SET_ON_HIDEN_COUNTER_COUNTER_TEXT_FIELD_ID", counterInitVal); 1002 } 1003 1004 /** 1005 * Method opens and closes ComboBox by all possible means and calls passed 1006 * functors after each opening or closing. 1007 * 1008 * @param checkCountersAfterOpening 1009 * @param checkCountersAfterClosing 1010 * @throws Throwable 1011 */ 1012 private void testEvents(CheckFunctor checkCountersAfterOpening, 1013 CheckFunctor checkCountersAfterClosing) throws Throwable { 1014 /** 1015 * make sure that comboBox is closed 1016 */ 1017 assertFalse(new GetAction<Boolean>() { 1018 @Override 1019 public void run(Object... os) throws Exception { 1020 setResult(testedControl.getControl().showingProperty().getValue()); 1021 } 1022 }.dispatch(Root.ROOT.getEnvironment())); 1023 1024 /** 1025 * Fill ComboBox with elements 1026 */ 1027 addElements("aaa", "bbb", "ccc", "ddd", "eee"); 1028 1029 clearCounters(); 1030 1031 int counterVal = 1; 1032 1033 /** 1034 * Open ComboBox by clicking on it's text field 1035 */ 1036 testedControl.mouse().click(); 1037 checkPopupShowing(true); 1038 checkCountersAfterOpening.call(counterVal); 1039 /** 1040 * Close it the same way 1041 */ 1042 testedControl.mouse().click(); 1043 checkPopupShowing(false); 1044 checkCountersAfterClosing.call(counterVal); 1045 1046 /** 1047 * Counter should have increased 1048 */ 1049 counterVal++; 1050 1051 /** 1052 * Click on drop down arrow 1053 */ 1054 clickDropDownButton(); 1055 checkPopupShowing(true); 1056 checkCountersAfterOpening.call(counterVal); 1057 1058 clickDropDownButton(); 1059 checkPopupShowing(false); 1060 checkCountersAfterClosing.call(counterVal); 1061 1062 counterVal++; 1063 1064 /** 1065 * Press f4 1066 */ 1067 testedControl.keyboard().pushKey(KeyboardButtons.F4); 1068 checkPopupShowing(true); 1069 checkCountersAfterOpening.call(counterVal); 1070 1071 testedControl.keyboard().pushKey(KeyboardButtons.F4); 1072 checkPopupShowing(false); 1073 checkCountersAfterClosing.call(counterVal); 1074 1075 counterVal++; 1076 1077 /** 1078 * Alt+down arrow 1079 */ 1080 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK); 1081 checkPopupShowing(true); 1082 checkCountersAfterOpening.call(counterVal); 1083 1084 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.ALT_DOWN_MASK); 1085 checkPopupShowing(false); 1086 checkCountersAfterClosing.call(counterVal); 1087 1088 counterVal++; 1089 1090 /** 1091 * Alt+up arrow 1092 */ 1093 testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK); 1094 checkPopupShowing(true); 1095 checkCountersAfterOpening.call(counterVal); 1096 1097 testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.ALT_DOWN_MASK); 1098 checkPopupShowing(false); 1099 checkCountersAfterClosing.call(counterVal); 1100 } 1101 1102 private static interface CheckFunctor { 1103 1104 public void call(int counterVal) throws Throwable; 1105 1106 static class NullCounter implements CheckFunctor { 1107 1108 public void call(int counterVal) throws Throwable { 1109 } 1110 }; 1111 1112 static class IdCounter implements CheckFunctor { 1113 1114 private final String id; 1115 1116 public IdCounter(String id) { 1117 this.id = id; 1118 } 1119 1120 public void call(int counterVal) throws Throwable { 1121 ComboBoxTest.checkCounterValue(id, counterVal); 1122 } 1123 } 1124 }; 1125 1126 /** 1127 * Test adds an element to ComboBox when onShowing event is fired and checks 1128 * that new element was rendered properly 1129 * 1130 * @throws Throwable 1131 */ 1132 @Smoke 1133 @Test(timeout = 300000) 1134 public void testOnShowingByModifyingContent() throws Throwable { 1135 1136 final int initialSize = 4; 1137 addElements("1", "2", "3", "4"); 1138 1139 clickButtonForTestPurpose(SET_ADDING_ELEMENTS_ON_SHOWING); 1140 testedControl.mouse().click(); 1141 checkPopupShowing(true); 1142 1143 Wrap<? extends ListView> list = getPopupWrap() 1144 .as(Parent.class, Node.class) 1145 .lookup(ListView.class) 1146 .wrap(); 1147 1148 Wrap<? extends ListCell> testCell = list 1149 .as(Parent.class, Node.class) 1150 .lookup(ListCell.class, new ListItemByObjectLookup<String>(INITIAL_VALUE)) 1151 .wrap(); 1152 1153 Wrap<? extends ListCell> previousCell = list 1154 .as(Parent.class, Node.class) 1155 .lookup(ListCell.class, new ListItemByObjectLookup<String>("4")) 1156 .wrap(); 1157 1158 assertTrue(testCell.getScreenBounds().getY() 1159 >= previousCell.getScreenBounds().getY() 1160 + previousCell.getScreenBounds().getHeight()); 1161 1162 /* Check that size of ComboBox list has increased */ 1163 Boolean result = new GetAction<Boolean>() { 1164 @Override 1165 public void run(Object... os) throws Exception { 1166 setResult(testedControl.getControl().getItems().size() == (initialSize + 1)); 1167 } 1168 }.dispatch(Root.ROOT.getEnvironment()); 1169 assertTrue(result); 1170 1171 clickButtonForTestPurpose(RESTORE_ON_SHOWING_EVENT_HANDLER); 1172 } 1173 1174 /** 1175 * Test that not editable ComboBox's getEditor() method must return null 1176 */ 1177 @Smoke 1178 @Test(timeout = 300000) 1179 public void testNotEditableGetEditorMethod() { 1180 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable, false); 1181 checkTextFieldText(Properties.text, ""); 1182 } 1183 1184 /** 1185 * Test that text entered in TextField doesn't change ComboBox's value 1186 */ 1187 @Smoke 1188 @Test(timeout = 300000) 1189 public void testInputByEditorProperty() throws Throwable { 1190 addElements("1", "2", "3", "4"); 1191 1192 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 1193 1194 final String selectedVal = "2"; 1195 testedControl.as(Selectable.class).selector().select(selectedVal); 1196 1197 /** 1198 * Change text in TextField 1199 */ 1200 final String testedText = "aaa"; 1201 setPropertyByTextField(SettingType.SETTER, Properties.text, testedText); 1202 1203 /** 1204 * Value shouldn't have changed 1205 */ 1206 checkTextFieldText(Properties.value, selectedVal); 1207 1208 checkTextFieldText(Properties.text, testedText); 1209 } 1210 1211 /** 1212 * Test that TextField returned by getEditor() method remains the same after 1213 * changing editable property 1214 */ 1215 @Smoke 1216 @Test(timeout = 300000) 1217 public void testEditorProperty() throws Throwable { 1218 new PropertyTest.EditorPropertyTest(testedControl).test(); 1219 } 1220 1221 /** 1222 * Test that TextField's parent remains the same after changing editable 1223 * property 1224 * 1225 */ 1226 @Smoke 1227 @Test(timeout = 300000) 1228 public void testEditorPropertyParent() throws Throwable { 1229 new PropertyTest.EditorParentPropertyTest(testedControl).test(); 1230 } 1231 1232 /** 1233 * Test that text entered via TextField becomes ComboBox's value when 1234 * ComboBox looses focus 1235 */ 1236 @Smoke 1237 @Test(timeout = 300000) 1238 public void textEditorPropertyCommitOnFocusLost() throws Throwable { 1239 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable); 1240 1241 final String testedText = "test test test"; 1242 getEditTextFieldWrap().as(Text.class).type(testedText); 1243 1244 Wrap<? extends TextField> textFieldWrap = findTextField("ARMED_LISTENER_ID"); 1245 textFieldWrap.mouse().click(); 1246 1247 checkTextFieldText(Properties.value, testedText); 1248 1249 final String anotherText = "another string"; 1250 setPropertyByTextField(SettingType.SETTER, Properties.text, anotherText); 1251 1252 testedControl.keyboard().pushKey(KeyboardButtons.TAB); 1253 checkTextFieldText(Properties.value, anotherText); 1254 } 1255 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()); 1310 1311 if (prevCellTextHeight == 0) { 1312 prevCellTextHeight = cellTextWrap.getScreenBounds().getHeight(); 1313 } else { 1314 assertTrue(prevCellTextHeight < cellTextWrap.getScreenBounds().getHeight()); 1315 prevCellTextHeight = cellTextWrap.getScreenBounds().getHeight(); 1316 } 1317 1318 if (fontSize == INITIAL_FONT_SIZE) { 1319 continue; 1320 } 1321 1322 Wrap<? extends ListCell> prevCellWrap = listWrap.as(Parent.class, Node.class) 1323 .lookup(ListCell.class, new ByText(String.valueOf(fontSize - 2), StringComparePolicy.EXACT)).wrap(); 1324 1325 /* compare cell coordinates with previous cell coordinates */ 1326 assertTrue(cellWrap.getScreenBounds().getY() 1327 >= prevCellWrap.getScreenBounds().getY() + prevCellWrap.getScreenBounds().getHeight()); 1328 } 1329 } 1330 } 1331 1332 /** 1333 * Test different cell rendering of ComboBox button and list (pop up). 1334 * Button width must remain the same. Width of cells of ComboBox must also 1335 * remain the same. 1336 * 1337 * http://javafx-jira.kenai.com/browse/RT-24528 1338 */ 1339 @Test(timeout = 300000) 1340 public void testCellRenderingWidth() throws Throwable { 1341 1342 clickButtonForTestPurpose(POPULATE_COMBOBOX_WITH_FONT_SIZES); 1343 1344 for (boolean isEditable : new boolean[]{false, true}) { 1345 1346 if (!isEditable) { 1347 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable, false); 1348 } else { 1349 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable, true); 1350 } 1351 1352 //Wait editable state application. 1353 Thread.sleep(1000); 1354 1355 final double initialButtonWidth = testedControl.getScreenBounds().getWidth(); 1356 1357 if (!isPopupVisible()) { 1358 clickDropDownButton(); 1359 } 1360 final double initialPopupWidth = getPopupWrap().getScreenBounds().getWidth(); 1361 clickDropDownButton(); 1362 1363 for (int fontSize = INITIAL_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize += 2) { 1364 String testVal = String.valueOf(fontSize); 1365 1366 testedControl.as(Selectable.class).selector().select(String.valueOf(fontSize)); 1367 1368 /* check width of the button */ 1369 assertEquals(initialButtonWidth, testedControl.getScreenBounds().getWidth(), 2.001); 1370 1371 if (!isPopupVisible()) { 1372 clickDropDownButton(); 1373 } 1374 1375 /* check width of the popup */ 1376 assertEquals(initialPopupWidth, getPopupWrap().getScreenBounds().getWidth(), 1.001); 1377 1378 /* get wraps of cell and cell text node to compare coordinates */ 1379 Wrap<? extends ListView> listWrap = getPopupWrap().as(Parent.class, Node.class) 1380 .lookup(ListView.class).wrap(); 1381 1382 Wrap<? extends ListCell> cellWrap = listWrap.as(Parent.class, Node.class) 1383 .lookup(ListCell.class, new ByText(testVal, StringComparePolicy.EXACT)).wrap(); 1384 1385 Wrap<? extends javafx.scene.text.Text> cellTextWrap = cellWrap.as(Parent.class, Node.class) 1386 .lookup(javafx.scene.text.Text.class).wrap(); 1387 1388 /* cell text should be always inside cell */ 1389 assertTrue(cellTextWrap.getScreenBounds().getX() >= cellWrap.getScreenBounds().getX()); 1390 assertTrue(cellWrap.getScreenBounds().getY() + cellWrap.getScreenBounds().getHeight() 1391 >= cellTextWrap.getScreenBounds().getY() + cellTextWrap.getScreenBounds().getHeight()); 1392 1393 if (fontSize == INITIAL_FONT_SIZE) { 1394 continue; 1395 } 1396 1397 Wrap<? extends ListCell> prevCellWrap = listWrap.as(Parent.class, Node.class) 1398 .lookup(ListCell.class, new ByText(String.valueOf(fontSize - 2), StringComparePolicy.EXACT)).wrap(); 1399 1400 /* compare cell coordinates with previous cell coordinates */ 1401 assertEquals(prevCellWrap.getScreenBounds().getX(), cellWrap.getScreenBounds().getX(), 0.001); 1402 assertEquals(prevCellWrap.getScreenBounds().getWidth(), cellWrap.getScreenBounds().getWidth(), 0.001); 1403 } 1404 } 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."; 1446 MessageFormat m = new MessageFormat(pattern); 1447 final Format fmt = new ComboBoxApp.MyMessageFormat(m); 1448 1449 //Set format string converter 1450 new GetAction<Object>() { 1451 @Override 1452 public void run(Object... parameters) throws Exception { 1453 1454 testedControl.getControl().setConverter(new FormatStringConverter<String>(fmt)); 1455 1456 //populate control 1457 testedControl.getControl().getItems().addAll(testedValues); 1458 } 1459 }.dispatch(Root.ROOT.getEnvironment()); 1460 1461 setPropertyByToggleClick(SettingType.SETTER, Properties.editable, true); 1462 1463 //#toString 1464 for (int i = 0; i < testedValues.size(); i++) { 1465 testedControl.as(Selectable.class).selector().select(testedValues.get(i)); 1466 assertEquals(getTextFieldText(), fmt.format(testedValues.get(i))); 1467 } 1468 1469 //#fromString 1470 for (int i = 0; i < testedValues.size(); i++) { 1471 testedControl.as(Text.class).clear(); 1472 testedControl.as(Text.class).type(fmt.format(testedValues.get(i))); 1473 testedControl.keyboard().pushKey(KeyboardButtons.ENTER); 1474 1475 checkTextFieldText(Properties.value, testedValues.get(i)); 1476 } 1477 1478 doNextResetHard(); 1479 } 1480 1481 /** 1482 * Checks that when the sorting is applied to the underlying data collection 1483 * the cells are rendered in the right order. 1484 */ 1485 @Smoke 1486 @Test(timeout = 30000) 1487 public void renderingAfterSortingTest() { 1488 addElements("1", "2", "3", "4", "1", "2", "3", "4", "1", "42"); 1489 1490 final int ITEMS_COUNT = 9; 1491 1492 StringConverter<String> conv = new StringConverter<String>() { 1493 @Override 1494 public String toString(String s) { 1495 return s; 1496 } 1497 1498 @Override 1499 public String fromString(String s) { 1500 return s; 1501 } 1502 }; 1503 1504 SortValidator<String, ListCell> validator = new SortValidator<String, ListCell>(ITEMS_COUNT, conv) { 1505 @Override 1506 protected void setControlData(final ObservableList<String> ls) { 1507 new GetAction<Object>() { 1508 @Override 1509 public void run(Object... parameters) throws Exception { 1510 testedControl.getControl().setItems(ls); 1511 } 1512 }.dispatch(testedControl.getEnvironment()); 1513 } 1514 1515 @Override 1516 protected Lookup<? extends ListCell> getCellsLookup() { 1517 testedControl.mouse().click(); 1518 1519 Wrap<? extends ListView> listWrap = getPopupWrap().as(Parent.class, Node.class) 1520 .lookup(ListView.class).wrap(); 1521 1522 Lookup lookup = listWrap.as(Parent.class, Node.class) 1523 .lookup(ListCell.class, new LookupCriteria<ListCell>() { 1524 public boolean check(ListCell cell) { 1525 return cell.isVisible(); 1526 } 1527 }); 1528 1529 testedControl.keyboard().pushKey(KeyboardButtons.ESCAPE); 1530 1531 return lookup; 1532 } 1533 1534 @Override 1535 protected String getTextFromCell(ListCell cell) { 1536 return cell.getText(); 1537 } 1538 }; 1539 1540 boolean result = validator.check(); 1541 String msg = validator.getFailureReason(); 1542 assertTrue(msg, result); 1543 } 1544 1545 /** 1546 * When there are no items, or items list is null, placeholder about items 1547 * emptyness is shown in the popup. This test changes placeholder and 1548 * checks, that it is shown when popup is shown. 1549 */ 1550 @Smoke 1551 @Test(timeout = 30000) 1552 public void emptyListDropDownPlaceholderTest() throws Throwable { 1553 placeholderTestLoop(true); 1554 placeholderTestLoop(false); 1555 1556 selectObjectFromChoiceBox(SettingType.UNIDIRECTIONAL, Properties.placeholder, Label.class); 1557 if (!isPopupVisible(false)) { 1558 clickDropDownButton(); 1559 } 1560 1561 //wait for animation 1562 try { 1563 Thread.sleep(SLEEP); 1564 } catch (Exception ignore) { 1565 } 1566 1567 checkScreenshot("combobox_placeholder_dimmed", 1568 new NodeWrap(testedControl.getEnvironment(), new GetAction<Node>() { 1569 @Override 1570 public void run(Object... os) throws Exception { 1571 setResult(((javafx.scene.Parent) getPopupWrap().getControl().getRoot().getChildrenUnmodifiable().get(0)).getChildrenUnmodifiable().get(0)); 1572 } 1573 }.dispatch(Root.ROOT.getEnvironment()))); 1574 throwScreenshotError(); 1575 } 1576 1577 private void placeholderTestLoop(boolean withPopupClosedState) { 1578 assertEquals("Check initial emptyness of items list.", new GetAction<Integer>() { 1579 @Override 1580 public void run(Object... os) throws Exception { 1581 setResult(testedControl.getControl().getItems().size()); 1582 } 1583 }.dispatch(testedControl.getEnvironment()), 0, 0); 1584 1585 selectObjectFromChoiceBox(SettingType.SETTER, Properties.placeholder, Rectangle.class); 1586 checkTextFieldTextContaining(Properties.placeholder, "Rectangle"); 1587 testEmptyPlaceholder(Rectangle.class, true, withPopupClosedState); 1588 1589 addElement("0", 0); 1590 testEmptyPlaceholder(Rectangle.class, false, withPopupClosedState); 1591 1592 removeFromPos(0); 1593 testEmptyPlaceholder(Rectangle.class, true, withPopupClosedState); 1594 1595 selectObjectFromChoiceBox(SettingType.BIDIRECTIONAL, Properties.placeholder, Polygon.class); 1596 checkTextFieldTextContaining(Properties.placeholder, "Polygon"); 1597 testEmptyPlaceholder(Polygon.class, true, withPopupClosedState); 1598 1599 clickButtonForTestPurpose(SET_ITEMS_NULL_BUTTON_ID); 1600 testEmptyPlaceholder(Polygon.class, true, withPopupClosedState); 1601 1602 selectObjectFromChoiceBox(SettingType.UNIDIRECTIONAL, Properties.placeholder, Rectangle.class); 1603 checkTextFieldTextContaining(Properties.placeholder, "Rectangle"); 1604 testEmptyPlaceholder(Rectangle.class, true, withPopupClosedState); 1605 1606 new GetAction() { 1607 @Override 1608 public void run(Object... os) throws Exception { 1609 testedControl.getControl().setItems(FXCollections.<String>observableArrayList("1")); 1610 } 1611 }.dispatch(testedControl.getEnvironment()); 1612 testEmptyPlaceholder(Rectangle.class, false, withPopupClosedState); 1613 1614 removeFromPos(0); 1615 } 1616 1617 private void testEmptyPlaceholder(final Class classOfPlaceholder, boolean expectedToBeShown, boolean closePopupAfter) { 1618 if (!isPopupVisible()) { 1619 clickDropDownButton(); 1620 } 1621 1622 testedControl.waitState(new State<Integer>() { 1623 public Integer reached() { 1624 final Lookup<Node> lookup = getPopupWrap().as(Parent.class, Node.class).lookup(classOfPlaceholder); 1625 final int size = lookup.size(); 1626 if (size == 0) { 1627 return 0; 1628 } else { 1629 final Wrap placeholderPane = getPopupWrap().as(Parent.class, Node.class).lookup(new ByStyleClass("placeholder")).wrap(0); 1630 final Parent<Node> parent = (Parent<Node>) placeholderPane.as(Parent.class, Node.class); 1631 assertTrue("Double check : there still must be a placeholder.", parent.lookup(classOfPlaceholder).size() > 0); 1632 if (!new GetAction<Boolean>() { 1633 @Override 1634 public void run(Object... os) throws Exception { 1635 setResult(((Wrap<Node>) os[0]).getControl().isVisible()); 1636 } 1637 }.dispatch(testedControl.getEnvironment(), placeholderPane)) { 1638 return 0; 1639 } else { 1640 return 1; 1641 } 1642 } 1643 } 1644 }, expectedToBeShown ? 1 : 0); 1645 1646 if (closePopupAfter) { 1647 clickDropDownButton(); 1648 } 1649 } 1650 }