Add utility method to close secondary shells after tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / CopyToClipboardTest.java
index 13b639fb686e553b9043cfd8756c273c26d4692d..59e21aae021263c5a36de4656281529ff53722a2 100644 (file)
@@ -26,12 +26,15 @@ import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.dnd.TextTransfer;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 import org.eclipse.swtbot.swt.finder.keyboard.Keyboard;
@@ -41,7 +44,6 @@ import org.eclipse.swtbot.swt.finder.results.StringResult;
 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
-import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
 import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.junit.After;
@@ -83,7 +85,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);
@@ -140,6 +142,7 @@ public class CopyToClipboardTest {
     @After
     public void after() {
         fBot.closeAllEditors();
+        SWTBotUtils.closeSecondaryShells(fBot);
     }
 
     /**
@@ -147,6 +150,7 @@ public class CopyToClipboardTest {
      */
     @Test
     public void testCopySingleSelection() {
+        assumeTrue(!isAffectedByBug486302());
         final SWTBotTable tableBot = fEditorBot.bot().table();
         tableBot.getTableItem(1).click();
 
@@ -159,6 +163,7 @@ public class CopyToClipboardTest {
      */
     @Test
     public void testCopyMultipleSelection() {
+        assumeTrue(!isAffectedByBug486302());
         final SWTBotTable tableBot = fEditorBot.bot().table();
         tableBot.getTableItem(1).click();
         KEYBOARD.pressShortcut(Keystrokes.SHIFT, Keystrokes.DOWN);
@@ -168,6 +173,22 @@ public class CopyToClipboardTest {
         assertClipboardContentsEquals(HEADER_TEXT + EVENT1_TEXT + EVENT2_TEXT + EVENT3_TEXT);
     }
 
+    /**
+     * Returns whether or not the running Eclipse is affected by Bug 486302. The
+     * bug is present in Eclipse 4.5.2 and earlier running GTK3.
+     */
+    private static boolean isAffectedByBug486302() {
+        String property = System.getProperty("org.eclipse.swt.internal.gtk.version");
+        if (property != null) {
+            @NonNull String @NonNull [] versionSegments = property.split("\\.");
+            if (versionSegments.length > 0) {
+                return SWT.getVersion() <= 4530 && versionSegments[0].equals("3");
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Test copy to clipboard not enabled when selection includes search row
      */
@@ -187,10 +208,8 @@ public class CopyToClipboardTest {
                 try {
                     SWTBotPreferences.TIMEOUT = 0;
                     tableBot.contextMenu(text);
-                } catch (TimeoutException e) {
+                } catch (WidgetNotFoundException e) {
                     return true;
-                } catch (IndexOutOfBoundsException e) {
-                    /* remove when Bug 474063 is fixed */
                 } finally {
                     SWTBotPreferences.TIMEOUT = TIMEOUT;
                 }
This page took 0.027732 seconds and 5 git commands to generate.