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 8ea681f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 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 @@ -15,7 +15,6 @@

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

import java.util.List;

Expand All @@ -27,8 +26,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import org.eclipse.core.runtime.Platform;

import org.eclipse.text.tests.Accessor;

import org.eclipse.jface.text.IDocument;
Expand All @@ -49,12 +46,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 +66,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 +89,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 @@ -120,12 +116,12 @@ public void testContextInfo_hide_focusOut() throws Exception {

@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 +145,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 8ea681f

Please sign in to comment.