mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-29 01:05:41 +08:00
Merge remote-tracking branch 'origin/GP-0-dragonmacher-splash-screen-test-fix'
This commit is contained in:
@@ -1765,8 +1765,11 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
|
||||
}
|
||||
|
||||
if (bestParent == null) {
|
||||
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
bestParent = kfm.getActiveWindow();
|
||||
bestParent = getJavaActiveWindow();
|
||||
}
|
||||
|
||||
if (bestParent != null && !bestParent.isShowing()) {
|
||||
bestParent = null; // don't let non-showing windows be parents
|
||||
}
|
||||
|
||||
return bestParent;
|
||||
@@ -1775,8 +1778,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
|
||||
private static Window getBestNonModalParent(DialogComponentProvider newProvider,
|
||||
Window bestParent) {
|
||||
|
||||
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
Window activeWindow = kfm.getActiveWindow();
|
||||
Window activeWindow = getJavaActiveWindow();
|
||||
if (!(activeWindow instanceof DockingDialog)) {
|
||||
return bestParent;
|
||||
}
|
||||
@@ -1937,13 +1939,19 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
|
||||
|
||||
private static Window getJavaActiveWindow() {
|
||||
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
return kfm.getActiveWindow();
|
||||
Window activeWindow = kfm.getActiveWindow();
|
||||
if (activeWindow == null) {
|
||||
return null;
|
||||
}
|
||||
if (!activeWindow.isShowing()) {
|
||||
return null; // don't let non-showing windows be considered active
|
||||
}
|
||||
return activeWindow;
|
||||
}
|
||||
|
||||
private static Window getActiveNonTransientWindow() {
|
||||
|
||||
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||
Window bestWindow = kfm.getActiveWindow();
|
||||
Window bestWindow = getJavaActiveWindow();
|
||||
if (bestWindow instanceof DockingDialog) {
|
||||
// We do not want Task Dialogs becoming parents, as they will get closed when the
|
||||
// task is finished, closing any other child dialogs, which means that dialogs such
|
||||
|
||||
+34
-73
@@ -30,71 +30,43 @@ import docking.*;
|
||||
import docking.test.AbstractDockingTest;
|
||||
import docking.widgets.PasswordDialog;
|
||||
import generic.test.category.NightlyCategory;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
// The splash screen is sensitive to windows being activated/deactivated, so don't run
|
||||
// when other test windows may be open
|
||||
@Category(NightlyCategory.class)
|
||||
public class SplashScreenTest extends AbstractDockingTest {
|
||||
|
||||
private AboutDialog aboutDialog;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Msg.debug(this, "tearDown() - open windows before closing");
|
||||
printOpenWindows();
|
||||
|
||||
runSwing(() -> SplashScreen.disposeSplashScreen());
|
||||
|
||||
closeAllWindows();
|
||||
printOpenWindows();
|
||||
|
||||
Msg.debug(this, "tearDown() - open windows after closing");
|
||||
disposeAllWindows();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowInfoWindow() throws Exception {
|
||||
// no parent
|
||||
showModalInfoWindow(null);
|
||||
|
||||
ensureInfoWindowVisible();
|
||||
hideInfoWindow();
|
||||
|
||||
// not visible parent
|
||||
JFrame parentFrame = new JFrame("InfoWindowTest.testShowInfoWindow Frame");
|
||||
parentFrame.setBounds(-100, -100, 0, 0);
|
||||
showModalInfoWindow(parentFrame);
|
||||
|
||||
ensureInfoWindowVisible();
|
||||
hideInfoWindow();
|
||||
|
||||
// visible parent
|
||||
parentFrame.setVisible(true);
|
||||
showModalInfoWindow(parentFrame);
|
||||
|
||||
ensureInfoWindowVisible();
|
||||
hideInfoWindow();
|
||||
private void disposeAllWindows() {
|
||||
for (Window window : getAllWindows()) {
|
||||
runSwing(window::dispose);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowAndHideSplashScreen() {
|
||||
showSplashScreen(true);
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
|
||||
showSplashScreen(false);
|
||||
ensureSpashScreenVisible(false);
|
||||
assertSpashScreenVisible(false);
|
||||
|
||||
showSplashScreen(true);
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
|
||||
showSplashScreen(false);
|
||||
ensureSpashScreenVisible(false);
|
||||
assertSpashScreenVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSplashScreenStatus() {
|
||||
showSplashScreen(true);
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
|
||||
JLabel statusLabel = (JLabel) getInstanceField("statusLabel", SplashScreen.class);
|
||||
|
||||
@@ -120,24 +92,24 @@ public class SplashScreenTest extends AbstractDockingTest {
|
||||
public void testSplashScreenPasswordModality_SharedParent() throws Exception {
|
||||
|
||||
showSplashScreen(true);
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
|
||||
// show a modal dialog with no parent (this will use the Splash Screen's parent)
|
||||
showModalPasswordDialog(null);
|
||||
|
||||
// When the splash screen and the dialog share a parent, then the dialog should NOT
|
||||
// cause the splash screen to go away
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplashScreenPasswordModality_UnsharedParent() throws Exception {
|
||||
// show the splash screen
|
||||
showSplashScreen(true);
|
||||
ensureSpashScreenVisible(true);
|
||||
assertSpashScreenVisible(true);
|
||||
|
||||
DockingFrame frame = new DockingFrame("Modal Parent Frame");
|
||||
frame.setVisible(true);
|
||||
show(frame);
|
||||
showModalPasswordDialog(frame);
|
||||
|
||||
ensureSplashScreenWillClose();
|
||||
@@ -147,6 +119,10 @@ public class SplashScreenTest extends AbstractDockingTest {
|
||||
// Private Methods
|
||||
//==================================================================================================
|
||||
|
||||
private void show(JFrame frame) {
|
||||
runSwing(() -> frame.setVisible(true));
|
||||
}
|
||||
|
||||
private void ensureSplashScreenWillClose() {
|
||||
waitForCondition(() -> {
|
||||
SplashScreen splash = getSplash();
|
||||
@@ -155,42 +131,44 @@ public class SplashScreenTest extends AbstractDockingTest {
|
||||
}
|
||||
|
||||
private DockingDialog showModalPasswordDialog(Frame parentFrame) throws Exception {
|
||||
|
||||
String dialogTitle = "InfoWindowTest.testSplashScreenPasswordModality() Dialog";
|
||||
DialogComponentProvider passwordDialog = runSwing(() -> new PasswordDialog(dialogTitle,
|
||||
"Server Type", "Server Name", "Prompt", null, null));
|
||||
|
||||
if (parentFrame == null) {
|
||||
// null means to share the parent
|
||||
Object splashParent = getInstanceField("hiddenFrame", SplashScreen.class);
|
||||
parentFrame = (Frame) splashParent;
|
||||
}
|
||||
|
||||
Frame finalParent = parentFrame;
|
||||
executeOnSwingWithoutBlocking(
|
||||
() -> DockingWindowManager.showDialog(parentFrame, passwordDialog));
|
||||
() -> {
|
||||
DockingDialog dialog =
|
||||
DockingDialog.createDialog(finalParent, passwordDialog, finalParent);
|
||||
dialog.setVisible(true);
|
||||
});
|
||||
|
||||
JDialog dialog = waitForJDialog(dialogTitle);
|
||||
assertNotNull(dialog);
|
||||
|
||||
Window dialogWindow = SwingUtilities.windowForComponent(dialog);
|
||||
Msg.debug(this, "Created modal dialog with parent: " + getTitleForWindow(dialogWindow) +
|
||||
" - id: " + System.identityHashCode(dialogWindow));
|
||||
|
||||
return (DockingDialog) dialog;
|
||||
}
|
||||
|
||||
// handles showing the modal info window, which must be done from a thread outside of the
|
||||
// test thread
|
||||
private void showModalInfoWindow(final JFrame parentFrame) {
|
||||
// create a thread to show the modal dialog so that the current thread doesn't block
|
||||
aboutDialog = runSwing(() -> new AboutDialog());
|
||||
executeOnSwingWithoutBlocking(() -> DockingWindowManager.showDialog(null, aboutDialog));
|
||||
}
|
||||
|
||||
private void showSplashScreen(final boolean makeVisible) {
|
||||
|
||||
if (makeVisible) {
|
||||
SplashScreen splash = runSwing(() -> SplashScreen.showSplashScreen());
|
||||
assertNotNull("Failed showing splash screen", splash);
|
||||
waitForSwing();
|
||||
return;
|
||||
}
|
||||
SplashScreen.disposeSplashScreen();
|
||||
waitForSwing();
|
||||
}
|
||||
|
||||
private void ensureSpashScreenVisible(boolean visible) {
|
||||
private void assertSpashScreenVisible(boolean visible) {
|
||||
// get the 'splashWindow' and make sure that it is not null and that it is visible
|
||||
SplashScreen splashScreen = getSplash();
|
||||
|
||||
@@ -206,23 +184,6 @@ public class SplashScreenTest extends AbstractDockingTest {
|
||||
|
||||
// timing issue debug
|
||||
waitForCondition(() -> splashScreen.isVisible());
|
||||
|
||||
if (!splashScreen.isVisible()) {
|
||||
|
||||
// this can happen if other OS windows trigger the splash window to be hidden
|
||||
printOpenWindows();
|
||||
fail("The splash screen is not visible when expected to be so - " + splashScreen);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureInfoWindowVisible() {
|
||||
// get the 'infoDialog' and make sure that it is not null and that it is visible
|
||||
assertTrue("The info dialog is not visible after it was supposed to " + "have been shown.",
|
||||
aboutDialog.isVisible());
|
||||
}
|
||||
|
||||
private void hideInfoWindow() throws Exception {
|
||||
runSwing(() -> aboutDialog.close());
|
||||
}
|
||||
|
||||
private SplashScreen getSplash() {
|
||||
|
||||
Reference in New Issue
Block a user