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.Mnemonics; 26 27 import client.test.Smoke; 28 import javafx.scene.Node; 29 import javafx.scene.control.Button; 30 import javafx.scene.control.CheckBox; 31 import javafx.scene.control.Label; 32 import static javafx.scene.control.test.Mnemonics.MnemonicsTestBase.scene; 33 import org.jemmy.control.Wrap; 34 import org.jemmy.env.Timeout; 35 import org.jemmy.fx.ByID; 36 import org.jemmy.fx.control.CheckBoxWrap; 37 import org.jemmy.interfaces.Keyboard.KeyboardButton; 38 import org.jemmy.interfaces.Keyboard.KeyboardButtons; 39 import org.jemmy.interfaces.Selectable; 40 import org.jemmy.interfaces.Selector; 41 import org.junit.BeforeClass; 42 import org.junit.Test; 43 import org.junit.runner.RunWith; 44 import test.javaclient.shared.FilteredTestRunner; 45 import test.javaclient.shared.Utils; 46 47 /** 48 * Class provides tests for mnemonics behavior. 49 * According to the <a href=http://xdesign.us.oracle.com/projects/javaFX/fxcontrols-ue/specifications/mnemonics/mnemonics-UESpec.html>Mnemonics spec</a> 50 * mnemonics are platform specific. Therefore tests design is aimed to 51 * consider the difference between platforms and to avoid boilerplate. 52 * 53 * If tests are run on Ubuntu with Unity the ALT key may invoke the HUD. 54 * In that case you should change system keyboard mapping to avoid such behavior. 55 * 56 */ 57 @RunWith(FilteredTestRunner.class) 58 public class LabelsMnemonicsTest extends MnemonicsTestBase { 59 60 @BeforeClass 61 public static void setUpClass() throws Exception { 62 LabelsMnemonicsApp.main(null); 63 MnemonicsTestBase.setUpClass(); 64 } 65 66 67 @Smoke 68 @Test(timeout = 300000) 69 public void staticTest() throws Throwable { 70 if (!Utils.isMacOS()) { 71 staticSequence(KeyboardButtons.ALT); 72 if (!Utils.isLinux()) { 73 // current spec is unclear 74 // staticSequence(KeyboardButtons.F10); 75 } 76 } 77 } 78 79 @Smoke 80 @Test(timeout = 300000) 81 public void dynamicTest() throws Throwable { 82 if (!Utils.isMacOS()) { 83 dynamicSequence(KeyboardButtons.ALT); 84 if (!Utils.isLinux()) { 85 // current spec is unclear 86 // dynamicSequence(KeyboardButtons.F10); 87 } 88 } 89 } 90 91 public void staticSequence(KeyboardButton activate_button) throws Throwable { 92 Wrap<? extends Button> button1 = sceneAsParent.lookup(Button.class, new ByID<Button>(LabelsMnemonicsApp.BUTTON_STATIC_ID)).wrap(); 93 Wrap<? extends Label> label1 = sceneAsParent.lookup(Label.class, new ByID<Label>(LabelsMnemonicsApp.LABEL_STATIC_SET_ID)).wrap(); 94 Wrap<? extends Button> button2 = sceneAsParent.lookup(Button.class, new ByID<Button>(LabelsMnemonicsApp.BUTTON_STATIC_2_ID)).wrap(); 95 Wrap<? extends Label> label2 = sceneAsParent.lookup(Label.class, new ByID<Label>(LabelsMnemonicsApp.LABEL_STATIC_RESET_ID)).wrap(); 96 Wrap<? extends Node> button3 = sceneAsParent.lookup(Button.class, new ByID<Button>(LabelsMnemonicsApp.BUTTON_STATIC_REVERSED_ID)).wrap(); 97 Wrap<? extends Label> label3 = sceneAsParent.lookup(Label.class, new ByID<Label>(LabelsMnemonicsApp.LABEL_STATIC_REVERSED_ID)).wrap(); 98 KeyboardButton button1_kbb = getButton(button1);//B 99 KeyboardButton label1_kbb = getButton(label1);//S 100 KeyboardButton label2_kbb = getButton(label2);//R 101 KeyboardButton label3_kbb = getButton(label3);//O 102 103 checkUnderline(label1, false); 104 checkUnderline(label2, false); 105 checkUnderline(label3, false); 106 107 removeFocus(button1, button2, button3); 108 scene.keyboard().pushKey(button1_kbb); 109 button1.waitProperty("isFocused", Boolean.FALSE); 110 scene.keyboard().pushKey(label1_kbb); 111 button1.waitProperty("isFocused", Boolean.FALSE); 112 scene.keyboard().pushKey(label2_kbb); 113 button2.waitProperty("isFocused", Boolean.FALSE); 114 scene.keyboard().pushKey(label3_kbb); 115 button3.waitProperty("isFocused", Boolean.FALSE); 116 117 try { 118 if (isLinux) { 119 scene.keyboard().pressKey(activate_button); 120 } else { 121 scene.keyboard().pushKey(activate_button); 122 } 123 124 checkUnderline(label1, true); 125 checkUnderline(label2, true); 126 checkUnderline(label3, true); 127 checkUnderline(button1, true); 128 129 if (isLinux) { scene.keyboard().releaseKey(activate_button); } 130 131 removeFocus(button1); 132 133 scene.keyboard().pushKey(button1_kbb, mod); 134 button1.waitProperty("isFocused", Boolean.TRUE); 135 removeFocus(button1); 136 scene.keyboard().pushKey(label1_kbb, mod); 137 button1.waitProperty("isFocused", Boolean.TRUE); 138 scene.keyboard().pushKey(label2_kbb, mod); 139 button2.waitProperty("isFocused", Boolean.TRUE); 140 scene.keyboard().pushKey(label3_kbb, mod); 141 button3.waitProperty("isFocused", Boolean.TRUE); 142 } catch (Throwable th) { 143 throw th; 144 } finally { 145 scene.keyboard().pushKey(activate_button); 146 } 147 checkUnderline(label1, false); 148 checkUnderline(label2, false); 149 checkUnderline(label3, false); 150 } 151 152 public void dynamicSequence(KeyboardButton activate_button) throws Throwable { 153 Wrap<? extends Button> button1 = sceneAsParent.lookup(Button.class, new ByID<Button>(LabelsMnemonicsApp.BUTTON_DYNAMIC_1_ID)).wrap(); 154 Wrap<? extends Button> button2 = sceneAsParent.lookup(Button.class, new ByID<Button>(LabelsMnemonicsApp.BUTTON_DYNAMIC_2_ID)).wrap(); 155 Wrap<? extends Label> label1 = sceneAsParent.lookup(Label.class, new ByID<Label>(LabelsMnemonicsApp.LABEL_DYNAMIC_1_ID)).wrap(); 156 Wrap<? extends Label> label2 = sceneAsParent.lookup(Label.class, new ByID<Label>(LabelsMnemonicsApp.LABEL_DYNAMIC_2_ID)).wrap(); 157 Selector check_parse1 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_PARSE_1_ID)).wrap().as(Selectable.class).selector(); 158 Selector check_parse2 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_PARSE_2_ID)).wrap().as(Selectable.class).selector(); 159 Selector check_set1 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_SET_1_ID)).wrap().as(Selectable.class).selector(); 160 Selector check_set2 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_SET_2_ID)).wrap().as(Selectable.class).selector(); 161 Selector check_reversed_set1 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_REVERSED_SET_1_ID)).wrap().as(Selectable.class).selector(); 162 Selector check_reversed_set2 = sceneAsParent.lookup(CheckBox.class, new ByID<CheckBox>(LabelsMnemonicsApp.CHECK_DYNAMIC_REVERSED_SET_2_ID)).wrap().as(Selectable.class).selector(); 163 KeyboardButton label1_kbb = getButton(label1); 164 KeyboardButton label2_kbb = getButton(label2); 165 166 try { 167 check_set1.select(CheckBoxWrap.State.CHECKED); 168 new Timeout("Item list delay", 200).sleep(); 169 check_set2.select(CheckBoxWrap.State.CHECKED); 170 new Timeout("Item list delay", 200).sleep(); 171 check_parse1.select(CheckBoxWrap.State.CHECKED); 172 new Timeout("Item list delay", 200).sleep(); 173 check_parse2.select(CheckBoxWrap.State.CHECKED); 174 new Timeout("Item list delay", 200).sleep(); 175 176 if (isLinux) { 177 scene.keyboard().pressKey(activate_button); 178 } else { 179 scene.keyboard().pushKey(activate_button); 180 } 181 182 checkUnderline(label1, true); 183 checkUnderline(label2, true); 184 185 if (isLinux) { scene.keyboard().releaseKey(activate_button); } 186 187 scene.keyboard().pushKey(label1_kbb, mod); 188 button1.waitProperty("isFocused", Boolean.TRUE); 189 scene.keyboard().pushKey(label2_kbb, mod); 190 button2.waitProperty("isFocused", Boolean.TRUE); 191 } catch (Throwable th) { 192 throw th; 193 } finally { 194 scene.keyboard().pushKey(activate_button); 195 } 196 197 checkUnderline(label1, false); 198 checkUnderline(label2, false); 199 200 try { 201 scene.keyboard().pushKey(KeyboardButtons.ALT); 202 203 check_reversed_set1.select(CheckBoxWrap.State.CHECKED); 204 check_reversed_set2.select(CheckBoxWrap.State.CHECKED); 205 206 removeFocus(button1, button2); 207 scene.keyboard().pushKey(label2_kbb, mod); 208 button1.waitProperty("isFocused", Boolean.TRUE); 209 removeFocus(button1); 210 scene.keyboard().pushKey(label1_kbb, mod); 211 button2.waitProperty("isFocused", Boolean.TRUE); 212 213 check_reversed_set1.select(CheckBoxWrap.State.UNCHECKED); 214 check_reversed_set2.select(CheckBoxWrap.State.UNCHECKED); 215 check_set1.select(CheckBoxWrap.State.UNCHECKED); 216 check_set2.select(CheckBoxWrap.State.UNCHECKED); 217 218 removeFocus(button1, button2); 219 scene.keyboard().pushKey(label1_kbb); 220 button1.waitProperty("isFocused", Boolean.FALSE); 221 removeFocus(button2); 222 scene.keyboard().pushKey(label2_kbb); 223 button2.waitProperty("isFocused", Boolean.FALSE); 224 } catch (Throwable th) { 225 throw th; 226 } finally { 227 scene.keyboard().pushKey(KeyboardButtons.ALT); 228 } 229 } 230 }