diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java index 4ebc7ed06f2..436b0f884bc 100644 --- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java +++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/UITestCase.java @@ -21,6 +21,7 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.resources.ResourcesPlugin; @@ -30,7 +31,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceMemento; -import org.eclipse.swt.SWT; import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.events.ShellListener; import org.eclipse.swt.widgets.Display; @@ -75,6 +75,7 @@ public static IAdaptable getPageInput() { private final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule(); protected IWorkbench fWorkbench; + private Set preExistingShells; /** Preference helper to restore changed preference values after test run. */ private final PreferenceMemento prefMemento = new PreferenceMemento(); @@ -180,6 +181,7 @@ public final void setUp() throws Exception { super.setUp(); closeTestWindows.before(); fWorkbench = PlatformUI.getWorkbench(); + this.preExistingShells = Set.of(fWorkbench.getDisplay().getShells()); String name = runningTest != null ? runningTest : this.getName(); trace(TestRunLogUtil.formatTestStartMessage(name)); doSetUp(); @@ -212,18 +214,17 @@ public final void tearDown() throws Exception { trace(TestRunLogUtil.formatTestFinishedMessage(name)); prefMemento.resetPreferences(); doTearDown(); - fWorkbench = null; - // Check for modal shell leak. + // Check for shell leak. List leakedModalShellTitles = new ArrayList<>(); - Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells(); + Shell[] shells = fWorkbench.getDisplay().getShells(); for (Shell shell : shells) { - if (!shell.isDisposed() && shell.isVisible() - && (shell.getStyle() & (SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL | SWT.SYSTEM_MODAL)) != 0) { + if (!shell.isDisposed() && !preExistingShells.contains(shell)) { leakedModalShellTitles.add(shell.getText()); shell.close(); } } + fWorkbench = null; assertEquals("Test leaked modal shell: [" + String.join(", ", leakedModalShellTitles) + "]", 0, leakedModalShellTitles.size()); } diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingArchiveProjectFilterTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingArchiveProjectFilterTest.java index 1aff6631812..5132ead15f5 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingArchiveProjectFilterTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingArchiveProjectFilterTest.java @@ -40,13 +40,13 @@ import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.dialogs.ImportExportWizard; import org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage; import org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage.ProjectRecord; import org.eclipse.ui.navigator.resources.ProjectExplorer; import org.eclipse.ui.tests.TestPlugin; -import org.eclipse.ui.tests.harness.util.DialogCheck; import org.eclipse.ui.tests.harness.util.EmptyPerspective; import org.eclipse.ui.tests.harness.util.FileUtil; import org.eclipse.ui.tests.harness.util.UITestCase; @@ -66,6 +66,10 @@ public ImportExistingArchiveProjectFilterTest() { @Override protected void doTearDown() throws Exception { + if (dialog != null) { + dialog.close(); + dialog = null; + } IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = wsRoot.getProjects(); for (int i = projects.length - 1; i >= 0; i--) { @@ -158,6 +162,7 @@ private void processElementAndChildren(Object element, ITreeContentProvider cont } } + private WizardDialog dialog; public WizardProjectsImportPage getNewWizard() { ImportExportWizard wizard = new ImportExportWizard(ImportExportWizard.IMPORT); wizard.init(getWorkbench(), null); @@ -173,7 +178,10 @@ public WizardProjectsImportPage getNewWizard() { Shell shell = getShell(); - WizardDialog dialog = new WizardDialog(shell, wizard); + if (dialog != null) { + dialog.close(); + } + dialog = new WizardDialog(shell, wizard); dialog.create(); dialog.getShell().setSize(Math.max(100, dialog.getShell().getSize().x), 100); @@ -185,6 +193,6 @@ public WizardProjectsImportPage getNewWizard() { } private Shell getShell() { - return DialogCheck.getShell(); + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); } } diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingProjectsWizardTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingProjectsWizardTest.java index 4149e8089b6..80b17938d83 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingProjectsWizardTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ImportExistingProjectsWizardTest.java @@ -56,7 +56,6 @@ import org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage.ProjectRecord; import org.eclipse.ui.tests.TestPlugin; import org.eclipse.ui.tests.datatransfer.ImportTestUtils.TestBuilder; -import org.eclipse.ui.tests.harness.util.DialogCheck; import org.eclipse.ui.tests.harness.util.FileUtil; import org.eclipse.ui.tests.harness.util.UITestCase; import org.eclipse.ui.wizards.datatransfer.ExternalProjectImportWizard; @@ -86,6 +85,8 @@ public class ImportExistingProjectsWizardTest extends UITestCase { private String zipLocation = null; + private WizardDialog dialog; + private boolean originalRefreshSetting; public ImportExistingProjectsWizardTest() { @@ -93,7 +94,7 @@ public ImportExistingProjectsWizardTest() { } private Shell getShell() { - return DialogCheck.getShell(); + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); } @Override @@ -109,6 +110,11 @@ protected void doSetUp() throws Exception { @Override protected void doTearDown() throws Exception { + if (dialog != null) { + dialog.close(); + dialog = null; + } + IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = wsRoot.getProjects(); for (int i = projects.length - 1; i >= 0; i--) { @@ -799,8 +805,6 @@ public void test14InitialValue() throws IOException, CoreException { wpip = getExternalImportWizard(null); selectedProjects = wpip.getProjectRecords(); assertEquals(0, selectedProjects.length); - - } @Test @@ -900,7 +904,6 @@ private String copyZipLocation(String zipLocation) throws IOException { return ImportTestUtils.copyZipLocation(zipLocation, ARCHIVE_HELLOWORLD); } - private WizardProjectsImportPage getNewWizard() { ImportExportWizard wizard = new ImportExportWizard( ImportExportWizard.IMPORT); @@ -920,7 +923,10 @@ private WizardProjectsImportPage getNewWizard() { Shell shell = getShell(); - WizardDialog dialog = new WizardDialog(shell, wizard); + if (dialog != null) { + dialog.close(); + } + dialog = new WizardDialog(shell, wizard); dialog.create(); dialog.getShell().setSize(Math.max(100, dialog.getShell().getSize().x), 100); @@ -1176,7 +1182,10 @@ private WizardProjectsImportPage getExternalImportWizard(String initialPath) { ExternalProjectImportWizard wizard = new ExternalProjectImportWizard( initialPath); wizard.init(getWorkbench(), null); - WizardDialog dialog = new WizardDialog(getShell(), wizard); + if (dialog != null) { + dialog.close(); + } + dialog = new WizardDialog(getShell(), wizard); dialog.create(); dialog.getShell().setSize(Math.max(100, dialog.getShell().getSize().x), diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerViewTests.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerViewTests.java index 77782ed8ef4..6efcc2e7a25 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerViewTests.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerViewTests.java @@ -46,9 +46,9 @@ public void testOpenView() { IWorkbenchPage page = window.getActivePage(); try { - page.showView(IPageLayout.ID_BOOKMARKS); - page.showView(IPageLayout.ID_PROBLEM_VIEW); - page.showView(IPageLayout.ID_TASK_LIST); + page.hideView(page.showView(IPageLayout.ID_BOOKMARKS)); + page.hideView(page.showView(IPageLayout.ID_PROBLEM_VIEW)); + page.hideView(page.showView(IPageLayout.ID_TASK_LIST)); } catch (PartInitException e) { assertTrue(e.getLocalizedMessage(), false); return;