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