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.textinput; 26 27 import client.test.Smoke; 28 import java.util.EnumSet; 29 import javafx.geometry.Orientation; 30 import javafx.scene.Node; 31 import javafx.scene.control.TextArea; 32 import javafx.scene.control.TextInputControl; 33 import javafx.scene.control.test.utils.ptables.AbstractPropertyController.SettingType; 34 import org.jemmy.interfaces.Keyboard; 35 import org.jemmy.interfaces.Keyboard.KeyboardButtons; 36 import org.jemmy.interfaces.Parent; 37 import org.junit.Assert; 38 import static org.junit.Assert.assertEquals; 39 import org.junit.Before; 40 import org.junit.BeforeClass; 41 import org.junit.Test; 42 import org.junit.runner.RunWith; 43 import test.javaclient.shared.FilteredTestRunner; 44 45 /** 46 * @author Alexander Kirov 47 */ 48 @RunWith(FilteredTestRunner.class) 49 public class TextAreaPropertiesTest extends TextControlCommonTests { 50 51 @BeforeClass 52 public static void setUpClass() throws Exception { 53 TextAreaPropertiesApp.main(null); 54 } 55 56 @Before 57 public void setup() throws InterruptedException { 58 setSize(200, 70); 59 } 60 61 @Smoke 62 @Test(timeout = 300000)//RT-18852 63 public void scrollLeftPropertyTest() throws InterruptedException, Throwable { 64 Assert.assertEquals((new TextArea()).scrollLeftProperty().getValue(), 0, 0); 65 commonScrollLeftTopTest(Orientation.HORIZONTAL, TextControlTestBase.Properties.scrollleft, "ContentScrolledLeft"); 66 } 67 68 @Smoke 69 @Test(timeout = 300000)//RT-18852 70 public void scrollTopPropertyTest() throws InterruptedException, Throwable { 71 Assert.assertEquals((new TextArea()).scrollTopProperty().getValue(), 0, 0); 72 commonScrollLeftTopTest(Orientation.VERTICAL, TextControlTestBase.Properties.scrolltop, "ContentScrolledDown"); 73 } 74 75 private void commonScrollLeftTopTest(Orientation orientation, TextControlTestBase.Properties property, String screenShotName) throws InterruptedException, Throwable { 76 setSize(200, 200); 77 addText(); 78 //There are both scrollBars must exist 79 80 assertEquals(getScrollBarValue(findScrollBar(testedControl.as(Parent.class, Node.class), orientation, true)), 0, 0); 81 82 double[] values = {10, 0, 50, 0, 100}; 83 84 setPropertyBySlider(SettingType.BIDIRECTIONAL, property, 10); 85 double item = getScrollBarValue(findScrollBar(testedControl.as(Parent.class, Node.class), orientation, true)) / 10; 86 87 for (SettingType type : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) { 88 for (double value : values) { 89 setPropertyBySlider(type, property, value); 90 checkTextFieldValue(property, value); 91 assertEquals(getScrollBarValue(findScrollBar(testedControl.as(Parent.class, Node.class), orientation, true)), value * item, 0.1 * item); 92 } 93 } 94 95 checkScreenshot(screenShotName + "On" + values[values.length - 1] + "Pixels", testedControl); 96 throwScreenshotError(); 97 } 98 99 @Smoke 100 @Test(timeout = 300000)//RT-18856 101 public void prefColumnCountPropertyTest() throws InterruptedException { 102 assertEquals((new TextArea()).prefColumnCountProperty().getValue(), 12, 0); 103 prefColumnCountCommonTest(); 104 } 105 106 @Smoke 107 @Test(timeout = 300000)//RT-18856 108 public void prefRowCountPropertyTest() throws InterruptedException { 109 int[] values = {5, 1, 0, 7, 5}; 110 double currentHeightPerRow = (getHeightValue(testedControl) - 10) / 10; // +/-10 is according to the minimal width. 111 112 for (SettingType type : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) { 113 for (int value : values) { 114 setPropertyBySlider(type, Properties.prefrowcount, value);//bind 115 checkTextFieldValue(Properties.prefrowcount, value);//getter 116 assertEquals(getHeightValue(testedControl), value * currentHeightPerRow + 10, 0.1 * currentHeightPerRow);//behavior 117 } 118 } 119 } 120 121 @Smoke 122 @Test(timeout = 300000) 123 public void wrapTextPropertyTest() throws InterruptedException { 124 setSize(70, 70); 125 126 String text = ""; 127 for (int i = 0; i < 15; i++) { 128 text += "text "; 129 } 130 131 setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.text, text); 132 133 for (SettingType type : EnumSet.of(SettingType.BIDIRECTIONAL, SettingType.SETTER, SettingType.UNIDIRECTIONAL)) { 134 setPropertyByToggleClick(type, Properties.wraptext);//true//bind 135 checkTextFieldText(Properties.wraptext, "true");//getter 136 Assert.assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, false) == null);//behavior 137 Assert.assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, true) == null);//behavior 138 139 setPropertyByToggleClick(type, Properties.wraptext);//false//bind 140 checkTextFieldText(Properties.wraptext, "false");//getter 141 Assert.assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.HORIZONTAL, true) == null);//behavior 142 Assert.assertFalse(findScrollBar(testedControl.as(Parent.class, Node.class), Orientation.VERTICAL, false) == null);//behavior 143 } 144 } 145 146 /** 147 * Test checks, that if control is focused and text is selected, it is blue, 148 * but when focused is lost, selected text becomes grey. Checking done with 149 * screenshot. 150 * 151 * @throws Throwable 152 */ 153 @Test(timeout = 300000) 154 @Smoke 155 public void focusedPropertyTest() throws Throwable { 156 final String text = "some text"; 157 setPropertyByTextField(SettingType.BIDIRECTIONAL, Properties.text, text); 158 159 checkTextFieldText(Properties.focused, "false"); 160 161 testedControl.mouse().click(); 162 testedControl.keyboard().pushKey(KeyboardButtons.A, CTRL_DOWN_MASK_OS); 163 164 checkTextFieldText(Properties.focused, "true"); 165 166 checkScreenshot("TextArea-focused-[blue]selection", testedControl); 167 168 testedControl.keyboard().pushKey(KeyboardButtons.TAB, Keyboard.KeyboardModifiers.CTRL_DOWN_MASK); 169 checkTextFieldText(Properties.focused, "false"); 170 171 checkScreenshot("TextArea-focused-[grey]selection", testedControl); 172 173 throwScreenshotError(); 174 } 175 176 @Override 177 protected TextInputControl getNewControl() { 178 return new TextArea(); 179 } 180 }