1 package javafx.scene.control; 2 3 /* 4 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Oracle designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Oracle in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 28 import com.sun.javafx.scene.control.infrastructure.StageLoader; 29 import com.sun.javafx.scene.control.inputmap.InputMap; 30 import org.junit.Test; 31 32 import static org.junit.Assert.assertEquals; 33 import static org.junit.Assert.assertFalse; 34 import static org.junit.Assert.assertNotNull; 35 import static org.junit.Assert.assertNull; 36 import static org.junit.Assert.assertTrue; 37 import static org.junit.Assert.fail; 38 39 import static javafx.scene.input.KeyCode.*; 40 41 public class InputMapTest { 42 43 @Test public void dummy() { 44 // no-op 45 } 46 47 // /*************************************************************************** 48 // * 49 // * Control InputMap mappings population / removal 50 // * 51 // **************************************************************************/ 52 // 53 // @Test public void testControlHasNonNullInputMap() { 54 // Button btn = new Button(); 55 // assertNotNull(btn.getInputMap()); 56 // } 57 // 58 // @Test public void testDefaultInputMapIsEmpty() { 59 // Button btn = new Button(); 60 // assertEquals(0, btn.getInputMap().getMappings().size()); 61 // } 62 // 63 // @Test public void addControlToSceneAndCheckInputMapIsPopulated() { 64 // Button btn = new Button(); 65 // assertEquals(0, btn.getInputMap().getMappings().size()); 66 // StageLoader sl = new StageLoader(btn); 67 // assertFalse(btn.getInputMap().getMappings().isEmpty()); 68 // sl.dispose(); 69 // } 70 // 71 // @Test public void testSkinDoesNotOverrideUserDefinedMappings() { 72 // Button btn = new Button(); 73 // assertEquals(0, btn.getInputMap().getMappings().size()); 74 // 75 // // ENTER is not a default mapping, but SPACE is 76 // InputMap.KeyMapping customEnterMapping = new InputMap.KeyMapping(ENTER, e -> { 77 // // no-op 78 // }); 79 // InputMap.KeyMapping customSpaceMapping = new InputMap.KeyMapping(SPACE, e -> { 80 // // no-op 81 // }); 82 // btn.getInputMap().getMappings().addAll(customEnterMapping, customSpaceMapping); 83 // assertEquals(2, btn.getInputMap().getMappings().size()); 84 // 85 // StageLoader sl = new StageLoader(btn); 86 // 87 // // There are 18 mappings provided by ButtonBehavior. We add two above, 88 // // but one of them displaces a default mapping, so we expect 19. 89 // assertEquals(19, btn.getInputMap().getMappings().size()); 90 // 91 // // we want to ensure that our two mappings still exist 92 // assertTrue(btn.getInputMap().getMappings().contains(customEnterMapping)); 93 // assertTrue(btn.getInputMap().getMappings().contains(customSpaceMapping)); 94 // 95 // // we also look up the mappings using their key codes, to double check 96 // // that they are there 97 // assertNotNull(btn.getInputMap().lookupMapping(ENTER)); 98 // assertNotNull(btn.getInputMap().lookupMapping(SPACE)); 99 // 100 // sl.dispose(); 101 // } 102 // 103 // @Test public void removeSkinAndEnsureSkinMappingsAreRemoved() { 104 // Button btn = new Button(); 105 // assertEquals(0, btn.getInputMap().getMappings().size()); 106 // 107 // StageLoader sl = new StageLoader(btn); 108 // 109 // // There are 18 mappings provided by ButtonBehavior. 110 // assertEquals(18, btn.getInputMap().getMappings().size()); 111 // btn.setSkin(null); 112 // assertEquals(0, btn.getInputMap().getMappings().size()); 113 // 114 // sl.dispose(); 115 // } 116 // 117 // @Test public void removeSkinAndEnsureSkinMappingsAreRemoved_shouldNotRemoveUserDefinedMappings() { 118 // Button btn = new Button(); 119 // assertEquals(0, btn.getInputMap().getMappings().size()); 120 // 121 // // ENTER is not a default mapping, but SPACE is 122 // InputMap.KeyMapping customEnterMapping = new InputMap.KeyMapping(ENTER, e -> { 123 // // no-op 124 // }); 125 // InputMap.KeyMapping customSpaceMapping = new InputMap.KeyMapping(SPACE, e -> { 126 // // no-op 127 // }); 128 // btn.getInputMap().getMappings().addAll(customEnterMapping, customSpaceMapping); 129 // assertEquals(2, btn.getInputMap().getMappings().size()); 130 // 131 // StageLoader sl = new StageLoader(btn); 132 // 133 // // There are 18 mappings provided by ButtonBehavior. We add two above, 134 // // but one of them displaces a default mapping, so we expect 19. 135 // assertEquals(19, btn.getInputMap().getMappings().size()); 136 // 137 // // remove the skin - we expect our two mappings to still exist - but that is it 138 // btn.setSkin(null); 139 // assertEquals(2, btn.getInputMap().getMappings().size()); 140 // 141 // // we want to ensure that our two mappings still exist 142 // assertTrue(btn.getInputMap().getMappings().contains(customEnterMapping)); 143 // assertTrue(btn.getInputMap().getMappings().contains(customSpaceMapping)); 144 // 145 // // we also look up the mappings using their key codes, to double check 146 // // that they are there 147 // assertNotNull(btn.getInputMap().lookupMapping(ENTER)); 148 // assertNotNull(btn.getInputMap().lookupMapping(SPACE)); 149 // 150 // sl.dispose(); 151 // } 152 // 153 // 154 // /*************************************************************************** 155 // * 156 // * Control InputMap childMap population / removal 157 // * 158 // **************************************************************************/ 159 // 160 // @Test public void testButtonControlHasNoInputMapChildMaps_afterSkinLoaded() { 161 // Button btn = new Button(); 162 // 163 // assertNotNull(btn.getInputMap().getChildInputMaps()); 164 // assertTrue(btn.getInputMap().getChildInputMaps().isEmpty()); 165 // 166 // StageLoader sl = new StageLoader(btn); 167 // assertNotNull(btn.getInputMap().getChildInputMaps()); 168 // assertTrue(btn.getInputMap().getChildInputMaps().isEmpty()); 169 // sl.dispose(); 170 // } 171 // 172 // @Test public void testListViewControlHasInputMapChildMaps_afterSkinLoaded() { 173 // ListView listView = new ListView(); 174 // 175 // assertNotNull(listView.getInputMap().getChildInputMaps()); 176 // assertTrue(listView.getInputMap().getChildInputMaps().isEmpty()); 177 // 178 // StageLoader sl = new StageLoader(listView); 179 // assertNotNull(listView.getInputMap().getChildInputMaps()); 180 // assertFalse(listView.getInputMap().getChildInputMaps().isEmpty()); 181 // sl.dispose(); 182 // } 183 // 184 // @Test public void removeSkinAndEnsureSkinChildInputMapsAreRemoved() { 185 // ListView listView = new ListView(); 186 // 187 // StageLoader sl = new StageLoader(listView); 188 // 189 // assertNotNull(listView.getInputMap().getChildInputMaps()); 190 // assertFalse(listView.getInputMap().getChildInputMaps().isEmpty()); 191 // 192 // listView.setSkin(null); 193 // assertTrue(listView.getInputMap().getChildInputMaps().isEmpty()); 194 // 195 // sl.dispose(); 196 // } 197 // 198 // @Test public void removeSkinAndEnsureSkinChildInputMapsAreRemoved_shouldNotRemoveUserDefinedInputMaps() { 199 // ListView<?> listView = new ListView<>(); 200 // 201 // InputMap<ListView<?>> dummyMap = new InputMap<>(listView); 202 // dummyMap.getMappings().add(new InputMap.KeyMapping(ENTER, e -> { 203 // // no-op 204 // })); 205 // ((InputMap<ListView<?>>)listView.getInputMap()).getChildInputMaps().add(dummyMap); 206 // 207 // assertEquals(1, listView.getInputMap().getChildInputMaps().size()); 208 // 209 // StageLoader sl = new StageLoader(listView); 210 // 211 // assertNotNull(listView.getInputMap().getChildInputMaps()); 212 // assertFalse(listView.getInputMap().getChildInputMaps().isEmpty()); 213 // 214 // listView.setSkin(null); 215 // assertEquals(1, listView.getInputMap().getChildInputMaps().size()); 216 // assertEquals(dummyMap, listView.getInputMap().getChildInputMaps().get(0)); 217 // 218 // sl.dispose(); 219 // } 220 }