Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2016-03-29 12:50:50 +0000
committerFlorian Barbin2016-03-29 13:24:32 +0000
commitb38268bcbf4c1ddb41a168255d7593f1c88455ca (patch)
tree3384e51d71626e48374273635bc1e1d026aaa2a9
parentc04358746b1788e124b4ca99b900b95581ba4ab3 (diff)
downloadorg.eclipse.sirius-b38268bcbf4c1ddb41a168255d7593f1c88455ca.tar.gz
org.eclipse.sirius-b38268bcbf4c1ddb41a168255d7593f1c88455ca.tar.xz
org.eclipse.sirius-b38268bcbf4c1ddb41a168255d7593f1c88455ca.zip
[485832] Fixes SWTBot test
Bug: 485832 Change-Id: I5ca2b88271b137897c9604fd4de2bc60c7b0921f Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/internal/conditions/ShellChangedCondition.java47
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java23
3 files changed, 58 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF
index a3c5494ec5..998eb02e1a 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.swtbot.support/META-INF/MANIFEST.MF
@@ -56,6 +56,7 @@ Export-Package: org.eclipse.sirius.tests.swtbot.support.api;
org.eclipse.sirius.tests.swtbot.support.api.view;version="3.0.0",
org.eclipse.sirius.tests.swtbot.support.api.widget;version="3.1.0",
org.eclipse.sirius.tests.swtbot.support.internal;x-internal:=true;version="3.0.0",
+ org.eclipse.sirius.tests.swtbot.support.internal.conditions,
org.eclipse.sirius.tests.swtbot.support.internal.business;x-internal:=true;version="3.0.0",
org.eclipse.sirius.tests.swtbot.support.utils;
uses:="org.eclipse.swtbot.swt.finder.widgets,org.eclipse.swt.widgets";version="1.1.0",
diff --git a/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/internal/conditions/ShellChangedCondition.java b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/internal/conditions/ShellChangedCondition.java
new file mode 100644
index 0000000000..efc521ffa5
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.swtbot.support/src/org/eclipse/sirius/tests/swtbot/support/internal/conditions/ShellChangedCondition.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2016 THALES GLOBAL SERVICES.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.swtbot.support.internal.conditions;
+
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+
+/**
+ * An {@link org.eclipse.swtbot.swt.finder.waits.ICondition} only to be used to
+ * deal with unnamed shells. Tests that the active shell is different from the
+ * one given in parameter.
+ *
+ * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
+ */
+public class ShellChangedCondition extends DefaultCondition {
+
+ private SWTBotShell oldShell;
+
+ /**
+ * Tests that the active shell is different from the one given in parameter.
+ *
+ * @param oldShell
+ * the old shell that should change
+ */
+ public ShellChangedCondition(SWTBotShell oldShell) {
+ this.oldShell = oldShell;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ return oldShell.widget != bot.activeShell().widget;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Shell did not activate";
+ }
+
+}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java
index 8cb256aea6..c66f74a539 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java
@@ -14,11 +14,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.sirius.tests.SiriusTestsPlugin;
import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
-import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition;
+import org.eclipse.sirius.tests.swtbot.support.internal.conditions.ShellChangedCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
/**
* This test checks that the securityException opens a popup only in the case of
@@ -54,19 +52,19 @@ public class SecurityExceptionPopupTest extends AbstractSiriusSwtBotGefTestCase
} else {
exception = new SecurityException();
}
-
+ ShellChangedCondition shellChangedCondition = new ShellChangedCondition(bot.activeShell());
SiriusTestsPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, SiriusTestsPlugin.PLUGIN_ID, "exception occurs", exception));
// Step 2 - Check whether the dialog is opened
// or not (if there is no message in the exception, the dialog
// should not be opened).
- Shell shell = null;
+ SWTBotShell shell = null;
try {
- WaitForObjectCondition<Shell> waitForShell = Conditions.waitForShell(WidgetMatcherFactory.<Shell> withText("Permission Issue"));
- bot.waitUntilWidgetAppears(waitForShell);
- shell = waitForShell.getAllMatches().get(0);
- } catch (WidgetNotFoundException e) {
+ bot.waitUntil(shellChangedCondition);
+ shell = bot.activeShell();
+ assertEquals("Permission Issue", shell.getText());
+ } catch (TimeoutException e) {
// We throw the exception only in the case where the
// dialog is expected (a SecurityException with a
// message).
@@ -76,8 +74,7 @@ public class SecurityExceptionPopupTest extends AbstractSiriusSwtBotGefTestCase
}
errors.clear();
if (shell != null) {
- // We close the shell and clear the error log.
- bot.closeAllShells();
+ shell.close();
// If the exception was logged without message, we
// shouldn't have found a shell.
if (!withMessage) {

Back to the top