diff options
Diffstat (limited to 'org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java')
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java new file mode 100644 index 000000000..39e3134d3 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AbstractDebugTest.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2017 Andrey Loskutov and others. + * 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: + * Andrey Loskutov <loskutov@gmx.de> - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.intro.IIntroManager; +import org.eclipse.ui.intro.IIntroPart; +import org.eclipse.ui.progress.UIJob; + +import junit.framework.TestCase; + +public class AbstractDebugTest extends TestCase { + + private static boolean welcomeClosed; + + public AbstractDebugTest() { + super(); + } + + public AbstractDebugTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + TestUtil.log(IStatus.INFO, getName(), "setUp"); + assertWelcomeScreenClosed(); + } + + @Override + protected void tearDown() throws Exception { + TestUtil.log(IStatus.INFO, getName(), "tearDown"); + TestUtil.cleanUp(getName()); + super.tearDown(); + } + + /** + * Ensure the welcome screen is closed because in 4.x the debug perspective + * opens a giant fast-view causing issues + * + * @throws Exception + */ + protected final void assertWelcomeScreenClosed() throws Exception { + if (!welcomeClosed && PlatformUI.isWorkbenchRunning()) { + final IWorkbench wb = PlatformUI.getWorkbench(); + if (wb == null) { + return; + } + // In UI thread we don't need to run a job + if (Display.getCurrent() != null) { + closeIntro(wb); + return; + } + + UIJob job = new UIJob("close welcome screen for debug test suite") { + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + closeIntro(wb); + return Status.OK_STATUS; + } + + }; + job.setPriority(Job.INTERACTIVE); + job.setSystem(true); + job.schedule(); + } + } + + private static void closeIntro(final IWorkbench wb) { + IWorkbenchWindow window = wb.getActiveWorkbenchWindow(); + if (window != null) { + IIntroManager im = wb.getIntroManager(); + IIntroPart intro = im.getIntro(); + if (intro != null) { + welcomeClosed = im.closeIntro(intro); + } + } + } +} |