modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java

Print this page
rev 9038 : RT-34620: [ComboBox, DatePicker] Buttons set to default/cancel are not reacting to ComboBox enter/esc keys


1191         keyboard.doKeyPress(KeyCode.ENTER);
1192 
1193         assertEquals(1, test_rt34603_count);
1194 
1195         sl.dispose();
1196     }
1197 
1198     private int test_rt35586_count = 0;
1199     @Test public void test_rt35586() {
1200         assertEquals(0, test_rt35586_count);
1201 
1202         final ComboBox<String> cb = new ComboBox<String>();
1203         cb.setEditable(true);
1204         cb.setOnAction(event -> {
1205             test_rt35586_count++;
1206             assertEquals("Test", cb.getEditor().getText());
1207         });
1208 
1209         StageLoader sl = new StageLoader(cb);
1210 
1211         cb.getEditor().requestFocus();
1212         cb.getEditor().setText("Test");
1213         KeyEventFirer keyboard = new KeyEventFirer(cb.getEditor());
1214         keyboard.doKeyPress(KeyCode.ENTER);
1215 
1216         assertEquals(1, test_rt35586_count);
1217 
1218         sl.dispose();
1219     }
1220 
1221     @Test public void test_rt35039() {
1222         final List<String> data = new ArrayList<>();
1223         data.add("aabbaa");
1224         data.add("bbc");
1225 
1226         final ComboBox<String> combo = new ComboBox<>();
1227         combo.setEditable(true);
1228         combo.setItems(FXCollections.observableArrayList(data));
1229 
1230         StageLoader sl = new StageLoader(combo);
1231 
1232         // everything should be null to start with
1233         assertNull(combo.getValue());


1637         assertEquals(cb1, scene.getFocusOwner());
1638 
1639         // move focus forward to cb2
1640         cb1Keyboard.doKeyPress(KeyCode.TAB);
1641         assertTrue(cb2.isFocused());
1642         assertEquals(cb2, scene.getFocusOwner());
1643 
1644         // move focus forward again to cb1
1645         cb2Keyboard.doKeyPress(KeyCode.TAB);
1646         assertTrue(cb1.isFocused());
1647         assertEquals(cb1, scene.getFocusOwner());
1648 
1649         // now start going backwards with shift-tab.
1650         // The first half of the bug is here - when we shift-tab into cb2, we
1651         // actually go into the FakeFocusTextField subcomponent, so whilst the
1652         // cb2.isFocused() returns true as expected, the scene focus owner is
1653         // not the ComboBox, but the FakeFocusTextField inside it
1654         cb1Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
1655         assertTrue("Expect cb2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
1656                 cb2.isFocused());
1657         assertEquals("Expect cb2 TextField to be focused, but actual focus owner is: " + scene.getFocusOwner(),
1658                 cb2.getEditor(), scene.getFocusOwner());




1659 
1660         // This is where the second half of the bug appears, as we are stuck in
1661         // the FakeFocusTextField of cb2, we never make it to cb1
1662         cb2Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
1663         assertTrue(cb1.isFocused());
1664         assertEquals(cb1, scene.getFocusOwner());
1665 
1666         sl.dispose();
1667     }
1668 
1669     private int rt_38901_counter;
1670     @Test public void test_rt_38901_selectNull() {
1671         test_rt_38901(true);
1672     }
1673 
1674     @Test public void test_rt_38901_selectNegativeOne() {
1675         test_rt_38901(false);
1676     }
1677 
1678     private void test_rt_38901(boolean selectNull) {




1191         keyboard.doKeyPress(KeyCode.ENTER);
1192 
1193         assertEquals(1, test_rt34603_count);
1194 
1195         sl.dispose();
1196     }
1197 
1198     private int test_rt35586_count = 0;
1199     @Test public void test_rt35586() {
1200         assertEquals(0, test_rt35586_count);
1201 
1202         final ComboBox<String> cb = new ComboBox<String>();
1203         cb.setEditable(true);
1204         cb.setOnAction(event -> {
1205             test_rt35586_count++;
1206             assertEquals("Test", cb.getEditor().getText());
1207         });
1208 
1209         StageLoader sl = new StageLoader(cb);
1210 
1211         cb.requestFocus();
1212         cb.getEditor().setText("Test");
1213         KeyEventFirer keyboard = new KeyEventFirer(cb);
1214         keyboard.doKeyPress(KeyCode.ENTER);
1215 
1216         assertEquals(1, test_rt35586_count);
1217 
1218         sl.dispose();
1219     }
1220 
1221     @Test public void test_rt35039() {
1222         final List<String> data = new ArrayList<>();
1223         data.add("aabbaa");
1224         data.add("bbc");
1225 
1226         final ComboBox<String> combo = new ComboBox<>();
1227         combo.setEditable(true);
1228         combo.setItems(FXCollections.observableArrayList(data));
1229 
1230         StageLoader sl = new StageLoader(combo);
1231 
1232         // everything should be null to start with
1233         assertNull(combo.getValue());


1637         assertEquals(cb1, scene.getFocusOwner());
1638 
1639         // move focus forward to cb2
1640         cb1Keyboard.doKeyPress(KeyCode.TAB);
1641         assertTrue(cb2.isFocused());
1642         assertEquals(cb2, scene.getFocusOwner());
1643 
1644         // move focus forward again to cb1
1645         cb2Keyboard.doKeyPress(KeyCode.TAB);
1646         assertTrue(cb1.isFocused());
1647         assertEquals(cb1, scene.getFocusOwner());
1648 
1649         // now start going backwards with shift-tab.
1650         // The first half of the bug is here - when we shift-tab into cb2, we
1651         // actually go into the FakeFocusTextField subcomponent, so whilst the
1652         // cb2.isFocused() returns true as expected, the scene focus owner is
1653         // not the ComboBox, but the FakeFocusTextField inside it
1654         cb1Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
1655         assertTrue("Expect cb2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
1656                 cb2.isFocused());
1657         // Updated with fix for RT-34602: The TextField now never gets
1658         // focus (it's just faking it).
1659         // assertEquals("Expect cb2 TextField to be focused, but actual focus owner is: " + scene.getFocusOwner(),
1660         //         cb2.getEditor(), scene.getFocusOwner());
1661         assertEquals("Expect cb2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
1662                      cb2, scene.getFocusOwner());
1663 
1664         // This is where the second half of the bug appears, as we are stuck in
1665         // the FakeFocusTextField of cb2, we never make it to cb1
1666         cb2Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
1667         assertTrue(cb1.isFocused());
1668         assertEquals(cb1, scene.getFocusOwner());
1669 
1670         sl.dispose();
1671     }
1672 
1673     private int rt_38901_counter;
1674     @Test public void test_rt_38901_selectNull() {
1675         test_rt_38901(true);
1676     }
1677 
1678     @Test public void test_rt_38901_selectNegativeOne() {
1679         test_rt_38901(false);
1680     }
1681 
1682     private void test_rt_38901(boolean selectNull) {