diff options
author | Lucas Bullen | 2018-08-22 18:59:31 +0000 |
---|---|---|
committer | Mickael Istria | 2018-08-23 14:08:47 +0000 |
commit | 16bb876f5de4fab50e3b7b5328553fff76166ef0 (patch) | |
tree | cd7dedcbc2e45604767537c3aa25348de36e02aa | |
parent | 169d7ded688ac6239bdf47e55d40f1ff1ae0ef52 (diff) | |
download | eclipse.platform.text-16bb876f5de4fab50e3b7b5328553fff76166ef0.tar.gz eclipse.platform.text-16bb876f5de4fab50e3b7b5328553fff76166ef0.tar.xz eclipse.platform.text-16bb876f5de4fab50e3b7b5328553fff76166ef0.zip |
Bug 537195 - HoverTest fails on Mac
- Adds a hover to be created on mac before the test starts
hopefully stopping the first hover test ran from failing
Change-Id: Ie9b2abbad309b63ea2e0d49c61536a6ea696bad8
Signed-off-by: Lucas Bullen <lbullen@redhat.com>
-rw-r--r-- | org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java | 98 |
1 files changed, 53 insertions, 45 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java index 883a73af7fb..8a138b8efa8 100644 --- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java +++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java @@ -66,16 +66,19 @@ import org.eclipse.ui.texteditor.AbstractTextEditor; public class HoverTest extends AbstratGenericEditorTest { @Rule - public TestName testName = new TestName(); + public TestName testName= new TestName(); @Before public void skipOnWindows() { Assume.assumeFalse("This test currently always fail on Windows (bug 505842), skipping", Platform.OS_WIN32.equals(Platform.getOS())); + if (Platform.OS_MACOSX.equals(Platform.getOS())) { + getHoverShell(triggerCompletionAndRetrieveInformationControlManager(), false); + } } @Test public void testSingleHover() throws Exception { - Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager()); + Shell shell= getHoverShell(triggerCompletionAndRetrieveInformationControlManager(), true); assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL)); assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL)); assertNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL)); @@ -83,18 +86,17 @@ public class HoverTest extends AbstratGenericEditorTest { @Test public void testEnabledWhenHover() throws Exception { - Assume.assumeFalse("This test currently always fails on Mac (bug 537195), skipping", Platform.OS_MACOSX.equals(Platform.getOS())); cleanFileAndEditor(); EnabledPropertyTester.setEnabled(true); createAndOpenFile("enabledWhen.txt", "bar 'bar'"); - Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager()); + Shell shell= getHoverShell(triggerCompletionAndRetrieveInformationControlManager(), true); assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL)); assertNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL)); cleanFileAndEditor(); EnabledPropertyTester.setEnabled(false); createAndOpenFile("enabledWhen.txt", "bar 'bar'"); - shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager()); + shell= getHoverShell(triggerCompletionAndRetrieveInformationControlManager(), true); assertNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL)); assertNotNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL)); } @@ -107,7 +109,7 @@ public class HoverTest extends AbstratGenericEditorTest { public void testMultipleHover() throws Exception { cleanFileAndEditor(); createAndOpenFile("bar.txt", "Hi"); - Shell shell = getHoverShell(triggerCompletionAndRetrieveInformationControlManager()); + Shell shell= getHoverShell(triggerCompletionAndRetrieveInformationControlManager(), true); assertNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL)); assertNotNull(findControl(shell, StyledText.class, WorldHoverProvider.LABEL)); assertNotNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL)); @@ -115,37 +117,37 @@ public class HoverTest extends AbstratGenericEditorTest { @Test public void testProblemHover() throws Exception { - String problemMessage = "Huston..."; - IMarker marker = null; + String problemMessage= "Huston..."; + IMarker marker= null; try { - marker = this.file.createMarker(IMarker.PROBLEM); + marker= this.file.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.LINE_NUMBER, 1); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IMarker.CHAR_START, 0); marker.setAttribute(IMarker.CHAR_END, 5); marker.setAttribute(IMarker.MESSAGE, problemMessage); marker.setAttribute(MarkerResolutionGenerator.FIXME, true); - AbstractInformationControlManager manager = triggerCompletionAndRetrieveInformationControlManager(); - Object hoverData = getHoverData(manager); + AbstractInformationControlManager manager= triggerCompletionAndRetrieveInformationControlManager(); + Object hoverData= getHoverData(manager); assertTrue(hoverData instanceof Map); - assertTrue(((Map<?,?>)hoverData).containsValue(Collections.singletonList(marker))); - assertTrue(((Map<?,?>)hoverData).containsValue(AlrightyHoverProvider.LABEL)); - assertFalse(((Map<?,?>)hoverData).containsValue(HelloHoverProvider.LABEL)); + assertTrue(((Map<?, ?>) hoverData).containsValue(Collections.singletonList(marker))); + assertTrue(((Map<?, ?>) hoverData).containsValue(AlrightyHoverProvider.LABEL)); + assertFalse(((Map<?, ?>) hoverData).containsValue(HelloHoverProvider.LABEL)); // check dialog content - Shell shell= getHoverShell(manager); + Shell shell= getHoverShell(manager, true); assertNotNull(findControl(shell, Label.class, marker.getAttribute(IMarker.MESSAGE, "NONE"))); assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL)); assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL)); // check quick-fix works - Link link = findControl(shell, Link.class, MarkerResolutionGenerator.FIXME); + Link link= findControl(shell, Link.class, MarkerResolutionGenerator.FIXME); assertNotNull(link); - Event event = new Event(); - event.widget = link; - event.display = link.getDisplay(); - event.doit = true; - event.type = SWT.Selection; + Event event= new Event(); + event.widget= link; + event.display= link.getDisplay(); + event.doit= true; + event.type= SWT.Selection; link.notifyListeners(SWT.Selection, event); - final IMarker m = marker; + final IMarker m= marker; new DisplayHelper() { @Override protected boolean condition() { @@ -160,53 +162,59 @@ public class HoverTest extends AbstratGenericEditorTest { } } - private Shell getHoverShell(AbstractInformationControlManager manager) { - AbstractInformationControl[] control = { null }; + private Shell getHoverShell(AbstractInformationControlManager manager, boolean failOnError) { + AbstractInformationControl[] control= { null }; new DisplayHelper() { @Override protected boolean condition() { - control[0] = (AbstractInformationControl)new Accessor(manager, AbstractInformationControlManager.class).get("fInformationControl"); + control[0]= (AbstractInformationControl) new Accessor(manager, AbstractInformationControlManager.class).get("fInformationControl"); return control[0] != null; } }.waitForCondition(this.editor.getSite().getShell().getDisplay(), 5000); if (control[0] == null) { - ScreenshotTest.takeScreenshot(getClass(), testName.getMethodName(), System.out); - fail(); + if (failOnError) { + ScreenshotTest.takeScreenshot(getClass(), testName.getMethodName(), System.out); + fail(); + } else { + return null; + } } - Shell shell = (Shell)new Accessor(control[0], AbstractInformationControl.class).get("fShell"); + Shell shell= (Shell) new Accessor(control[0], AbstractInformationControl.class).get("fShell"); new DisplayHelper() { @Override protected boolean condition() { return shell.isVisible(); } }.waitForCondition(this.editor.getSite().getShell().getDisplay(), 2000); - assertTrue(shell.isVisible()); + if (failOnError) { + assertTrue(shell.isVisible()); + } return shell; } private <T extends Control> T findControl(Control control, Class<T> controlType, String label) { if (control.getClass() == controlType) { @SuppressWarnings("unchecked") - T res = (T) control; + T res= (T) control; if (label == null) { return res; } - String controlLabel = null; + String controlLabel= null; if (control instanceof Label) { - controlLabel = ((Label)control).getText(); + controlLabel= ((Label) control).getText(); } else if (control instanceof Link) { - controlLabel = ((Link) control).getText(); + controlLabel= ((Link) control).getText(); } else if (control instanceof Text) { - controlLabel = ((Text) control).getText(); + controlLabel= ((Text) control).getText(); } else if (control instanceof StyledText) { - controlLabel = ((StyledText) control).getText(); + controlLabel= ((StyledText) control).getText(); } if (controlLabel != null && controlLabel.contains(label)) { return res; } } else if (control instanceof Composite) { for (Control child : ((Composite) control).getChildren()) { - T res = findControl(child, controlType, label); + T res= findControl(child, controlType, label); if (res != null) { return res; } @@ -216,14 +224,14 @@ public class HoverTest extends AbstratGenericEditorTest { } private Object getHoverData(AbstractInformationControlManager manager) { - Object hoverData = new Accessor(manager, AbstractInformationControlManager.class).get("fInformation"); + Object hoverData= new Accessor(manager, AbstractInformationControlManager.class).get("fInformation"); return hoverData; } private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() { final int caretLocation= 2; this.editor.selectAndReveal(caretLocation, 0); - final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class); + final StyledText editorTextWidget= (StyledText) this.editor.getAdapter(Control.class); new DisplayHelper() { @Override protected boolean condition() { @@ -235,13 +243,13 @@ public class HoverTest extends AbstratGenericEditorTest { editorTextWidget.getShell().setActive(); editorTextWidget.getShell().setFocus(); editorTextWidget.getShell().getDisplay().wake(); - Event hoverEvent = new Event(); - hoverEvent.widget = editorTextWidget; - hoverEvent.type = SWT.MouseHover; - hoverEvent.x = editorTextWidget.getClientArea().x + 5; - hoverEvent.y = editorTextWidget.getClientArea().y + 5; - hoverEvent.display = editorTextWidget.getDisplay(); - hoverEvent.doit = true; + Event hoverEvent= new Event(); + hoverEvent.widget= editorTextWidget; + hoverEvent.type= SWT.MouseHover; + hoverEvent.x= editorTextWidget.getClientArea().x + 5; + hoverEvent.y= editorTextWidget.getClientArea().y + 5; + hoverEvent.display= editorTextWidget.getDisplay(); + hoverEvent.doit= true; editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y)); editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent); ITextViewer viewer= (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]); |