tmf: Try to make the shell fully visible in SWTBot at start
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 24 Nov 2015 04:27:46 +0000 (23:27 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 26 Nov 2015 00:46:27 +0000 (19:46 -0500)
In certain environments, the workbench shell can be positioned at random
locations. Depending on the size of the display, it is possible that the
shell is not fully visible. This patch adds logic to the start of SWTBot
tests so that if the top shell is not fully visible, it will try to move
it in within the display bounds. If the shell cannot fit the display, it
will be positioned at the top-left corner of the display.

To be able to apply this to all test, a new utility method was
introduced, SWTBotUtils.initialize. More common code that is applicable
to all SWTBot tests could be moved there in the future.

This fix is important to some tests that can depend on whether of not
some controls get painted. For example, a drag listener is only added on
a sash when it gets first painted. If it is never painted,
TmfAlignTimeAxisTest fails when trying to drag this sash to verify the
proper behavior of time alignment.

Change-Id: Ic67739e204fcb0a4b567914e8b6078c286d56bd3
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/61094
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
25 files changed:
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/TestInvalidCtfTrace.java
lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/KernelTest.java
lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/OpenTraceStressTest.java
lttng/org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/ust/ui/swtbot/tests/CallStackViewTest.java
pcap/org.eclipse.tracecompass.tmf.pcap.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/pcap/ui/swtbot/tests/ImportAndReadPcapTest.java
tmf/org.eclipse.tracecompass.tmf.remote.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/remote/ui/swtbot/tests/fetch/FetchRemoteTracesTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/AbstractPerspectiveChecker.java
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/parsers/custom/AbstractCustomParserWizard.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CallsiteEventsInTableTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CollapseEventsInTableTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/ColorsViewTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/ColumnHeaderMenuTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/CopyToClipboardTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FilterColorEditorTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FilterViewerTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/FontEventEditorTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/MovableColumnEventsEditorTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/SDViewTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/TestRefreshTextTrace.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/TestTraceOffsetting.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/viewers/events/TmfAlignTimeAxisTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/wizards/StandardImportGzipTraceTest.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/wizards/TestImportExportPackageWizard.java

index f81faf05c73a079f56a979c0314b6a433a2b0afb..08480979f3f72c99a4cb95345a6fd589798b14d0 100644 (file)
@@ -83,7 +83,7 @@ public abstract class AbstractImportAndReadSmokeTest {
     /** Test Class setup */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
index 025284c725b57895662b2f44ad75b4bd5a9347de..bd75d1023905dc8a0cab1ae3cc39b10d7d4dda38 100644 (file)
@@ -166,7 +166,7 @@ public class TestInvalidCtfTrace {
      */
     @Before
     public void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index eaa6effde5de60d57264dc7b55153be17a1ed940..285b0d04fdb2ac2a8a4147d39395cc75e14272f4 100644 (file)
@@ -61,7 +61,7 @@ public class KernelTest {
      */
     @BeforeClass
     public static void beforeClass() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index d2a7566feb064884c8dd3bb0478828dd62c7bc51..14102c228081e06f262c48f93b414b80bcfef426 100644 (file)
@@ -60,7 +60,7 @@ public class OpenTraceStressTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* Set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index 6dae7d00f5b1b7ea465bb4af7d4224f06fdfe96a..a85851ef22b3edef01d97e148d5f1f51b6547f1f 100644 (file)
@@ -143,7 +143,7 @@ public class CallStackViewTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
index 8a0d70c906985e13ee5cbcfe5eed4026bb7e1b7d..28e9eac2bef3b3c8f8983b740bfbff5dbec6ff66 100644 (file)
@@ -86,7 +86,7 @@ public class ImportAndReadPcapTest {
     @BeforeClass
     public static void init() {
 
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 300000; /* 300 second timeout */
index 7ebdde5431275fd7da4b7abae8384d8138b1df3b..22840529ad07d6070a128ab85bc24cc422147212 100644 (file)
@@ -110,7 +110,7 @@ public class FetchRemoteTracesTest {
     @BeforeClass
     public static void init() {
         SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
         Logger.getRootLogger().addAppender(new NullAppender());
         fBot = new SWTWorkbenchBot();
index da18132367fc36ac212030969698d6ed26840e67..288606c4f05302b213fe13040ec257b0de11a783 100644 (file)
@@ -57,7 +57,7 @@ public abstract class AbstractPerspectiveChecker {
     /** Test Class setup */
     @BeforeClass
     public static void beforeInit() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
index 7386e341f3ecca0004bd6b67d920fe1910bfe26a..b8bbe60a511dbdb8a62c5a4b3cacfa748e603ea3 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.jface.bindings.keys.ParseException;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
@@ -249,15 +250,52 @@ public final class SWTBotUtils {
         });
     }
 
+    /**
+     * Initialize the environment for SWTBot
+     */
+    public static void initialize() {
+        failIfUIThread();
+
+        SWTWorkbenchBot bot = new SWTWorkbenchBot();
+        UIThreadRunnable.syncExec(() -> {
+            Shell shell = bot.activeShell().widget;
+
+            // Only adjust shell if it appears to be the top-most
+            if (shell.getParent() == null) {
+                makeShellFullyVisible(shell);
+            }
+        });
+    }
+
     /**
      * If the test is running in the UI thread then fail
      */
-    public static void failIfUIThread() {
+    private static void failIfUIThread() {
         if (Display.getCurrent() != null && Display.getCurrent().getThread() == Thread.currentThread()) {
             fail("SWTBot test needs to run in a non-UI thread. Make sure that \"Run in UI thread\" is unchecked in your launch configuration or"
                     + " that useUIThread is set to false in the pom.xml");
         }
+    }
 
+    /**
+     * Try to make the shell fully visible in the display. If the shell cannot
+     * fit the display, it will be positioned so that top-left corner is at
+     * <code>(0, 0)</code> in display-relative coordinates.
+     *
+     * @param shell
+     *            the shell to make fully visible
+     */
+    private static void makeShellFullyVisible(Shell shell) {
+        Rectangle displayBounds = shell.getDisplay().getBounds();
+        Point absCoord = shell.toDisplay(0, 0);
+        Point shellSize = shell.getSize();
+
+        Point newLocation = new Point(absCoord.x, absCoord.y);
+        newLocation.x = Math.max(0, Math.min(absCoord.x, displayBounds.width - shellSize.x));
+        newLocation.y = Math.max(0, Math.min(absCoord.y, displayBounds.height - shellSize.y));
+        if (!newLocation.equals(absCoord)) {
+            shell.setLocation(newLocation);
+        }
     }
 
     /**
index 0870adfb9659c05329a84b7e7717dd101d697446..93d8912458c74f808d6173579a665784b98840a3 100644 (file)
@@ -45,7 +45,7 @@ public class AbstractCustomParserWizard {
     /** Test Class setup */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index 45c52eadd5f6f17631479f60e1b64b32cd778da1..d677c5c6b3bfc26dbc33f5ab3f91965b6615d8b0 100644 (file)
@@ -77,7 +77,7 @@ public class CallsiteEventsInTableTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace*/
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(CALLSITE_TRACE_PATH), null);
index 1307de8c29bf8129fee4991496d90270eece351d..6a59af119bcb660642fd3119b8386daafad9a3aa 100644 (file)
@@ -71,7 +71,7 @@ public class CollapseEventsInTableTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace*/
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLLAPSE_TRACE_PATH), null);
index 9f74f6cea0068ff1bf6b6a9cb97d48079bdd75e8..7c3455c7e8c5e8bd242a62e3bc9a42f35c589862 100644 (file)
@@ -160,7 +160,7 @@ public class ColorsViewTest {
      */
     @BeforeClass
     public static void init() throws IOException {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index ba55593be85e3aec63f3348c6e0d8b462b06631c..fa2ee74de694851a2821a4625283929297c612cc 100644 (file)
@@ -72,7 +72,7 @@ public class ColumnHeaderMenuTest {
      */
     @BeforeClass
     public static void beforeClass() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace */
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
index 13b639fb686e553b9043cfd8756c273c26d4692d..2ff9cdbb225a78e32820e67974f0431f9765465b 100644 (file)
@@ -83,7 +83,7 @@ public class CopyToClipboardTest {
      */
     @BeforeClass
     public static void beforeClass() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace */
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TRACE_PATH), null);
index 3adc993ab3fadcf3b495466815ec5dd4fea9d518..e57e998a46a39702ea4ad5c2dd71f1335df78331 100644 (file)
@@ -87,7 +87,7 @@ public class FilterColorEditorTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace */
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
index b79ba51b2757192df754b462ff75df15c0152c66..b54dd736dfdd498ba4ea5b5fb6bf239655637e45 100644 (file)
@@ -83,7 +83,7 @@ public class FilterViewerTest {
      */
     @BeforeClass
     public static void init() throws IOException {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index 8c4a7020c92f243a63750480a55a39136a313b7b..84c04d3d40daf2a809c565d47cce8938b5ad9d0c 100644 (file)
@@ -70,7 +70,7 @@ public class FontEventEditorTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace */
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
index 6f0cbb40ec856e8b7992a3677ddcdca78f4a6f98..b970db9d26df329c2d1ab316e4956495c1ffad1c 100644 (file)
@@ -69,7 +69,7 @@ public class MovableColumnEventsEditorTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up test trace */
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
index 6e8396858ca78ddb5da162643b1b335862cc19e7..71cc0341f0f88b4a3be842a9d914b7b49084553c 100644 (file)
@@ -79,7 +79,7 @@ public class SDViewTest {
      */
     @BeforeClass
     public static void init() throws IOException {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index 9e1c41adcd1e28ee4dee5dc77a0de98d01ba123a..522072fda3024bd32c897672b85868431e4b5b2a 100644 (file)
@@ -62,7 +62,7 @@ public class TestRefreshTextTrace {
     @BeforeClass
     public static void init() {
         SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
         Logger.getRootLogger().addAppender(new NullAppender());
         fBot = new SWTWorkbenchBot();
index 703f622cf79d4ec699abbed555c1762ef70dd82c..b8e1392bcef2aaea7bbb818aed5b4c977310dc16 100644 (file)
@@ -72,7 +72,7 @@ public class TestTraceOffsetting {
      */
     @Before
     public void init() throws IOException {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index 9a1a9faa0cbcd74f86f0a5651a3dd783e3a8cfc2..dd74c15e24d1fb9c70182bf3c6bf6c00b6f61618 100644 (file)
@@ -96,7 +96,7 @@ public class TmfAlignTimeAxisTest {
      */
     @BeforeClass
     public static void init() throws IOException {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName("SWTBot Thread"); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
index a7ad2397522e2182051150580d14e7ceec475064..8d5dabc909db81480ca5a44d753c6974df54d87f 100644 (file)
@@ -83,7 +83,7 @@ public class StandardImportGzipTraceTest {
      */
     @BeforeClass
     public static void init() {
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         zipTrace();
         fLogger.removeAllAppenders();
         fLogger.addAppender(new NullAppender());
index b2cf229b45a36526142373953b845a0db585603b..b0c8f1ac48e0ccfe43f81a54ab1cc4b75f0a96e6 100644 (file)
@@ -94,7 +94,7 @@ public class TestImportExportPackageWizard {
     @BeforeClass
     public static void init() {
         SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
         Thread.currentThread().setName(SWT_BOT_THREAD_NAME); // for the debugger
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
This page took 0.036057 seconds and 5 git commands to generate.