Skip to content

Commit

Permalink
fix ContextInformationTest #35
Browse files Browse the repository at this point in the history
Identify correct shell instead of taking random one.
  • Loading branch information
EcljpseB0T committed May 26, 2023
1 parent e6757c2 commit d9170ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.jface.text.tests.contentassist;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
Expand Down Expand Up @@ -226,14 +227,13 @@ protected List<Shell> findNewShells(Collection<Shell> beforeShells) {
}

protected Shell findNewShell(Collection<Shell> beforeShells) {
DisplayHelper.sleep(getDisplay(), 100);
List<Shell> afterShells= findNewShells(beforeShells);
if (afterShells.isEmpty()) {
DisplayHelper.sleep(getDisplay(), 1000);
for (int attempt= 0; afterShells.size() != 1 && attempt < 10; attempt++) {
DisplayHelper.sleep(getDisplay(), 100);
afterShells= findNewShells(beforeShells);
}
afterShells= findNewShells(beforeShells);
assertTrue("No new shell found, existing: " + beforeShells, afterShells.size() > beforeShells.size());
return afterShells.get(afterShells.size() - 1);
assertEquals("Not unique new shell found", 1, afterShells.size());
return afterShells.get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public IContextInformationValidator getContextInformationValidator() {

@Test
public void testContextInfo_withStyledTextPresentation() throws Exception {
final List<Shell> beforeShells= getCurrentShells();
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL);

postSourceViewerKeyEvent(SWT.ARROW_RIGHT, 0, SWT.KeyDown);
selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);
assertEquals("idx= 0", getInfoText(this.infoShell));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ private ContentAssistant createBarContentAssist() {

@Test
public void testContextInfo() throws Exception {
final List<Shell> beforeShells= getCurrentShells();
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL);

selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);
assertEquals("idx= 0", getInfoText(this.infoShell));
Expand All @@ -69,12 +69,12 @@ public void testContextInfo() throws Exception {

@Test
public void testContextInfo_hide_Bug512251() throws Exception {
final List<Shell> beforeShells= getCurrentShells();
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL);

selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);

Expand All @@ -92,15 +92,14 @@ public void testContextInfo_hide_Bug512251() throws Exception {

@Test
public void testContextInfo_hide_focusOut() throws Exception {
assumeFalse("Test fails on Mac: Bug 558989", Platform.OS_MACOSX.equals(Platform.getOS()));
assumeFalse("Test fails on CentOS 8: See https://github.com/eclipse-platform/eclipse.platform.text/pull/162", Platform.OS_LINUX.equals(Platform.getOS()));

final List<Shell> beforeShells= getCurrentShells();
// opens source viewer shell:
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL);

selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
// opens content assist shell:
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);
assertEquals("idx= 0", getInfoText(this.infoShell));
Expand All @@ -114,18 +113,21 @@ public void testContextInfo_hide_focusOut() throws Exception {

// Hide all
getButton().setFocus();
// hides and disposes Shell (by org.eclipse.jface.text.contentassist.ContentAssistant.hide()):
processEvents();
assertTrue(this.infoShell.isDisposed() || !this.infoShell.isVisible());
assumeFalse("Test fails on Mac: Bug 558989", Platform.OS_MACOSX.equals(Platform.getOS()));
assumeFalse("Test fails on CentOS 8: See https://github.com/eclipse-platform/eclipse.platform.text/pull/162", Platform.OS_LINUX.equals(Platform.getOS()));
assertTrue("Shell not disposed:" + this.infoShell, this.infoShell.isDisposed());
}

@Test
public void testContextInfo_hide_keyEsc() throws Exception {
final List<Shell> beforeShells= getCurrentShells();
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL);

selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);
assertEquals("idx= 0", getInfoText(this.infoShell));
Expand All @@ -149,12 +151,12 @@ public void testContextInfo_hide_keyEsc() throws Exception {

@Test
public void testContextInfo_hide_validRange() throws Exception {
final List<Shell> beforeShells= getCurrentShells();
setupSourceViewer(createBarContentAssist(), BarContentAssistProcessor.PROPOSAL + '\n');

selectAndReveal(4, 0);
processEvents();

final List<Shell> beforeShells= getCurrentShells();
triggerContextInformation();
this.infoShell= findNewShell(beforeShells);
assertEquals("idx= 0", getInfoText(this.infoShell));
Expand Down

0 comments on commit d9170ee

Please sign in to comment.