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

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


 415 
 416         // Convert from MinguoDate to LocalDate (ISO)
 417         datePicker.setChronology(IsoChronology.INSTANCE);
 418         assertEquals(LocalDate.of(2013, 5, 22), datePicker.getValue());
 419         datePicker.getEditor().setText(datePicker.getConverter().toString(datePicker.getValue()));
 420         assertEquals("5/22/2013", datePicker.getEditor().getText());
 421     }
 422 
 423     private int test_rt35586_count = 0;
 424     @Test public void test_rt35586() {
 425         assertEquals(0, test_rt35586_count);
 426 
 427         final DatePicker dp = new DatePicker();
 428         dp.setOnAction(event -> {
 429             test_rt35586_count++;
 430             assertEquals("1/2/2015", dp.getEditor().getText());
 431         });
 432 
 433         StageLoader sl = new StageLoader(dp);
 434 
 435         dp.getEditor().requestFocus();
 436         dp.getEditor().setText("1/2/2015");
 437         KeyEventFirer keyboard = new KeyEventFirer(dp.getEditor());
 438         keyboard.doKeyPress(KeyCode.ENTER);
 439 
 440         assertEquals(1, test_rt35586_count);
 441 
 442         sl.dispose();
 443     }
 444 
 445     @Test public void test_rt35840() {
 446         final DatePicker dp = new DatePicker();
 447         dp.setEditable(true);
 448         StageLoader sl = new StageLoader(dp);
 449         dp.requestFocus();
 450 
 451         KeyEventFirer keyboard = new KeyEventFirer(dp);
 452         keyboard.doKeyTyped(KeyCode.DIGIT1);
 453         keyboard.doKeyTyped(KeyCode.SLASH);
 454         keyboard.doKeyTyped(KeyCode.DIGIT2);
 455         keyboard.doKeyTyped(KeyCode.SLASH);
 456         keyboard.doKeyTyped(KeyCode.DIGIT2);
 457         keyboard.doKeyTyped(KeyCode.DIGIT0);


 575         assertEquals(dp1, scene.getFocusOwner());
 576 
 577         // move focus forward to dp2
 578         dp1Keyboard.doKeyPress(KeyCode.TAB);
 579         assertTrue(dp2.isFocused());
 580         assertEquals(dp2, scene.getFocusOwner());
 581 
 582         // move focus forward again to dp1
 583         dp2Keyboard.doKeyPress(KeyCode.TAB);
 584         assertTrue(dp1.isFocused());
 585         assertEquals(dp1, scene.getFocusOwner());
 586 
 587         // now start going backwards with shift-tab.
 588         // The first half of the bug is here - when we shift-tab into dp2, we
 589         // actually go into the FakeFocusTextField subcomponent, so whilst the
 590         // dp2.isFocused() returns true as expected, the scene focus owner is
 591         // not the ComboBox, but the FakeFocusTextField inside it
 592         dp1Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
 593         assertTrue("Expect dp2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
 594                 dp2.isFocused());
 595         assertEquals("Expect dp2 TextField to be focused, but actual focus owner is: " + scene.getFocusOwner(),
 596                 dp2.getEditor(), scene.getFocusOwner());




 597 
 598         // This is where the second half of the bug appears, as we are stuck in
 599         // the FakeFocusTextField of dp2, we never make it to dp1
 600         dp2Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
 601         assertTrue(dp1.isFocused());
 602         assertEquals(dp1, scene.getFocusOwner());
 603 
 604         sl.dispose();
 605     }
 606 }


 415 
 416         // Convert from MinguoDate to LocalDate (ISO)
 417         datePicker.setChronology(IsoChronology.INSTANCE);
 418         assertEquals(LocalDate.of(2013, 5, 22), datePicker.getValue());
 419         datePicker.getEditor().setText(datePicker.getConverter().toString(datePicker.getValue()));
 420         assertEquals("5/22/2013", datePicker.getEditor().getText());
 421     }
 422 
 423     private int test_rt35586_count = 0;
 424     @Test public void test_rt35586() {
 425         assertEquals(0, test_rt35586_count);
 426 
 427         final DatePicker dp = new DatePicker();
 428         dp.setOnAction(event -> {
 429             test_rt35586_count++;
 430             assertEquals("1/2/2015", dp.getEditor().getText());
 431         });
 432 
 433         StageLoader sl = new StageLoader(dp);
 434 
 435         dp.requestFocus();
 436         dp.getEditor().setText("1/2/2015");
 437         KeyEventFirer keyboard = new KeyEventFirer(dp);
 438         keyboard.doKeyPress(KeyCode.ENTER);
 439 
 440         assertEquals(1, test_rt35586_count);
 441 
 442         sl.dispose();
 443     }
 444 
 445     @Test public void test_rt35840() {
 446         final DatePicker dp = new DatePicker();
 447         dp.setEditable(true);
 448         StageLoader sl = new StageLoader(dp);
 449         dp.requestFocus();
 450 
 451         KeyEventFirer keyboard = new KeyEventFirer(dp);
 452         keyboard.doKeyTyped(KeyCode.DIGIT1);
 453         keyboard.doKeyTyped(KeyCode.SLASH);
 454         keyboard.doKeyTyped(KeyCode.DIGIT2);
 455         keyboard.doKeyTyped(KeyCode.SLASH);
 456         keyboard.doKeyTyped(KeyCode.DIGIT2);
 457         keyboard.doKeyTyped(KeyCode.DIGIT0);


 575         assertEquals(dp1, scene.getFocusOwner());
 576 
 577         // move focus forward to dp2
 578         dp1Keyboard.doKeyPress(KeyCode.TAB);
 579         assertTrue(dp2.isFocused());
 580         assertEquals(dp2, scene.getFocusOwner());
 581 
 582         // move focus forward again to dp1
 583         dp2Keyboard.doKeyPress(KeyCode.TAB);
 584         assertTrue(dp1.isFocused());
 585         assertEquals(dp1, scene.getFocusOwner());
 586 
 587         // now start going backwards with shift-tab.
 588         // The first half of the bug is here - when we shift-tab into dp2, we
 589         // actually go into the FakeFocusTextField subcomponent, so whilst the
 590         // dp2.isFocused() returns true as expected, the scene focus owner is
 591         // not the ComboBox, but the FakeFocusTextField inside it
 592         dp1Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
 593         assertTrue("Expect dp2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
 594                 dp2.isFocused());
 595         // Updated with fix for RT-34602: The TextField now never gets
 596         // focus (it's just faking it).
 597         // assertEquals("Expect dp2 TextField to be focused, but actual focus owner is: " + scene.getFocusOwner(),
 598         //         dp2.getEditor(), scene.getFocusOwner());
 599         assertEquals("Expect dp2 to be focused, but actual focus owner is: " + scene.getFocusOwner(),
 600                      dp2, scene.getFocusOwner());
 601 
 602         // This is where the second half of the bug appears, as we are stuck in
 603         // the FakeFocusTextField of dp2, we never make it to dp1
 604         dp2Keyboard.doKeyPress(KeyCode.TAB, KeyModifier.SHIFT);
 605         assertTrue(dp1.isFocused());
 606         assertEquals(dp1, scene.getFocusOwner());
 607 
 608         sl.dispose();
 609     }
 610 }