Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.ui.internal.decorators.DecorationResult;
import org.eclipse.ui.internal.decorators.DecoratorManager;
import org.eclipse.ui.internal.decorators.LightweightDecoratorManager;
import org.eclipse.ui.tests.harness.util.UITestUtil;
import org.eclipse.ui.tests.menus.ObjectContributionClasses;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -63,6 +64,10 @@ public void doSetUp() throws Exception {
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestUnadaptableDecoratorContributor.ID, true);
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceDecoratorContributor.ID, true);
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceMappingDecoratorContributor.ID, true);

// Process all pending UI events to ensure decorator enablement has completed
// This prevents race conditions where decorators may not be fully registered yet
UITestUtil.processEvents();
}

@After
Expand All @@ -71,6 +76,9 @@ public void doTearDown() throws Exception {
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestUnadaptableDecoratorContributor.ID, false);
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceDecoratorContributor.ID, false);
PlatformUI.getWorkbench().getDecoratorManager().setEnabled(TestResourceMappingDecoratorContributor.ID, false);

// Process all pending UI events to ensure clean state for next test
UITestUtil.processEvents();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void testSingleSelectionAndNoInitialSelectionWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertFalse("One file should be selected by default", selected.isEmpty());
Expand All @@ -100,6 +103,9 @@ public void testSingleSelectionAndOneInitialSelectionWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
Expand All @@ -119,6 +125,9 @@ public void testSingleSelectionAndOneInitialNonExistingSelectionWithInitialPatte
dialog.open();
dialog.refresh();

// Don't wait for full refresh - this test checks that invalid initial
// selections don't cause a selection before dialog is fully loaded

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
Expand All @@ -136,6 +145,9 @@ public void testSingleSelectionAndOneInitialSelectionWithoutInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
Expand All @@ -155,6 +167,9 @@ public void testSingleSelectionAndOneFilteredSelection() {
dialog.open();
dialog.refresh();

// Don't wait for full refresh - this test checks that filtered initial
// selections don't cause a selection before dialog is fully loaded

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
Expand All @@ -174,6 +189,9 @@ public void testSingleSelectionAndTwoInitialSelectionsWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertEquals("The first file should be selected by default", asList(FILES.get("foo.txt")), selected);
Expand All @@ -192,6 +210,9 @@ public void testMultiSelectionAndNoInitialSelectionWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertFalse("One file should be selected by default", selected.isEmpty());
Expand All @@ -211,6 +232,9 @@ public void testMultiSelectionAndOneInitialSelectionWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertEquals("One file should be selected by default", asList(FILES.get("foo.txt")), selected);
Expand All @@ -228,6 +252,9 @@ public void testMultiSelectionAndOneInitialSelectionWithoutInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
Expand All @@ -247,6 +274,9 @@ public void testMultiSelectionAndTwoInitialNonExistingSelectionWithInitialPatter
dialog.open();
dialog.refresh();

// Don't wait for full refresh - this test checks that invalid initial
// selections don't cause a selection before dialog is fully loaded

List<Object> selected = getSelectedItems(dialog);

assertTrue("No file should be selected by default", selected.isEmpty());
Expand All @@ -266,6 +296,9 @@ public void testMultiSelectionAndSomeInitialNonExistingSelectionWithInitialPatte
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);
Set<IFile> expectedSelection = new HashSet<>(asList(FILES.get("bar.txt"), FILES.get("foofoo")));
boolean allInitialElementsAreSelected = expectedSelection.equals(new HashSet<>(selected));
Expand All @@ -288,6 +321,9 @@ public void testMultiSelectionAndTwoInitialSelectionsWithInitialPattern() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);
boolean initialElementsAreSelected = selected.containsAll(initialSelection)
&& initialSelection.containsAll(selected);
Expand All @@ -310,6 +346,9 @@ public void testMultiSelectionAndTwoInitialFilteredSelections() {
dialog.open();
dialog.refresh();

// Wait for background refresh jobs to complete
waitForDialogRefresh();

List<Object> selected = getSelectedItems(dialog);
List<IFile> expectedSelection = asList(FILES.get("foo.txt"), FILES.get("bar.txt"));
boolean initialElementsAreSelected = selected.containsAll(expectedSelection)
Expand Down Expand Up @@ -408,6 +447,26 @@ private void processUIEvents() {
}
}

/**
* Wait for dialog refresh jobs to complete and process UI events.
* This ensures background jobs finish before assertions are made.
*/
private void waitForDialogRefresh() {
// Process UI events multiple times to allow background jobs to complete
// Similar to the fix in DecoratorAdaptableTests
for (int i = 0; i < 3; i++) {
processUIEvents();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
// Final event loop processing
processUIEvents();
}

/**
* Delete project with retry mechanism to handle cases where background jobs
* are still using the project resources.
Expand Down
Loading