swtbot: Stabilize use of SWTBotUtils.maximizeTable()
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 21 Mar 2016 20:50:14 +0000 (16:50 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 29 Mar 2016 15:07:47 +0000 (11:07 -0400)
When Ctrl+M is pressed, the resize and layout of the workbench part does
not necessarily occur immediately. For tests that depend on the part
being maximized, the method should block until the resize has occurred.

So far, this issue was only seen when SWTKeyboardStrategy is used.
SWT strategy posts events to SWT and this differs from the AWT strategy.
But the solution in this patch offers an additional safety that is
beneficial to all keyboard strategies.

Change-Id: I3afac9314a82c319064accca1fce00c1dbeb893e
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/69075
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CallsiteEventsInTableTest.java

index 29842d9393a38604a0446ba4c8d92d664bec3f16..3e0638adeccb254ed24315291d4048191106aebe 100644 (file)
@@ -18,6 +18,7 @@ import static org.junit.Assert.fail;
 
 import java.util.List;
 import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -32,6 +33,8 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.bindings.keys.IKeyLookup;
 import org.eclipse.jface.bindings.keys.KeyStroke;
 import org.eclipse.jface.bindings.keys.ParseException;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Display;
@@ -679,11 +682,35 @@ public final class SWTBotUtils {
      *            the {@link SWTBotTable} table
      */
     public static void maximizeTable(SWTBotTable tableBot) {
+        final AtomicBoolean controlResized = new AtomicBoolean();
+        UIThreadRunnable.syncExec(new VoidResult() {
+            @Override
+            public void run() {
+                tableBot.widget.addControlListener(new ControlAdapter() {
+                    @Override
+                    public void controlResized(ControlEvent e) {
+                        tableBot.widget.removeControlListener(this);
+                        controlResized.set(true);
+                    }
+                });
+            }
+        });
         try {
             tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
         } catch (ParseException e) {
             fail();
         }
+        new SWTBot().waitUntil(new DefaultCondition() {
+            @Override
+            public boolean test() throws Exception {
+                return controlResized.get();
+            }
+
+            @Override
+            public String getFailureMessage() {
+                return "Control was not resized";
+            }
+        });
     }
 
     /**
index d677c5c6b3bfc26dbc33f5ab3f91965b6615d8b0..7f7ac92a02b1a940d6606101fda9b96fe21bed7f 100644 (file)
@@ -169,6 +169,7 @@ public class CallsiteEventsInTableTest {
         final SWTBotEditor sourceEditorBot = fBot.editor(matcher);
         assertTrue(sourceEditorBot.isActive());
 
+        editorBot.show();
         SWTBotUtils.maximizeTable(tableBot);
 
         fBot.closeAllEditors();
This page took 0.027348 seconds and 5 git commands to generate.