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.ListView; 26 27 import client.test.ScreenshotCheck; 28 import client.test.Smoke; 29 import javafx.collections.ObservableList; 30 import javafx.commons.SortValidator; 31 import javafx.event.EventHandler; 32 import javafx.geometry.Orientation; 33 import javafx.scene.Node; 34 import javafx.scene.control.ListCell; 35 import javafx.scene.control.ListView; 36 import javafx.scene.control.ScrollBar; 37 import javafx.scene.control.SelectionMode; 38 import javafx.scene.control.test.util.MultipleSelectionHelper; 39 import javafx.scene.control.test.util.ScrollingChecker; 40 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType; 41 import javafx.scene.input.KeyCode; 42 import javafx.scene.input.KeyEvent; 43 import javafx.scene.input.MouseEvent; 44 import javafx.scene.text.Text; 45 import javafx.util.StringConverter; 46 import org.jemmy.Rectangle; 47 import org.jemmy.action.GetAction; 48 import org.jemmy.control.Wrap; 49 import org.jemmy.fx.Root; 50 import org.jemmy.interfaces.Keyboard.KeyboardButtons; 51 import org.jemmy.interfaces.Keyboard.KeyboardModifiers; 52 import org.jemmy.interfaces.Mouse; 53 import org.jemmy.interfaces.Parent; 54 import org.jemmy.interfaces.Showable; 55 import org.jemmy.lookup.Lookup; 56 import org.jemmy.lookup.LookupCriteria; 57 import org.jemmy.timing.State; 58 import org.junit.After; 59 import static org.junit.Assert.assertFalse; 60 import static org.junit.Assert.assertTrue; 61 import org.junit.Before; 62 import org.junit.Test; 63 import org.junit.runner.RunWith; 64 import test.javaclient.shared.FilteredTestRunner; 65 import test.javaclient.shared.Utils; 66 67 /** 68 * @author Alexander Kirov 69 */ 70 @RunWith(FilteredTestRunner.class) 71 public class NewListViewTest extends TestBase { 72 73 static StringBuilder sb = new StringBuilder(); 74 75 @Before 76 @Override 77 public void setUp() { 78 super.setUp(); 79 80 new GetAction<Object>() { 81 @Override 82 public void run(Object... os) throws Exception { 83 ListView list = (ListView) testedControl.getControl(); 84 list.addEventFilter(KeyEvent.KEY_RELEASED, new EventHandler<javafx.scene.input.KeyEvent>() { 85 public void handle(javafx.scene.input.KeyEvent event) { 86 if (event.getCode() == KeyCode.CONTROL) return; 87 if (event.getCode() == KeyCode.ALT) return; 88 if (event.getCode() == KeyCode.SHIFT) return; 89 90 if (event.isAltDown()) sb.append("ALT + "); 91 if (event.isControlDown()) sb.append("CTRL + "); 92 if (event.isShiftDown()) sb.append("SHIFT + "); 93 94 sb.append(event.getCode()).append("\n"); 95 } 96 }); 97 } 98 }.dispatch(testedControl.getEnvironment()); 99 100 new GetAction<Object>() { 101 @Override 102 public void run(Object... os) throws Exception { 103 ListView list = (ListView) testedControl.getControl(); 104 list.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() { 105 public void handle(MouseEvent event) { 106 sb.append("mouse ").append(event.getButton()).append("\n"); 107 } 108 }); 109 } 110 }.dispatch(testedControl.getEnvironment()); 111 } 112 113 @After 114 public void _after() { 115 String newLine = "\n"; 116 int currIndex = sb.indexOf(newLine); 117 int prevIndex = 0; 118 119 int counter = 1; 120 String prevLine = null; 121 122 StringBuilder rolledUpResult = new StringBuilder(); 123 while(currIndex > 0) { 124 String currLine = sb.substring(prevIndex, currIndex); 125 if (prevLine == null) { 126 prevLine = currLine; 127 } else if (prevLine.equals(currLine)) { 128 ++counter; 129 } else { 130 rolledUpResult.append(prevLine); 131 if (counter > 1) rolledUpResult.append(" x").append(counter); 132 rolledUpResult.append(newLine); 133 counter = 1; 134 prevLine = currLine; 135 } 136 prevIndex = currIndex + 1; 137 currIndex = sb.indexOf(newLine, prevIndex); 138 if (currIndex == sb.length() - 1) { 139 rolledUpResult.append(sb.substring(prevIndex)); 140 break; 141 } 142 } 143 System.out.println("Key sequence:"); 144 System.out.println(rolledUpResult.toString()); 145 sb = new StringBuilder(); 146 } 147 148 //SECTION OF TESTS ON PROPERTIES 149 @Smoke 150 @Test(timeout = 300000) 151 public void editablePropertyTest() { 152 setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.editable); 153 checkTextFieldText(Properties.editable, "true"); 154 155 clickToggleButton("BIDIR_EDITABLE_CONTROLLER_ID"); 156 checkTextFieldText(Properties.editable, "false"); 157 158 setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.editable); 159 checkTextFieldText(Properties.editable, "true"); 160 161 clickToggleButton("UNIDIR_EDITABLE_CONTROLLER_ID"); 162 checkTextFieldText(Properties.editable, "false"); 163 } 164 165 @Smoke 166 @Test(timeout = 300000) 167 public void orientationPropertyTest() { 168 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.VERTICAL, Properties.orientation); 169 checkTextFieldText(Properties.orientation, "VERTICAL"); 170 171 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 172 checkTextFieldText(Properties.orientation, "HORIZONTAL"); 173 174 setPropertyByChoiceBox(SettingType.UNIDIRECTIONAL, Orientation.VERTICAL, Properties.orientation); 175 checkTextFieldText(Properties.orientation, "VERTICAL"); 176 177 setPropertyByChoiceBox(SettingType.UNIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 178 checkTextFieldText(Properties.orientation, "HORIZONTAL"); 179 } 180 181 @Smoke 182 @Test(timeout = 300000) 183 public void selectionModePropertyTest() { 184 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 185 checkTextFieldText(Properties.selectionMode, "MULTIPLE"); 186 187 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 188 checkTextFieldText(Properties.selectionMode, "SINGLE"); 189 190 setPropertyByChoiceBox(SettingType.UNIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 191 checkTextFieldText(Properties.selectionMode, "MULTIPLE"); 192 193 setPropertyByChoiceBox(SettingType.UNIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 194 checkTextFieldText(Properties.selectionMode, "SINGLE"); 195 } 196 197 @Smoke 198 @Test(timeout = 300000) 199 public void prefHeightPropertyTest() throws InterruptedException { 200 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 200); 201 checkTextFieldValue(Properties.prefHeight, 200); 202 203 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100); 204 checkTextFieldValue(Properties.prefHeight, 100); 205 206 setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefHeight, 150); 207 checkTextFieldValue(Properties.prefHeight, 150); 208 209 setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefHeight, 50); 210 checkTextFieldValue(Properties.prefHeight, 50); 211 } 212 213 @Smoke 214 @Test(timeout = 300000) 215 public void prefWidthPropertyTest() throws InterruptedException { 216 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 200); 217 checkTextFieldValue(Properties.prefWidth, 200); 218 219 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100); 220 checkTextFieldValue(Properties.prefWidth, 100); 221 222 setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefWidth, 150); 223 checkTextFieldValue(Properties.prefWidth, 150); 224 225 setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefWidth, 50); 226 checkTextFieldValue(Properties.prefWidth, 50); 227 } 228 229 // SITUATIONAL TESTS 230 @Smoke 231 @Test(timeout = 300000) 232 public void keyboardRangeMultipleSelection2Test() throws Throwable { 233 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 234 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 235 KeyboardButtons CTRL_OS = Utils.isMacOS() ? KeyboardButtons.META : KeyboardButtons.CONTROL; 236 237 selectionHelper = new MultipleSelectionHelper(1, DATA_ITEMS_NUM); 238 selectionHelper.setMultiple(true); 239 240 requestFocusOnControl(testedControl); 241 242 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 243 244 testedControl.keyboard().pressKey(KeyboardButtons.SHIFT); 245 try { 246 for (int i = 1; i < 5; i++) { 247 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 248 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 249 checkSelection(); 250 } 251 } finally { 252 testedControl.keyboard().releaseKey(KeyboardButtons.SHIFT); 253 } 254 255 testedControl.keyboard().pressKey(CTRL_OS); 256 try { 257 for (int i = 1; i < 5; i++) { 258 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 259 selectionHelper.push(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 260 checkSelection(); 261 } 262 } finally { 263 testedControl.keyboard().releaseKey(CTRL_OS); 264 } 265 266 testedControl.keyboard().pressKey(KeyboardButtons.SHIFT); 267 try { 268 for (int i = 1; i < 5; i++) { 269 testedControl.keyboard().pushKey(KeyboardButtons.UP); 270 selectionHelper.push(KeyboardButtons.UP, KeyboardModifiers.SHIFT_DOWN_MASK); 271 checkSelection(); 272 } 273 } finally { 274 testedControl.keyboard().releaseKey(KeyboardButtons.SHIFT); 275 } 276 277 testedControl.keyboard().pressKey(CTRL_OS); 278 try { 279 for (int i = 1; i < 5; i++) { 280 testedControl.keyboard().pushKey(KeyboardButtons.UP); 281 selectionHelper.push(KeyboardButtons.UP, CTRL_DOWN_MASK_OS); 282 checkSelection(); 283 } 284 } finally { 285 testedControl.keyboard().releaseKey(CTRL_OS); 286 } 287 } 288 289 @Smoke 290 @Test(timeout = 300000) 291 public void scrollToTest() throws InterruptedException { 292 int size = 10; 293 294 for (int i = 0; i <= size; i++) { 295 addElement(String.valueOf(i), i); 296 } 297 298 setSize(50, 50); 299 for (Orientation orientation : Orientation.values()) { 300 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, orientation, Properties.orientation); 301 302 scrollTo(size); 303 checkScrollingState(1, false, true, size, orientation); 304 305 scrollTo(0); 306 checkScrollingState(0, true, false, size, orientation); 307 308 scrollTo(size * 2); 309 checkScrollingState(1, false, true, size, orientation); 310 311 scrollTo(-size); 312 checkScrollingState(0, true, false, size, orientation); 313 } 314 } 315 316 private void checkScrollingState(final double scrollValue, boolean beginVisible, boolean endVisible, int size, final Orientation orientation) { 317 //assertEquals(findScrollBar(testedControl.as(Parent.class, Node.class), orientation, true).getControl().getValue(), scrollValue, 0.01); 318 testedControl.waitState(new State() { 319 public Object reached() { 320 Wrap<? extends ScrollBar> sb = findScrollBar(testedControl.as(Parent.class, Node.class), orientation, true); 321 if (Math.abs(sb.getControl().getValue() - scrollValue) < 0.01) { 322 return true; 323 } else { 324 return null; 325 } 326 } 327 }); 328 329 if (beginVisible) { 330 assertTrue(isCellShown(0, orientation)); 331 } 332 if (endVisible) { 333 assertTrue(isCellShown(size, orientation)); 334 } 335 } 336 337 private boolean isCellShown(final int item, Orientation orientation) { 338 Wrap<Text> cellWrap = getCellWrap(item); 339 Rectangle cellRect = cellWrap.getScreenBounds(); 340 Rectangle control = testedControl.getScreenBounds(); 341 342 // int epsilon = 0; 343 // 344 // if (orientation == Orientation.HORIZONTAL) { 345 // control.x = control.x - epsilon; 346 // control.width = control.width + 2 * epsilon; 347 // } else { 348 // control.y = control.y - epsilon; 349 // control.height = control.height + 2 * epsilon; 350 // } 351 352 return control.contains(cellRect); 353 } 354 355 @Smoke 356 @Test(timeout = 30000) 357 public void fixedCellSizePropertyTest() throws InterruptedException { 358 adjustControl(); 359 fixedCellSizePropertyTestCommon(testedControl, Properties.fixedCellSize, Utils.isCaspian() ? 19.4 : 21); 360 } 361 362 @Smoke 363 @Test(timeout = 30000) 364 public void fixedCellSizePropertyCSSTest() { 365 adjustControl(); 366 fixedCellSizePropertyCSSTestCommon(testedControl, Properties.fixedCellSize, Utils.isCaspian() ? 19.4 : 21); 367 } 368 369 @Smoke 370 @Test(timeout = 300000) 371 public void verticalScrollBarBehaviorOnAddingDeletingTest() throws InterruptedException { 372 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 50); 373 assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null); 374 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 375 assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) == null); 376 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 500); 377 assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null); 378 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 50); 379 for (int i = 0; i < 10; i++) { 380 removeFromPos(0); 381 } 382 assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null); 383 } 384 385 //Test//RT-17538//Test removed, as non actual (bug - is not a bug). 386 public void steadyScrollingTest() throws InterruptedException { 387 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 150); 388 389 addRectangleAtPos(0); 390 addTextFieldAtPos(1); 391 addRectangleAtPos(2); 392 393 Wrap<? extends ScrollBar> sb = findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true); 394 ScrollingChecker sc = new ScrollingChecker(sb.getControl().valueProperty()); 395 testedControl.mouse().move(); 396 for (int i = 0; i < 8; i++) { 397 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+1); 398 sc.checkChanging(+1); 399 } 400 } 401 402 @Smoke 403 @Test(timeout = 300000) 404 public void scrollAppearingOnResizingTest() throws InterruptedException { 405 setSize(50, 50); 406 checkScrollbarsStates(false, false); 407 408 addRectangleAtPos(0); 409 410 checkScrollbarsStates(true, true); 411 412 setSize(230, 50); 413 checkScrollbarsStates(false, true); 414 415 setSize(50, 225); 416 checkScrollbarsStates(true, false); 417 418 setSize(230, 230); 419 checkScrollbarsStates(false, false); 420 421 setSize(50, 50); 422 checkScrollbarsStates(true, true); 423 424 removeFromPos(0); 425 426 checkScrollbarsStates(false, false); 427 } 428 429 @Smoke 430 @Test(timeout = 300000) 431 public void scrollBarAppearingSensitivityTest() throws InterruptedException { 432 addRectangleAtPos(0); 433 434 setSize(208, 208); 435 checkScrollbarsStates(true, true); 436 437 setSize(225, 225); 438 checkScrollbarsStates(false, false); 439 } 440 441 @Smoke 442 @Test(timeout = 300000)//RT-18293 443 public void eventsCommingTest() throws InterruptedException { 444 addFormAtPos(0); 445 446 setSize(200, 200); 447 448 clickFormButton(); 449 checkFormClickCounter(1); 450 scrollFormScrollBar(-1); 451 checkFormScrollCounter(1); 452 } 453 454 //Test//RT-17701// Test removed, because developers don't want to count size of content, to evaluate scrollBar size propertly. 455 public void scrollBarSize1Test() throws InterruptedException, Throwable { 456 setSize(150, 150); 457 addRectangleAtPos(0); 458 addRectangleAtPos(0); 459 addTextFieldAtPos(1); 460 461 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 462 463 checkScreenshot("ListView_scrollBarSize1Test_HorizontalScroll_1", findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true)); 464 checkScreenshot("ListView_scrollBarSize1Test_VerticalScroll_1", findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true)); 465 throwScreenshotError(); 466 } 467 468 @ScreenshotCheck 469 @Test(timeout = 300000) //RT-17460 470 public void scrollBarSize2Test() throws InterruptedException, Throwable { 471 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 472 setSize(200, 210); 473 474 addRectangleAtPos(0); 475 addRectangleAtPos(0); 476 checkScreenshot("ListView_HorizontalScroll_2", findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true)); 477 throwScreenshotError(); 478 } 479 480 @Smoke 481 @Test(timeout = 300000) //RT-17462 482 public void scrollBarDisappearTest() throws InterruptedException { 483 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 484 setSize(210, 210); 485 486 addRectangleAtPos(0); 487 addRectangleAtPos(0); 488 489 for (int i = 0; i < 100; i++) { 490 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+1); 491 } 492 493 assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) == null); 494 } 495 496 @ScreenshotCheck 497 @Smoke 498 @Test(timeout = 300000)//RT-17465 499 public void selectionSavingTest() throws InterruptedException, Throwable { 500 setSize(100, 100); 501 addRectangleAtPos(0); 502 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 503 testedControl.mouse().click(); 504 505 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.VERTICAL, Properties.orientation); 506 checkScreenshot("ListView_SelectionSavingChecking", testedControl); 507 508 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 509 checkScreenshot("ListView_SelectionSavingChecking", testedControl); 510 511 throwScreenshotError(); 512 } 513 514 @ScreenshotCheck 515 @Test(timeout = 300000)//RT-17705 516 public void scrollingConfused1Test() throws InterruptedException, Throwable { 517 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 518 setSize(150, 150); 519 addRectangleAtPos(0); 520 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+20); 521 522 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+20); 523 524 checkScreenshot("ListView_ScrollingIssue_1", testedControl); 525 throwScreenshotError(); 526 } 527 528 @ScreenshotCheck 529 @Test(timeout = 300000)//RT-17730 530 public void scrollingConfused2Test() throws InterruptedException, Throwable { 531 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.VERTICAL, Properties.orientation); 532 setSize(150, 150); 533 addRectangleAtPos(0); 534 Thread.sleep(500); 535 536 for (int i = 0; i < 20; i++) { 537 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+1); 538 } 539 540 for (int i = 0; i < 20; i++) { 541 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+1); 542 } 543 544 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 545 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+20); 546 checkScreenshot("ListView_ScrollingIssue_2", testedControl); 547 throwScreenshotError(); 548 } 549 550 @ScreenshotCheck 551 @Test(timeout = 300000)//RT-17733 552 public void scrollingConfused3Test() throws Throwable { 553 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.VERTICAL, Properties.orientation); 554 setSize(150, 150); 555 addRectangleAtPos(0); 556 557 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+20); 558 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+20); 559 checkScreenshot("ListView_ScrollingIssue_3", testedControl); 560 throwScreenshotError(); 561 } 562 563 @Smoke 564 @Test(timeout = 300000)//RT-17522 565 public void addingElementOnFocusPositionTest() { 566 addElements(1, 2, 3, 4, 5, 6, 7); 567 testedControl.mouse().click(); 568 569 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 570 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 571 572 checkListener(Listeners.focusedIndex, 1); 573 addElement("0", 0); 574 checkListener(Listeners.focusedIndex, 2); 575 addElement("0", 2); 576 checkListener(Listeners.focusedIndex, 3); 577 addElement("0", 4); 578 checkListener(Listeners.focusedIndex, 3); 579 } 580 581 //Test//RT-17539//Test removed because developers don't count size of content. 582 public void knobSizeChangingTest() throws InterruptedException, Throwable { 583 setSize(150, 150); 584 585 addTextFieldAtPos(0); 586 addRectangleAtPos(1); 587 addElement("0", 2); 588 589 checkScreenshot("ListView_ScrollBarKnobSizeIssue_1", testedControl); 590 591 for (int i = 0; i < 20; i++) { 592 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+1); 593 } 594 595 checkScreenshot("ListView_ScrollBarKnobSizeIssue_2", testedControl); 596 597 findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+10); 598 599 checkScreenshot("ListView_ScrollBarKnobSizeIssue_3", testedControl); 600 throwScreenshotError(); 601 } 602 603 @Smoke 604 @Test(timeout = 300000)//RT-18234 - possible 605 public void singleSelectionOnKeyBoardTest() throws InterruptedException, Throwable { 606 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 607 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 608 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 609 setSize(130, 130); 610 611 selectionHelper = new MultipleSelectionHelper(1, DATA_ITEMS_NUM); 612 selectionHelper.setSingleCell(false); 613 selectionHelper.setMultiple(false); 614 615 requestFocusOnControl(testedControl); 616 617 Thread.sleep(SLEEP); 618 619 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 620 621 Thread.sleep(SLEEP); 622 623 //Testing section 624 try { 625 for (int i = 0; i < 5; i++) { 626 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 627 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 628 checkSelection(); 629 } 630 631 for (int i = 0; i < 3; i++) { 632 testedControl.keyboard().pushKey(KeyboardButtons.UP, CTRL_DOWN_MASK_OS); 633 selectionHelper.push(KeyboardButtons.UP, CTRL_DOWN_MASK_OS); 634 checkSelection(); 635 } 636 637 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 638 testedControl.keyboard().releaseKey(KeyboardButtons.SHIFT); 639 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 640 checkSelection(); 641 // End of testing section 642 } catch (Throwable error) { 643 throw error; 644 } 645 } 646 647 @Smoke 648 @Test(timeout = 300000) 649 public void multipleSelectionCommonLogicOnKeyBoardTest() throws InterruptedException, Throwable { 650 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 651 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 652 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 653 setSize(130, 130); 654 655 selectionHelper = new MultipleSelectionHelper(1, DATA_ITEMS_NUM); 656 selectionHelper.setSingleCell(false); 657 selectionHelper.setMultiple(true); 658 659 requestFocusOnControl(testedControl); 660 661 Thread.sleep(SLEEP); 662 663 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 664 665 Thread.sleep(SLEEP); 666 667 //Testing section 668 try { 669 for (int i = 0; i < 2; i++) { 670 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 671 selectionHelper.push(KeyboardButtons.DOWN); 672 } 673 674 for (int i = 0; i < 5; i++) { 675 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 676 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 677 checkSelection(); 678 } 679 //Elements from 2 to 7 are selected 680 681 for (int i = 0; i < 2; i++) { 682 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 683 selectionHelper.push(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 684 checkSelection(); 685 } 686 687 for (int i = 0; i < 5; i++) { 688 testedControl.keyboard().pushKey(KeyboardButtons.UP, KeyboardModifiers.SHIFT_DOWN_MASK); 689 selectionHelper.push(KeyboardButtons.UP, KeyboardModifiers.SHIFT_DOWN_MASK); 690 checkSelection(); 691 } 692 693 for (int i = 0; i < 4; i++) { 694 testedControl.keyboard().pushKey(KeyboardButtons.UP, CTRL_DOWN_MASK_OS); 695 selectionHelper.push(KeyboardButtons.UP, CTRL_DOWN_MASK_OS); 696 checkSelection(); 697 } 698 699 for (int i = 0; i < 6; i++) { 700 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 701 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 702 checkSelection(); //RT-18234 - possible 703 } 704 705 for (int i = 0; i < 2; i++) { 706 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 707 selectionHelper.push(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 708 checkSelection(); 709 } 710 711 for (int i = 0; i < 15; i++) { 712 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 713 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 714 checkSelection(); 715 } 716 // End of testing section 717 } catch (Throwable error) { 718 throw error; 719 } 720 } 721 722 @Smoke 723 @Test(timeout = 300000) 724 public void ctrlAClickSingleTest() throws InterruptedException, Throwable { 725 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 726 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 727 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 728 setSize(130, 130); 729 730 selectionHelper = new MultipleSelectionHelper(1, DATA_ITEMS_NUM); 731 selectionHelper.setSingleCell(false); 732 selectionHelper.setMultiple(false); 733 734 requestFocusOnControl(testedControl); 735 736 Thread.sleep(SLEEP); 737 738 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 739 740 Thread.sleep(SLEEP); 741 742 //Testing section 743 try { 744 for (int i = 0; i < 2; i++) { 745 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 746 selectionHelper.push(KeyboardButtons.DOWN); 747 } 748 749 for (int i = 0; i < 4; i++) { 750 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 751 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 752 checkSelection(); 753 } 754 //Elements from 2 to 6 are selected 755 756 for (int i = 0; i < 2; i++) { 757 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 758 selectionHelper.push(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 759 checkSelection(); 760 } 761 762 testedControl.keyboard().pushKey(KeyboardButtons.A, CTRL_DOWN_MASK_OS); 763 selectionHelper.ctrlA = true; 764 currentListContentSize = 10; 765 checkSelection(); 766 checkListener(Listeners.focusedIndex, 8); 767 checkListener(Listeners.selectedIndex, 6); 768 769 // End of testing section 770 } catch (Throwable error) { 771 throw error; 772 } 773 } 774 775 @Smoke 776 @Test(timeout = 300000) 777 public void ctrlAClickMultipleTest() throws InterruptedException, Throwable { 778 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); 779 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 780 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 781 setSize(130, 130); 782 783 selectionHelper = new MultipleSelectionHelper(1, 10); 784 selectionHelper.setSingleCell(false); 785 selectionHelper.setMultiple(true); 786 787 requestFocusOnControl(testedControl); 788 789 Thread.sleep(SLEEP); 790 791 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 792 793 Thread.sleep(SLEEP); 794 795 //Testing section 796 try { 797 for (int i = 0; i < 2; i++) { 798 testedControl.keyboard().pushKey(KeyboardButtons.DOWN); 799 selectionHelper.push(KeyboardButtons.DOWN); 800 } 801 802 for (int i = 0; i < 4; i++) { 803 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 804 selectionHelper.push(KeyboardButtons.DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 805 checkSelection(); 806 } 807 //Elements from 2 to 6 are selected 808 809 for (int i = 0; i < 2; i++) { 810 testedControl.keyboard().pushKey(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 811 selectionHelper.push(KeyboardButtons.DOWN, CTRL_DOWN_MASK_OS); 812 checkSelection(); 813 } 814 815 testedControl.keyboard().pushKey(KeyboardButtons.A, CTRL_DOWN_MASK_OS); 816 selectionHelper.ctrlA = true; 817 currentListContentSize = 10; 818 checkSelection(); 819 checkListener(Listeners.focusedIndex, 8); 820 checkListener(Listeners.selectedIndex, 8); 821 822 // End of testing section 823 } catch (Throwable error) { 824 throw error; 825 } 826 } 827 828 @Smoke 829 @Test(timeout = 300000) 830 public void mouseClickingVerticalMultipleTest() throws InterruptedException, Throwable { 831 commonClickingTest(Orientation.VERTICAL, SelectionMode.MULTIPLE); 832 } 833 834 @Smoke 835 @Test(timeout = 300000) 836 public void mouseClickingHorizontalMultipleTest() throws InterruptedException, Throwable { 837 commonClickingTest(Orientation.HORIZONTAL, SelectionMode.MULTIPLE); 838 } 839 840 @Smoke 841 @Test(timeout = 300000) 842 public void mouseClickingVerticalSingleTest() throws InterruptedException, Throwable { 843 commonClickingTest(Orientation.VERTICAL, SelectionMode.SINGLE); 844 } 845 846 @Smoke 847 @Test(timeout = 300000) 848 public void mouseClickingHorizontalSingleTest() throws InterruptedException, Throwable { 849 commonClickingTest(Orientation.HORIZONTAL, SelectionMode.SINGLE); 850 } 851 852 protected void commonClickingTest(Orientation orientation, SelectionMode selectionMode) throws InterruptedException, Throwable { 853 setSize(130, 130); 854 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 855 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.SINGLE, Properties.selectionMode); 856 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, selectionMode, Properties.selectionMode); 857 858 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, orientation, Properties.orientation); 859 for (int i = 1; i < listItems; i++) { 860 addElement(String.valueOf(Integer.valueOf((int) Math.round(Math.pow(i, i)))), i - 1); 861 } 862 863 selectionCycle(0, listItems - 1, null, selectionMode); 864 865 localReset(); 866 867 selectionCycle(0, listItems - 1, KeyboardButtons.SHIFT, selectionMode); 868 869 localReset(); 870 871 selectionCycle(0, listItems - 1, KeyboardButtons.CONTROL, selectionMode); 872 } 873 874 @Test(timeout = 300000) 875 /** 876 * Add big amount of elements in a list and select some of the according to 877 * some rule. After that checks, whether focus is correct. 878 */ 879 public void simpleSelectionScreenShotTest() throws InterruptedException, Throwable { 880 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 200); 881 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 200); 882 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 883 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 884 885 final int elementsCount = 15; 886 addAndSelectElements(elementsCount); 887 888 final int step = 6; 889 checkScreenshotsWithStep("SimpleTest", elementsCount, step); 890 } 891 892 @Test(timeout = 300000)//RT-18234 - possible 893 /** 894 * Add big amount of elements in a list and select some of the according to 895 * some rules. It tries to apply different combinations of keys pushing with 896 * modifiers. A few time in process it tries to check screenshots. 897 */ 898 public void complexSelectionScreenShotTest() throws InterruptedException, Throwable { 899 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 200); 900 setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 200); 901 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 902 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, Orientation.HORIZONTAL, Properties.orientation); 903 904 final int elementsCount = 50; 905 addAndSelectElements(elementsCount); 906 final int step = 5; 907 908 for (Orientation orientation : Orientation.values()) { 909 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, orientation, Properties.orientation); 910 Wrap<Text> cellWrap = getCellWrap((Integer) (0)); //mouse will be over the second item. 911 cellWrap.as(Showable.class).shower().show(); 912 cellWrap.mouse().click(1, cellWrap.getClickPoint(), Mouse.MouseButtons.BUTTON1, CTRL_DOWN_MASK_OS); 913 914 KeyboardButtons lessKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.LEFT : KeyboardButtons.UP); 915 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 916 917 applyKeysPushing(2, KeyboardButtons.PAGE_DOWN, KeyboardModifiers.SHIFT_DOWN_MASK); 918 applyKeysPushing(1, KeyboardButtons.PAGE_DOWN, CTRL_DOWN_MASK_OS); 919 applyKeysPushing(2, KeyboardButtons.PAGE_UP, KeyboardModifiers.SHIFT_DOWN_MASK); 920 applyKeysPushing(1, KeyboardButtons.PAGE_UP, CTRL_DOWN_MASK_OS); 921 922 applyKeysPushing(15, moreKey, CTRL_DOWN_MASK_OS); 923 for (int i = 0; i < 10; i++) { 924 if (Utils.isMacOS()) { 925 applyKeysPushing(i, KeyboardButtons.SPACE, CTRL_DOWN_MASK_OS, KeyboardModifiers.CTRL_DOWN_MASK); 926 } else { 927 applyKeysPushing(i, KeyboardButtons.SPACE, CTRL_DOWN_MASK_OS); 928 } 929 applyKeysPushing(2, lessKey, CTRL_DOWN_MASK_OS); 930 } 931 applyKeysPushing(5, lessKey, KeyboardModifiers.SHIFT_DOWN_MASK); 932 applyKeysPushing(1, KeyboardButtons.SPACE, KeyboardModifiers.SHIFT_DOWN_MASK); 933 applyKeysPushing(2, KeyboardButtons.PAGE_DOWN, CTRL_DOWN_MASK_OS); 934 checkScreenshotsWithStep("ComlexTests_" + orientation + "_1", elementsCount, step); 935 936 applyKeysPushing(1, KeyboardButtons.HOME, CTRL_DOWN_MASK_OS); 937 applyKeysPushing(1, KeyboardButtons.END, KeyboardModifiers.SHIFT_DOWN_MASK); 938 applyKeysPushing(1, KeyboardButtons.HOME, CTRL_DOWN_MASK_OS); 939 applyKeysPushing(1, KeyboardButtons.END, CTRL_DOWN_MASK_OS); 940 applyKeysPushing(1, KeyboardButtons.HOME, KeyboardModifiers.SHIFT_DOWN_MASK); 941 942 applyKeysPushing(20, lessKey, CTRL_DOWN_MASK_OS); 943 applyKeysPushing(5, moreKey, KeyboardModifiers.SHIFT_DOWN_MASK); 944 applyKeysPushing(3, moreKey, CTRL_DOWN_MASK_OS); 945 applyKeysPushing(2, KeyboardButtons.PAGE_UP, CTRL_DOWN_MASK_OS); 946 checkScreenshotsWithStep("ComlexTests_" + orientation + "_2", elementsCount, step); 947 } 948 } 949 950 @Test(timeout = 300000) 951 public void simpleSelectionUpTest() throws InterruptedException { 952 for (Orientation orientation : Orientation.values()) { 953 prepareSelectionHelper(orientation, 20); 954 955 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 956 957 applyKeysPushing(10, moreKey, CTRL_DOWN_MASK_OS); 958 959 moveSelectUp(5, orientation); 960 961 checkMainListeners(5, 5); 962 963 resetSceneByDefault(); 964 } 965 } 966 967 @Test(timeout = 300000) 968 public void simpleSelectionDownTest() throws InterruptedException { 969 for (Orientation orientation : Orientation.values()) { 970 prepareSelectionHelper(orientation, 20); 971 972 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 973 974 applyKeysPushing(10, moreKey, CTRL_DOWN_MASK_OS); 975 976 moveSelectDown(5, orientation); 977 978 checkMainListeners(15, 15); 979 980 resetSceneByDefault(); 981 } 982 } 983 984 @Test(timeout = 300000) 985 public void simpleMoveUpTest() throws InterruptedException { 986 for (Orientation orientation : Orientation.values()) { 987 prepareSelectionHelper(orientation, 20); 988 989 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 990 991 applyKeysPushing(10, moreKey, CTRL_DOWN_MASK_OS); 992 993 moveFocusUp(5, orientation); 994 995 checkMainListeners(5, 18); 996 997 resetSceneByDefault(); 998 } 999 } 1000 1001 @Test(timeout = 300000) 1002 public void simpleMoveDownTest() throws InterruptedException { 1003 for (Orientation orientation : Orientation.values()) { 1004 prepareSelectionHelper(orientation, 20); 1005 1006 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1007 1008 applyKeysPushing(10, moreKey, CTRL_DOWN_MASK_OS); 1009 1010 moveFocusDown(5, orientation); 1011 1012 checkMainListeners(15, 18); 1013 1014 resetSceneByDefault(); 1015 } 1016 } 1017 1018 @Test(timeout = 300000) 1019 public void simpleMovePageUpTest() throws InterruptedException { 1020 for (Orientation orientation : Orientation.values()) { 1021 prepareSelectionHelper(orientation, 20); 1022 selectionHelper.setPageHeight(8); 1023 selectionHelper.setPageWidth(1); 1024 1025 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1026 1027 applyKeysPushing(15, moreKey, CTRL_DOWN_MASK_OS); 1028 1029 moveFocusPageUp(1); 1030 1031 resetSceneByDefault(); 1032 } 1033 } 1034 1035 @Test(timeout = 300000) 1036 public void simpleMovePageDownTest() throws InterruptedException { 1037 for (Orientation orientation : Orientation.values()) { 1038 prepareSelectionHelper(orientation, 20); 1039 selectionHelper.setPageHeight(8); 1040 selectionHelper.setPageWidth(1); 1041 1042 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1043 1044 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1045 1046 moveFocusPageDown(1); 1047 1048 resetSceneByDefault(); 1049 } 1050 } 1051 1052 @Test(timeout = 300000) 1053 public void simpleSelectPageUpTest() throws InterruptedException { 1054 for (Orientation orientation : Orientation.values()) { 1055 prepareSelectionHelper(orientation, 20); 1056 selectionHelper.setPageHeight(8); 1057 selectionHelper.setPageWidth(1); 1058 1059 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1060 1061 applyKeysPushing(15, moreKey, CTRL_DOWN_MASK_OS); 1062 1063 moveSelectPageUp(1); 1064 1065 resetSceneByDefault(); 1066 } 1067 } 1068 1069 @Test(timeout = 300000) 1070 public void simpleSelectPageDownTest() throws InterruptedException { 1071 for (Orientation orientation : Orientation.values()) { 1072 prepareSelectionHelper(orientation, 20); 1073 selectionHelper.setPageHeight(8); 1074 selectionHelper.setPageWidth(1); 1075 1076 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1077 1078 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1079 1080 moveSelectPageDown(1); 1081 1082 resetSceneByDefault(); 1083 } 1084 } 1085 1086 @Test(timeout = 300000) 1087 public void simpleMoveHomeTest() throws InterruptedException { 1088 for (Orientation orientation : Orientation.values()) { 1089 prepareSelectionHelper(orientation, 20); 1090 1091 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1092 1093 applyKeysPushing(15, moreKey, CTRL_DOWN_MASK_OS); 1094 1095 moveToHome(); 1096 1097 checkMainListeners(0, 18); 1098 1099 resetSceneByDefault(); 1100 } 1101 1102 } 1103 1104 @Test(timeout = 300000) 1105 public void simpleMoveEndTest() throws InterruptedException { 1106 for (Orientation orientation : Orientation.values()) { 1107 prepareSelectionHelper(orientation, 20); 1108 1109 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1110 1111 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1112 1113 moveToEnd(); 1114 1115 checkMainListeners(19, 18); 1116 1117 resetSceneByDefault(); 1118 } 1119 } 1120 1121 @Test(timeout = 300000)//RT-18413 1122 public void simpleSelectHomeTest() throws InterruptedException { 1123 for (Orientation orientation : Orientation.values()) { 1124 prepareSelectionHelper(orientation, 20); 1125 1126 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1127 1128 applyKeysPushing(15, moreKey, CTRL_DOWN_MASK_OS); 1129 1130 selectToHome(); 1131 1132 checkMainListeners(0, 18); 1133 1134 resetSceneByDefault(); 1135 } 1136 } 1137 1138 @Test(timeout = 300000)//RT-18412 1139 public void simpleSelectEndTest() throws InterruptedException { 1140 for (Orientation orientation : Orientation.values()) { 1141 prepareSelectionHelper(orientation, 20); 1142 1143 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1144 1145 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1146 1147 selectToEnd(); 1148 1149 checkMainListeners(19, 19); 1150 1151 resetSceneByDefault(); 1152 } 1153 } 1154 1155 @Test(timeout = 60000) 1156 public void compositeSelectionTest() throws InterruptedException, Throwable { 1157 for (Orientation orientation : Orientation.values()) { 1158 final int elementsCount = 20; 1159 prepareSelectionHelper(orientation, elementsCount); 1160 selectionHelper.setPageHeight(8); 1161 selectionHelper.setPageWidth(1); 1162 1163 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1164 1165 applyKeysPushing(10, moreKey, CTRL_DOWN_MASK_OS);//we are in center 1166 1167 final int stepForScreenShotMaking = 8; 1168 1169 moveSelectUp(5, orientation); 1170 moveFocusPageDown(1); 1171 moveSelectUp(3, orientation); 1172 moveSelectPageUp(1); 1173 moveFocusDown(4, orientation); 1174 moveSelectUp(6, orientation); 1175 selectToHome(); 1176 moveSelectDown(4, orientation); 1177 checkScreenshotsWithStep("ComplexSelectionTest_1_" + orientation, elementsCount, stepForScreenShotMaking); 1178 selectToEnd(); 1179 moveFocusUp(3, orientation); 1180 moveSelectUp(5, orientation); 1181 moveToHome(); 1182 moveSelectPageDown(1); 1183 moveSelectDown(4, orientation); 1184 moveToEnd(); 1185 moveSelectDown(4, orientation); 1186 moveSelectUp(5, orientation); 1187 moveFocusPageUp(2); 1188 moveSelectDown(4, orientation); 1189 checkScreenshotsWithStep("ComplexSelectionTest_2_" + orientation, elementsCount, stepForScreenShotMaking); 1190 1191 resetSceneByDefault(); 1192 } 1193 } 1194 1195 @Test(timeout = 300000) 1196 public void selectionCancelTest() throws InterruptedException { 1197 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.HOME); 1198 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.END); 1199 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.UP); 1200 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.DOWN); 1201 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.LEFT); 1202 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.RIGHT); 1203 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.PAGE_UP); 1204 checkKeyboardButtonOnCancellingSelection(KeyboardButtons.PAGE_DOWN); 1205 } 1206 1207 @Test(timeout = 300000) 1208 public void focusTraversalSelectionSavingTest() throws InterruptedException { 1209 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.HORIZONTAL, KeyboardButtons.UP); 1210 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.HORIZONTAL, KeyboardButtons.DOWN); 1211 1212 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.VERTICAL, KeyboardButtons.RIGHT); 1213 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.VERTICAL, KeyboardButtons.LEFT); 1214 1215 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(KeyboardButtons.TAB); 1216 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(KeyboardButtons.TAB, KeyboardModifiers.SHIFT_DOWN_MASK); 1217 } 1218 1219 /** 1220 * Checks that when the sorting is applied to the underlying data collection 1221 * the cells are rendered in the right order. 1222 */ 1223 @Smoke 1224 @Test(timeout = 30000) 1225 public void renderingAfterSortingTest() { 1226 try { 1227 setSize(100, 218); 1228 } catch (InterruptedException ex) { 1229 System.out.println(ex); 1230 } 1231 1232 addElements(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100500); 1233 1234 final int ITEMS_COUNT = 9; 1235 1236 StringConverter<String> conv = new StringConverter<String>() { 1237 @Override 1238 public String toString(String t) { 1239 return t; 1240 } 1241 1242 @Override 1243 public String fromString(String s) { 1244 return s; 1245 } 1246 }; 1247 1248 SortValidator<String, ListCell> validator = new SortValidator<String, ListCell>(ITEMS_COUNT, conv) { 1249 @Override 1250 protected void setControlData(final ObservableList<String> ls) { 1251 new GetAction<Object>() { 1252 @Override 1253 public void run(Object... os) throws Exception { 1254 ListView listView = (ListView) testedControl.getControl(); 1255 listView.setItems(ls); 1256 } 1257 }.dispatch(testedControl.getEnvironment()); 1258 } 1259 1260 @Override 1261 protected Lookup<? extends ListCell> getCellsLookup() { 1262 return testedControl.as(Parent.class, Node.class) 1263 .lookup(ListCell.class, new LookupCriteria<ListCell>() { 1264 public boolean check(ListCell cell) { 1265 return cell.isVisible(); 1266 } 1267 }); 1268 } 1269 1270 @Override 1271 protected String getTextFromCell(ListCell cell) { 1272 return cell.getText(); 1273 } 1274 }; 1275 1276 boolean result = validator.check(); 1277 String msg = validator.getFailureReason(); 1278 assertTrue(msg, result); 1279 } 1280 1281 protected void checkKeyboardButtonOnCancellingSelection(KeyboardButtons button) throws InterruptedException { 1282 for (Orientation orientation : Orientation.values()) { 1283 prepareSelectionHelper(orientation, 10); 1284 selectionHelper.setPageHeight(8); 1285 selectionHelper.setPageWidth(1); 1286 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1287 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1288 if (!(orientation == Orientation.HORIZONTAL && (button == KeyboardButtons.UP || button == KeyboardButtons.DOWN)) 1289 && !(orientation == Orientation.VERTICAL && (button == KeyboardButtons.LEFT || button == KeyboardButtons.RIGHT))) //because it is focus traversal. 1290 { 1291 applyKeysPushing(1, button); 1292 } 1293 resetSceneByDefault(); 1294 } 1295 } 1296 1297 protected void checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(KeyboardButtons button, KeyboardModifiers... modifiers) throws InterruptedException { 1298 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.HORIZONTAL, button, modifiers); 1299 checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation.VERTICAL, button, modifiers); 1300 } 1301 1302 protected void checkKeyboardButtonOnNonCancellingSelectionBecauseTraversal(Orientation orientation, KeyboardButtons button, KeyboardModifiers... modifiers) throws InterruptedException { 1303 resetSceneByDefault(); 1304 requestFocusOnControl(testedControl); 1305 prepareSelectionHelper(orientation, 10); 1306 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1307 applyKeysPushing(5, moreKey, CTRL_DOWN_MASK_OS); 1308 1309 testedControl.keyboard().pushKey(button, modifiers); 1310 1311 checkSelection(); 1312 } 1313 1314 protected void checkMainListeners(int focusIndex, int selectedIndex) { 1315 checkListener(Listeners.focusedIndex, focusIndex); 1316 checkListener(Listeners.selectedIndex, selectedIndex); 1317 } 1318 1319 protected void checkMainListeners(int focusIndex, int editingIndex, int selectedIndex) { 1320 checkMainListeners(focusIndex, selectedIndex); 1321 checkListener(Listeners.editingIndex, editingIndex); 1322 } 1323 1324 protected void prepareSelectionHelper(Orientation orientation, int numberOfElements) throws InterruptedException { 1325 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, SelectionMode.MULTIPLE, Properties.selectionMode); 1326 setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, orientation, Properties.orientation); 1327 setSize(195, 195); 1328 1329 KeyboardButtons lessKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.LEFT : KeyboardButtons.UP); 1330 KeyboardButtons moreKey = (orientation == Orientation.HORIZONTAL ? KeyboardButtons.RIGHT : KeyboardButtons.DOWN); 1331 1332 selectionHelper = new MultipleSelectionHelper(1, numberOfElements); 1333 selectionHelper.setMultiple(true); 1334 1335 for (int i = 0; i < numberOfElements; i++) { 1336 addElement(String.valueOf(i * i), i); 1337 } 1338 1339 requestFocusOnControl(testedControl); 1340 1341 new GetAction() { 1342 @Override 1343 public void run(Object... os) throws Exception { 1344 ((ListView) testedControl.getControl()).getSelectionModel().clearSelection(); 1345 ((ListView) testedControl.getControl()).getFocusModel().focus(0); 1346 } 1347 }.dispatch(Root.ROOT.getEnvironment()); 1348 //testedControl.keyboard().pushKey(moreKey, CTRL_DOWN_MASK_OS); 1349 for (int i = 1; i < numberOfElements; i++) { 1350 applyKeysPushing(1, moreKey, CTRL_DOWN_MASK_OS); 1351 if (i % 2 == 0) { 1352 if (Utils.isMacOS()) { 1353 applyKeysPushing(1, KeyboardButtons.SPACE, CTRL_DOWN_MASK_OS, KeyboardModifiers.CTRL_DOWN_MASK); 1354 } else { 1355 applyKeysPushing(1, KeyboardButtons.SPACE, CTRL_DOWN_MASK_OS); 1356 } 1357 } 1358 } 1359 applyKeysPushing(numberOfElements, lessKey, CTRL_DOWN_MASK_OS); 1360 } 1361 }