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.ScrollPane;
  26 
  27 import client.test.ScreenshotCheck;
  28 import client.test.Smoke;
  29 import com.oracle.jdk.sqe.cc.markup.Covers;
  30 import com.oracle.jdk.sqe.cc.markup.Covers.Level;
  31 import java.util.EnumSet;
  32 import javafx.geometry.Bounds;
  33 import javafx.geometry.Orientation;
  34 import javafx.scene.Group;
  35 import javafx.scene.Node;
  36 import javafx.scene.control.*;
  37 import javafx.scene.control.ScrollPane.ScrollBarPolicy;
  38 import static javafx.scene.control.test.ScrollPane.NewScrollPaneApp.*;
  39 import javafx.scene.control.test.util.ScrollingChecker;
  40 import javafx.scene.control.test.utils.ContentMotion;
  41 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType;
  42 import org.jemmy.Point;
  43 import org.jemmy.Rectangle;
  44 import org.jemmy.action.GetAction;
  45 import org.jemmy.control.Wrap;
  46 import org.jemmy.env.Timeout;
  47 import org.jemmy.fx.ByID;
  48 import org.jemmy.fx.NodeDock;
  49 import org.jemmy.fx.Root;
  50 import org.jemmy.fx.SceneDock;
  51 import org.jemmy.input.AbstractScroll;
  52 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  53 import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
  54 import org.jemmy.interfaces.Parent;
  55 import org.jemmy.timing.State;
  56 import org.junit.Assert;
  57 import org.junit.Before;
  58 import org.junit.Ignore;
  59 import org.junit.Test;
  60 import org.junit.runner.RunWith;
  61 import test.javaclient.shared.FilteredTestRunner;
  62 import test.javaclient.shared.Utils;
  63 
  64 /**
  65  * @author Alexander Kirov
  66  */
  67 @RunWith(FilteredTestRunner.class)
  68 public class ScrollPaneTest extends TestBase {
  69 
  70     @Before
  71     public void setUp() {
  72         initWrappers();
  73         scene.mouse().move(new Point(0, 0));
  74     }
  75 
  76     @Smoke
  77     @Test(timeout = 300000)
  78     @Covers(value = {"javafx.scene.control.ScrollPane.vmax.DEFAULT", "javafx.scene.control.ScrollPane.vmax.GET"}, level = Level.FULL)
  79     public void checkVMaxOptionTest() throws InterruptedException {
  80         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
  81         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
  82 
  83         Assert.assertEquals((new ScrollPane()).vmaxProperty().getValue(), 1, commonComparePrecision);
  84 
  85         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vmax, 200);
  86         checkTextFieldValue(Properties.vmax, 200);
  87 
  88         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vvalue, 200);
  89         checkTextFieldValue(Properties.vvalue, 200);
  90 
  91         Wrap<? extends ScrollBar> sb1 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true);
  92         sb1.as(AbstractScroll.class).to(0);
  93         checkTextFieldValue(Properties.vvalue, 0);
  94 
  95         Wrap<? extends ScrollBar> sb2 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true);
  96         sb2.as(AbstractScroll.class).to(200);
  97         checkTextFieldValue(Properties.vvalue, 200);
  98 
  99         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(-1 * (Utils.isMacOS() ? -1 : 1));
 100 
 101         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+1 * (Utils.isMacOS() ? -1 : 1));
 102         checkTextFieldValue(Properties.vvalue, 200);
 103 
 104         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.vmax, 150);
 105         checkTextFieldValue(Properties.vmax, 150);
 106 
 107         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.vmax, -150);
 108         checkTextFieldValue(Properties.vmax, -100);
 109     }
 110 
 111     @Smoke
 112     @Test(timeout = 300000)
 113     @Covers(value = {"javafx.scene.control.ScrollPane.vmin.DEFAULT", "javafx.scene.control.ScrollPane.vmin.GET"}, level = Level.FULL)
 114     public void checkVMinOptionTest() throws InterruptedException {
 115         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 116         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 117 
 118         Assert.assertEquals((new ScrollPane()).vminProperty().getValue(), 0, commonComparePrecision);
 119 
 120         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vmin, -100);
 121         checkTextFieldValue(Properties.vmin, -100);
 122 
 123         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vvalue, -100);
 124         checkTextFieldValue(Properties.vvalue, -100);
 125 
 126         Wrap<? extends ScrollBar> sb1 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true);
 127         sb1.as(AbstractScroll.class).to(1);
 128         checkTextFieldValue(Properties.vvalue, 1);
 129 
 130         Wrap<? extends ScrollBar> sb2 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true);
 131         sb2.as(AbstractScroll.class).to(-100);
 132         checkTextFieldValue(Properties.vvalue, -100);
 133 
 134         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(+1 * (Utils.isMacOS() ? -1 : 1));
 135 
 136         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).mouse().turnWheel(-1 * (Utils.isMacOS() ? -1 : 1));
 137         checkTextFieldValue(Properties.vvalue, -100);
 138 
 139         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.vmin, -50);
 140         checkTextFieldValue(Properties.vmin, -50);
 141 
 142         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.vmin, +150);
 143         checkTextFieldValue(Properties.vmin, +150);
 144     }
 145 
 146     @Smoke
 147     @Test(timeout = 300000)
 148     @Covers(value = {"javafx.scene.control.ScrollPane.hmax.DEFAULT", "javafx.scene.control.ScrollPane.hmax.GET"}, level = Level.FULL)
 149     public void checkHMaxOptionTest() throws InterruptedException {
 150         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 151         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 152 
 153         Assert.assertEquals((new ScrollPane()).hmaxProperty().getValue(), 1, commonComparePrecision);
 154 
 155         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hmax, 200);
 156         checkTextFieldValue(Properties.hmax, 200);
 157 
 158         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hvalue, 200);
 159         checkTextFieldValue(Properties.hvalue, 200);
 160 
 161         Wrap<? extends ScrollBar> sb1 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true);
 162         sb1.as(AbstractScroll.class).to(0);
 163         checkTextFieldValue(Properties.hvalue, 0);
 164 
 165         Wrap<? extends ScrollBar> sb2 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true);
 166         sb2.as(AbstractScroll.class).to(200);
 167         checkTextFieldValue(Properties.hvalue, 200);
 168 
 169         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(-1);
 170 
 171         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+1);
 172         checkTextFieldValue(Properties.hvalue, 200);
 173 
 174         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.hmax, 150);
 175         checkTextFieldValue(Properties.hmax, 150);
 176 
 177         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.hmax, -150);
 178         checkTextFieldValue(Properties.hmax, -100);
 179     }
 180 
 181     @Smoke
 182     @Test(timeout = 300000)
 183     @Covers(value = {"javafx.scene.control.ScrollPane.hmin.DEFAULT", "javafx.scene.control.ScrollPane.hmin.GET"}, level = Level.FULL)
 184     public void checkHMinOptionTest() throws InterruptedException {
 185         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 186         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 187 
 188         Assert.assertEquals((new ScrollPane()).vminProperty().getValue(), 0, commonComparePrecision);
 189 
 190         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hmin, -100);
 191         checkTextFieldValue(Properties.hmin, -100);
 192 
 193         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hvalue, -100);
 194         checkTextFieldValue(Properties.hvalue, -100);
 195 
 196         Wrap<? extends ScrollBar> sb1 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true);
 197         sb1.as(AbstractScroll.class).to(1);
 198         checkTextFieldValue(Properties.hvalue, 1);
 199 
 200         Wrap<? extends ScrollBar> sb2 = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true);
 201         sb2.as(AbstractScroll.class).to(-100);
 202         checkTextFieldValue(Properties.hvalue, -100);
 203 
 204         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(+1);
 205 
 206         findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).mouse().turnWheel(-1);
 207         checkTextFieldValue(Properties.hvalue, -100);
 208 
 209         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.hmin, -50);
 210         checkTextFieldValue(Properties.hmin, -50);
 211 
 212         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.hmin, +150);
 213         checkTextFieldValue(Properties.hmin, +150);
 214     }
 215 
 216     @ScreenshotCheck
 217     @Test(timeout = 300000)
 218     public void checkH_V_ValueOptionTest() throws InterruptedException, Throwable {
 219         Assert.assertEquals((new ScrollPane()).hvalueProperty().getValue(), 0, commonComparePrecision);
 220         Assert.assertEquals((new ScrollPane()).vvalueProperty().getValue(), 0, commonComparePrecision);
 221 
 222         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 223         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 224 
 225         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hvalue, 200);
 226         checkTextFieldValue(Properties.hvalue, 1);
 227 
 228         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vvalue, 200);
 229         checkTextFieldValue(Properties.vvalue, 1);
 230 
 231         checkScreenshot("ScrollPane_H_V_Values_test", testedControl);
 232         throwScreenshotError();
 233     }
 234 
 235     /**
 236      * Assume, that scrollPane contain rectangle 200X200 pixels
 237      */
 238     @Smoke
 239     @Test(timeout = 300000)
 240     @Covers(value = {"javafx.scene.control.ScrollPane.prefViewportHeight.GET", "javafx.scene.control.ScrollPane.prefViewportHeight.DEFAULT"}, level = Level.FULL)
 241     public void checkPrefViewPortHeightOptionTest() throws InterruptedException {
 242         Assert.assertEquals((new ScrollPane()).prefViewportHeightProperty().getValue(), 0, commonComparePrecision);
 243 
 244         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 150);
 245         checkTextFieldValue(Properties.prefViewportHeight, 150);
 246         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) == null);
 247 
 248         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefViewportHeight, 230);
 249         checkTextFieldValue(Properties.prefViewportHeight, 230);
 250         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null);
 251     }
 252 
 253     /**
 254      * Assume, that scrollPane contain rectangle 200X200 pixels
 255      */
 256     @Smoke
 257     @Test(timeout = 300000)
 258     @Covers(value = {"javafx.scene.control.ScrollPane.prefViewportWidth.GET", "javafx.scene.control.ScrollPane.prefViewportWidth.DEFAULT"}, level = Level.FULL)
 259     public void checkPrefViewPortWidthOptionTest() throws InterruptedException {
 260         Assert.assertEquals((new ScrollPane()).prefViewportWidthProperty().getValue(), 0, commonComparePrecision);
 261 
 262         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 150);
 263         checkTextFieldValue(Properties.prefViewportWidth, 150);
 264         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) == null);
 265 
 266         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.prefViewportWidth, 230);
 267         checkTextFieldValue(Properties.prefViewportWidth, 230);
 268         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, false) == null);
 269     }
 270 
 271     @Test(timeout = 300000)
 272     @Covers(value = {"javafx.scene.control.ScrollPane.prefViewportWidth.GET", "javafx.scene.control.ScrollPane.prefViewportWidth.DEFAULT"}, level = Level.FULL)
 273     public void checkMinViewPortWidthSetTest() throws InterruptedException {
 274         Assert.assertEquals((new ScrollPane()).prefViewportWidthProperty().getValue(), 0, commonComparePrecision);
 275         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.minViewportWidth, 600);
 276         checkTextFieldValue(Properties.width, 600, 20);
 277     }
 278 
 279     @Smoke
 280     @Test(timeout = 300000)//Property affecting is verified in other test.
 281     @Covers(value = {"javafx.scene.control.ScrollPane.pannable.GET", "javafx.scene.control.ScrollPane.pannable.DEFAULT"}, level = Level.FULL)
 282     public void checkPannableOptionTest() throws InterruptedException {
 283         Assert.assertFalse((new ScrollPane()).pannableProperty().getValue());
 284 
 285         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, TestBase.Properties.pannable);
 286         checkTextFieldText(Properties.pannable, "true");
 287 
 288         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, TestBase.Properties.pannable);
 289         checkTextFieldText(Properties.pannable, "false");
 290 
 291         setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, TestBase.Properties.pannable);
 292         checkTextFieldText(Properties.pannable, "true");
 293 
 294         setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, TestBase.Properties.pannable);
 295         checkTextFieldText(Properties.pannable, "false");
 296     }
 297 
 298     @Smoke
 299     @Test(timeout = 300000)
 300     @Covers(value = {"javafx.scene.control.ScrollPane.fitToHeight.GET", "javafx.scene.control.ScrollPane.fitToHeight.DEFAULT",
 301         "javafx.scene.control.ScrollPane.fitToWidth.GET", "javafx.scene.control.ScrollPane.fitToWidth.DEFAULT"}, level = Level.FULL)
 302     public void checkFitToWidthAndHeightOptionTest() throws InterruptedException, Throwable {
 303         Assert.assertEquals((new ScrollPane()).fitToWidthProperty().getValue(), false);
 304         Assert.assertEquals((new ScrollPane()).fitToHeightProperty().getValue(), false);
 305 
 306         changeContentToResizable();
 307 
 308         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.fitToWidth);
 309         checkTextFieldText(Properties.fitToWidth, "true");
 310 
 311         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.fitToWidth);
 312         checkTextFieldText(Properties.fitToWidth, "false");
 313 
 314         setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.fitToWidth);
 315         checkTextFieldText(Properties.fitToWidth, "true");
 316 
 317         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.fitToHeight);
 318         checkTextFieldText(Properties.fitToHeight, "true");
 319 
 320         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.fitToHeight);
 321         checkTextFieldText(Properties.fitToHeight, "false");
 322 
 323         setPropertyByToggleClick(SettingType.UNIDIRECTIONAL, Properties.fitToHeight);
 324         checkTextFieldText(Properties.fitToHeight, "true");
 325 
 326         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 200);
 327         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 200);
 328 
 329         checkScreenshot("ScrollPane_fitToSize", testedControl);
 330         throwScreenshotError();
 331     }
 332 
 333     private enum Influence {
 334 
 335         INSIDEOUT, OUTSIDEIN
 336     };
 337 
 338     private void checkScrollbarsVisibility(boolean horizontalVisible, boolean verticalVisible) {
 339         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, horizontalVisible) == null);
 340         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, verticalVisible) == null);
 341     }
 342 
 343     @Smoke
 344     @Test(timeout = 300000)//RT-17395
 345     @Covers(value = {"javafx.scene.control.ScrollPane.vbarPolicy.GET", "javafx.scene.control.ScrollPane.vbarPolicy.DEFAULT",
 346         "javafx.scene.control.ScrollPane.hbarPolicy.GET", "javafx.scene.control.ScrollPane.hbarPolicy.DEFAULT"}, level = Level.FULL)
 347     public void checkHVBarPolicyOptionTest() throws InterruptedException {
 348         Assert.assertTrue((new ScrollPane()).vbarPolicyProperty().getValue() == ScrollBarPolicy.AS_NEEDED);
 349         Assert.assertTrue((new ScrollPane()).hbarPolicyProperty().getValue() == ScrollBarPolicy.AS_NEEDED);
 350 
 351         for (SettingType btype : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) {
 352             for (Influence influence : EnumSet.of(Influence.INSIDEOUT, Influence.OUTSIDEIN)) {
 353                 for (ScrollPane.ScrollBarPolicy policy : EnumSet.of(ScrollPane.ScrollBarPolicy.ALWAYS, ScrollPane.ScrollBarPolicy.AS_NEEDED, ScrollPane.ScrollBarPolicy.NEVER)) {
 354                     //Content size == 100X100
 355                     setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 200);
 356                     setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 200);
 357 
 358                     setPropertyByChoiceBox(btype, policy, Properties.hbarPolicy);
 359                     setPropertyByChoiceBox(btype, policy, Properties.vbarPolicy);
 360                     checkTextFieldText(Properties.hbarPolicy, policy.name());
 361                     checkTextFieldText(Properties.vbarPolicy, policy.name());
 362 
 363                     switch (policy) {
 364                         case ALWAYS:
 365                             checkScrollbarsVisibility(true, true);
 366                             break;
 367                         case AS_NEEDED:
 368                             checkScrollbarsVisibility(false, false);
 369                             break;
 370                         case NEVER:
 371                             checkScrollbarsVisibility(false, false);
 372                             break;
 373                     }
 374 
 375                     if (influence == Influence.INSIDEOUT) {
 376                         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 230);
 377                         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 230);
 378 
 379                     } else { // Influence.OUTSIDEIN
 380                         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 50);
 381                         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 50);
 382 
 383                     }
 384 
 385                     switch (policy) {
 386                         case ALWAYS:
 387                             checkScrollbarsVisibility(true, true);
 388                             break;
 389                         case AS_NEEDED:
 390                             checkScrollbarsVisibility(false, false);
 391                             break;
 392                         case NEVER:
 393                             checkScrollbarsVisibility(false, false);
 394                             break;
 395                     }
 396                 }
 397             }
 398         }
 399     }
 400 
 401     @ScreenshotCheck
 402     @Test(timeout = 300000)
 403     public void contentRotationTest() throws InterruptedException, Throwable {
 404         rotateContent();
 405         checkScreenshot("ScrollPaneRotatedContent", testedControl);
 406         throwScreenshotError();
 407     }
 408 
 409     @ScreenshotCheck
 410     @Test(timeout = 300000)
 411     public void contentScalingTest() throws InterruptedException, Throwable {
 412         increaseContentScale();
 413         checkScreenshot("ScrollPaneScaledContent", testedControl);
 414         throwScreenshotError();
 415     }
 416 
 417     @ScreenshotCheck
 418     @Test(timeout = 300000)
 419     public void dynamicContentChangingTest() throws Throwable {
 420         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 421         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 422 
 423         changeContent();
 424         //If content has really changed, button will be searchable.
 425         //If content didn't change, button won't be on scene.
 426         clickContentButton();
 427 
 428         checkScreenshot("ScrollPane_DynamicContentChanging", testedControl);
 429         throwScreenshotError();
 430     }
 431 
 432     @ScreenshotCheck
 433     @Test(timeout = 300000)//RT-17335
 434     public void resizingTest() throws InterruptedException, Throwable {
 435         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 200);
 436         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 200);
 437 
 438         currentSettingOption = SettingOption.MANUAL;
 439         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 20);
 440         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 20);
 441 
 442         currentSettingOption = SettingOption.PROGRAM;
 443         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 100);
 444         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 100);
 445 
 446         checkScreenshot("ScrollPaneAfterResizing", testedControl);
 447         throwScreenshotError();
 448     }
 449 
 450     @Smoke
 451     @Test(timeout = 300000)//RT-17368
 452     public void viewPortPrefSizeTest() throws InterruptedException {
 453         changeContentToResizable();
 454         double[] sizes = {100, 50, 40, 55};
 455 
 456         for (Double size : sizes) {
 457 
 458             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, size);
 459             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, size);
 460 
 461             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, size * 2);
 462             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, size * 2);
 463 
 464             Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) == null);
 465             Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) == null);
 466 
 467             Point controlSize = new GetAction<Point>() {
 468                 @Override
 469                 public void run(Object... os) throws Exception {
 470                     setResult(new Point(((ScrollPane) os[0]).getWidth(), ((ScrollPane) os[0]).getHeight()));
 471                 }
 472             }.dispatch(Root.ROOT.getEnvironment(), testedControl.getControl());
 473 
 474             Point viewPortSize = new GetAction<Point>() {
 475                 @Override
 476                 public void run(Object... os) throws Exception {
 477                     setResult(new Point(((ScrollPane) os[0]).getPrefViewportWidth(), ((ScrollPane) os[0]).getPrefViewportHeight()));
 478                 }
 479             }.dispatch(Root.ROOT.getEnvironment(), testedControl.getControl());
 480 
 481             double verticalScrollBarWidth = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).getScreenBounds().width;
 482             double horizontalScrollBarHeight = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).getScreenBounds().height;
 483 
 484             Assert.assertEquals(viewPortSize.x + verticalScrollBarWidth, controlSize.x, commonComparePrecision);
 485             Assert.assertEquals(viewPortSize.y + horizontalScrollBarHeight, controlSize.y, commonComparePrecision);
 486         }
 487     }
 488 
 489     @ScreenshotCheck
 490     @Test(timeout = 300000)
 491     public void whiteGapTest() throws InterruptedException, Throwable {
 492         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 493         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 494 
 495         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hmax, 200);
 496         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hmin, 50);
 497         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hvalue, 200);
 498 
 499         checkScreenshot("ScrollPane_WhiteGapTest", testedControl);
 500         throwScreenshotError();
 501     }
 502 
 503     @Smoke
 504     @Test(timeout = 300000)//(expected=java.lang.RuntimeException.class) //RT-17334
 505     public void unidirectionalBindingForVHValueTest() throws InterruptedException {
 506         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.vvalue, 200);
 507         setPropertyBySlider(SettingType.UNIDIRECTIONAL, Properties.hvalue, 200);
 508     }
 509 
 510     @ScreenshotCheck
 511     @Test(timeout = 300000)//RT-17350
 512     public void immediateHVBarPoliticApplyingTest() throws Throwable {
 513         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 514         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 515 
 516         setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, ScrollPane.ScrollBarPolicy.ALWAYS, Properties.hbarPolicy);
 517         setPropertyByChoiceBox(SettingType.BIDIRECTIONAL, ScrollPane.ScrollBarPolicy.NEVER, Properties.hbarPolicy);
 518 
 519         //There must not be horizontal bar.
 520         checkScreenshot("ScrollPane_PoliticApplyingTest", testedControl);
 521         throwScreenshotError();
 522     }
 523 
 524     @ScreenshotCheck
 525     @Test(timeout = 300000) //RT-17365
 526     public void contentMovingTest() throws InterruptedException, Throwable {
 527         contentMotionStart();
 528 
 529         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 100);
 530         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 100);
 531 
 532         Thread.sleep(ContentMotion.motionDuration + 1000);
 533 
 534         checkScreenshot("ScrollPane_ContentMovingTest", testedControl);
 535         throwScreenshotError();
 536     }
 537 
 538     @Smoke
 539     @Test(timeout = 300000)
 540     public void contentReceiveMouseEventsTest() {
 541         changeContent();
 542         clickContentButton();
 543 
 544         checkContentTextFieldValue(1);
 545     }
 546 
 547     @Smoke
 548     private void checkFocusStates(boolean buttonFocus, boolean textFieldFocus, boolean textAreaFocus, boolean emptyButtonFocus) {
 549         checkFocus(CONTENT_BUTTON, buttonFocus);
 550         checkFocus(CONTENT_TEXT_FIELD_ID, textFieldFocus);
 551         checkFocus(CONTENT_TEXT_AREA_ID, textAreaFocus);
 552         checkFocus(WITHOUT_ACTION_BUTTON, emptyButtonFocus);
 553     }
 554 
 555     @ScreenshotCheck
 556     @Test(timeout = 300000)
 557     public void insideTraversalCheckTest() throws Throwable {
 558         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, 100);
 559         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, 100);
 560 
 561         changeContent();
 562         clickContentButton();
 563 
 564         Wrap<? extends Button> buttonWrap = parent.lookup(Button.class, new ByID<Button>(CONTENT_BUTTON)).wrap();
 565         buttonWrap.mouse().click();
 566         checkFocusStates(true, false, false, false);
 567         checkScreenshot("ScrollPane_InnerTraversal_1_Test", testedControl);
 568 
 569         buttonWrap.keyboard().pushKey(KeyboardButtons.TAB);
 570         checkFocusStates(false, true, false, false);
 571         checkScreenshot("ScrollPane_InnerTraversal_2_Test", testedControl);
 572 
 573         parent.lookup(TextField.class, new ByID<TextField>(CONTENT_TEXT_FIELD_ID)).wrap().keyboard().pushKey(KeyboardButtons.TAB);
 574         checkFocusStates(false, false, true, false);
 575         checkScreenshot("ScrollPane_InnerTraversal_3_Test", testedControl);
 576 
 577         parent.lookup(TextArea.class, new ByID<TextArea>(CONTENT_TEXT_AREA_ID)).wrap().keyboard().pushKey(KeyboardButtons.TAB, KeyboardModifiers.CTRL_DOWN_MASK);
 578         checkFocusStates(false, false, false, true);
 579         checkScreenshot("ScrollPane_InnerTraversal_4_Test", testedControl);
 580 
 581         throwScreenshotError();
 582     }
 583 
 584     @Smoke
 585     @Test(timeout = 300000)//RT-17378
 586     public void contentSizeDetectionAndScrolls() throws InterruptedException, Throwable {
 587         SettingOption temp = currentSettingOption;
 588         currentSettingOption = SettingOption.PROGRAM;
 589         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 201);
 590         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 201);
 591 
 592         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, false) == null);
 593         Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null);
 594 
 595         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 200);
 596         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 200);
 597 
 598         Assert.assertTrue(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) != null);
 599         Assert.assertTrue(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) != null);
 600 
 601         currentSettingOption = temp;
 602     }
 603 
 604     @Smoke
 605     @Test(timeout = 300000)//RT-17380
 606     public void focusFromOutsideTest() {
 607         changeContent();
 608         parent.lookup(Button.class, new ByID<Button>(CHANGE_CONTENT_BUTTON_ID)).wrap().keyboard().pushKey(KeyboardButtons.UP);
 609 
 610         parent.lookup(Button.class, new ByID<Button>(WITHOUT_ACTION_BUTTON)).wrap().waitProperty("isFocused", true);
 611     }
 612 
 613     private void makeDND(int initialDeltaX, int initialDeltaY, int deltaX, int deltaY) throws InterruptedException {
 614         Wrap<? extends Group> group = parent.lookup(Group.class, new ByID<Group>(CUSTOM_CONTENT_ID)).wrap();
 615         Point fromPoint = group.getClickPoint();
 616 
 617         fromPoint.x += initialDeltaX;
 618         fromPoint.y += initialDeltaY;
 619         Point toPoint = new Point(fromPoint.x + deltaX, fromPoint.y + deltaY);
 620 
 621         NodeDock groupDock = new NodeDock(parent, new ByID<Node>(CUSTOM_CONTENT_ID));
 622 
 623         groupDock.drag().dnd(fromPoint, groupDock.wrap(), toPoint);
 624     }
 625 
 626     @ScreenshotCheck
 627     @Smoke
 628     @Test(timeout = 300000)
 629     public void panningTest() throws Throwable {
 630         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.pannable);
 631         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 150);
 632         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 150);
 633 
 634         makeDND(-30, -30, -150, -150);
 635         checkTextFieldValue(Properties.hvalue, 1);
 636         checkTextFieldValue(Properties.vvalue, 1);
 637 
 638         makeDND(30, 30, -150, 150);
 639         checkTextFieldValue(Properties.hvalue, 1);
 640         checkTextFieldValue(Properties.vvalue, 0);
 641 
 642         makeDND(30, -30, 150, -150);
 643         checkTextFieldValue(Properties.hvalue, 0);
 644         checkTextFieldValue(Properties.vvalue, 1);
 645 
 646         makeDND(-30, 30, 150, 150);
 647         checkTextFieldValue(Properties.hvalue, 0);
 648         checkTextFieldValue(Properties.vvalue, 0);
 649 
 650         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.pannable);
 651 
 652         makeDND(-30, -30, -150, -150);
 653         checkTextFieldValue(Properties.hvalue, 0);
 654         checkTextFieldValue(Properties.vvalue, 0);
 655         checkScreenshot("ScrollPane_PanningTest", testedControl);
 656         throwScreenshotError();
 657     }
 658 
 659     @Smoke
 660     @Test(timeout = 300000)
 661     public void longRotativeDND() throws InterruptedException {
 662         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.pannable);
 663         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 150);
 664         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 150);
 665 
 666         final int mouseSmoothness = getMouseSmoothness();
 667         int newMouseSmoothness = 3;
 668         setMouseSmoothness(newMouseSmoothness);
 669 
 670         final double R = 120;
 671         final double alpha = 0.1;
 672         double angle = 0;
 673         final Point initialPoint = testedControl.getClickPoint();
 674         final int numPoints = 500;
 675 
 676         Point next;
 677 
 678         testedControl.mouse().move(initialPoint);
 679         testedControl.mouse().press();
 680         testedControl.getEnvironment().getExecutor().waitQuiet(new Timeout("", 500));
 681 
 682         final double EPS = alpha / 2;
 683         for (int i = 0; i < numPoints; i++) {
 684             next = new Point(initialPoint.x + R * Math.sin(angle), initialPoint.y + R * Math.cos(angle));
 685             testedControl.mouse().move(next);
 686             final double DELTA = 0.05;
 687 
 688             if (Math.abs(angle - Math.PI / 4) < EPS) {
 689                 checkTextFieldValue(Properties.hvalue, 0, DELTA);
 690                 checkTextFieldValue(Properties.vvalue, 0, DELTA);
 691             } else if (Math.abs(angle - 3 * Math.PI / 4) < EPS) {
 692                 checkTextFieldValue(Properties.hvalue, 0, DELTA);
 693                 checkTextFieldValue(Properties.vvalue, 1, DELTA);
 694             } else if (Math.abs(angle - 5 * Math.PI / 4) < EPS) {
 695                 checkTextFieldValue(Properties.hvalue, 1, DELTA);
 696                 checkTextFieldValue(Properties.vvalue, 1, DELTA);
 697             } else if (Math.abs(angle - 7 * Math.PI / 4) < EPS) {
 698                 checkTextFieldValue(Properties.hvalue, 1, DELTA);
 699                 checkTextFieldValue(Properties.vvalue, 0, DELTA);
 700             }
 701 
 702             angle += alpha;
 703             if (angle > 2 * Math.PI) {
 704                 angle -= 2 * Math.PI;
 705             }
 706         }
 707 
 708         scene.mouse().move(new Point(0, 0));
 709         testedControl.mouse().release();
 710 
 711         setMouseSmoothness(mouseSmoothness);
 712 
 713         checkSimpleListenerValue(Properties.hvalue, "1.0");
 714         checkSimpleListenerValue(Properties.vvalue, "1.0");
 715     }
 716 
 717     private void tryToMove(int initX, int initY, int deltaX, int deltaY) throws InterruptedException {
 718         Wrap<? extends Group> wrap = parent.lookup(Group.class, new ByID<Group>(CUSTOM_CONTENT_ID)).wrap();
 719         Point before = new Point(wrap.getScreenBounds().x, wrap.getScreenBounds().y);
 720         makeDND(initX, initY, deltaX, deltaY);
 721         Point after = new Point(wrap.getScreenBounds().x, wrap.getScreenBounds().y);
 722         //assert that the maximum difference in coordinates is less or equal 1 pixel
 723         final Point expected = new Point(deltaX, deltaY);
 724         final Point actual = new Point(after.x - before.x, after.y - before.y);
 725 
 726         int dx = expected.x - actual.x;
 727         int dy = expected.y - actual.y;
 728         int distance_squared = dx * dx + dy * dy;
 729 
 730         Assert.assertTrue("[Expected point is too far from actual]", distance_squared <= 2);
 731     }
 732 
 733     @Smoke
 734     @Test(timeout = 300000)
 735     public void panningAndMouseMovementCompare() throws InterruptedException {
 736         setPropertyByToggleClick(SettingType.BIDIRECTIONAL, Properties.pannable);
 737         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 100);
 738         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 100);
 739 
 740         tryToMove(-75, -75, -50, -50);
 741         tryToMove(-25, -25, 50, -50);
 742         tryToMove(-75, 25, -50, 50);
 743         tryToMove(-25, -25, -50, -50);
 744     }
 745 
 746     //Test//Switched off, because developers don't fix such bugs.
 747     public void steadyScrollingTest() throws InterruptedException {
 748         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, 100);
 749         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, 100);
 750 
 751         Wrap<? extends ScrollBar> vertical = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true);
 752         Wrap<? extends ScrollBar> horizontal = findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true);
 753 
 754         ScrollingChecker scV = new ScrollingChecker(vertical.getControl().valueProperty());
 755         ScrollingChecker scH = new ScrollingChecker(horizontal.getControl().valueProperty());
 756         for (int i = 0; i < 10; i++) {
 757             vertical.mouse().turnWheel(+1);
 758             scV.checkChanging(+1);
 759 
 760             horizontal.mouse().turnWheel(+1);
 761             scH.checkChanging(+1);
 762         }
 763 
 764         vertical.mouse().turnWheel(-17);
 765         horizontal.mouse().turnWheel(-17);
 766 
 767         changeContent();
 768 
 769         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.hvalue, 0);
 770         setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.vvalue, 0);
 771 
 772         ScrollingChecker sc = new ScrollingChecker(vertical.getControl().valueProperty());
 773 
 774         for (int i = 0; i < 17; i++) {
 775             vertical.mouse().turnWheel(+1);
 776             sc.checkChanging(+1);
 777         }
 778     }
 779 
 780     @Smoke
 781     @Test(timeout = 300000)//RT-17368
 782     @Covers(value = "javafx.scene.control.ScrollPane.viewportBounds.GET", level = Level.FULL)
 783     public void boundsTest() throws InterruptedException {
 784         changeContentToResizable();
 785         double[] sizes = {100, 50, 40, 55};
 786 
 787         for (Double size : sizes) {
 788 
 789             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportHeight, size);
 790             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefViewportWidth, size);
 791 
 792             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefHeight, size * 2);
 793             setPropertyBySlider(SettingType.BIDIRECTIONAL, Properties.prefWidth, size * 2);
 794 
 795             Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) == null);
 796             Assert.assertFalse(findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) == null);
 797 
 798             Bounds bounds = new GetAction<Bounds>() {
 799                 @Override
 800                 public void run(Object... os) throws Exception {
 801                     setResult(((ScrollPane) os[0]).getViewportBounds());
 802                 }
 803             }.dispatch(Root.ROOT.getEnvironment(), testedControl.getControl());
 804 
 805             Point viewPortSize = new GetAction<Point>() {
 806                 @Override
 807                 public void run(Object... os) throws Exception {
 808                     setResult(new Point(((ScrollPane) os[0]).getPrefViewportWidth(), ((ScrollPane) os[0]).getPrefViewportHeight()));
 809                 }
 810             }.dispatch(Root.ROOT.getEnvironment(), testedControl.getControl());
 811 
 812             Assert.assertEquals(viewPortSize.x, bounds.getWidth() + findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true).getScreenBounds().getWidth(), commonComparePrecision);
 813             Assert.assertEquals(viewPortSize.y, bounds.getHeight() + findScrollBar((Parent<Node>) testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true).getScreenBounds().getHeight(), commonComparePrecision);
 814         }
 815     }
 816 
 817     @Ignore //due to http://javafx-jira.kenai.com/browse/RT-27467
 818     @Smoke
 819     @Test(timeout = 30000)
 820     /**
 821      * Test checks method scrollTo of the control.
 822      */
 823     public void scrollToTest() {
 824         addGrid(10);
 825         scrollToCommonTest("B-5-5");
 826         scrollToCommonTest("B-9-0");
 827         scrollToCommonTest("B-0-9");
 828         scrollToCommonTest("B-9-9");
 829         scrollToCommonTest("B-0-0");
 830     }
 831 
 832     private void scrollToCommonTest(String name) {
 833         scrollTo(name);
 834         final Wrap<? extends Button> buttonInGrid = getButtonInGrid(name);
 835 
 836         testedControl.waitState(new State() {
 837             public Object reached() {
 838                 final Point clickPoint = buttonInGrid.getClickPoint();
 839                 final Rectangle buttonBounds = buttonInGrid.getScreenBounds();
 840                 if (testedControl.getScreenBounds().contains(new Point(buttonBounds.getX() + clickPoint.x, buttonBounds.getY() + clickPoint.y))) {
 841                     return true;
 842                 }
 843                 return null;
 844             }
 845         });
 846     }
 847 }