|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2006, 2016 Mountainminds GmbH & Co. KG and Contributors |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * Evgeny Mandrikov - initial API and implementation |
| 10 | + * |
| 11 | + ******************************************************************************/ |
| 12 | +package org.eclipse.eclemma.ui; |
| 13 | + |
| 14 | +import static org.junit.Assert.assertEquals; |
| 15 | + |
| 16 | +import java.util.ArrayList; |
| 17 | + |
| 18 | +import org.eclipse.core.commands.ExecutionEvent; |
| 19 | +import org.eclipse.core.commands.ExecutionException; |
| 20 | +import org.eclipse.core.resources.IProject; |
| 21 | +import org.eclipse.core.resources.IProjectDescription; |
| 22 | +import org.eclipse.core.resources.ResourcesPlugin; |
| 23 | +import org.eclipse.core.runtime.CoreException; |
| 24 | +import org.eclipse.core.runtime.preferences.InstanceScope; |
| 25 | +import org.eclipse.eclemma.core.ICoverageSession; |
| 26 | +import org.eclipse.eclemma.core.launching.ICoverageLaunch; |
| 27 | +import org.eclipse.eclemma.internal.ui.dialogs.MergeSessionsDialog; |
| 28 | +import org.eclipse.eclemma.internal.ui.handlers.DumpExecutionDataHandler; |
| 29 | +import org.eclipse.eclemma.internal.ui.handlers.SelectActiveSessionHandler; |
| 30 | +import org.eclipse.jdt.core.JavaCore; |
| 31 | +import org.eclipse.jface.resource.JFaceResources; |
| 32 | +import org.eclipse.swt.graphics.FontData; |
| 33 | +import org.eclipse.swt.widgets.Control; |
| 34 | +import org.eclipse.swt.widgets.Widget; |
| 35 | +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
| 36 | +import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; |
| 37 | +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 38 | +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
| 39 | +import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 40 | +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; |
| 41 | +import org.eclipse.ui.PlatformUI; |
| 42 | +import org.eclipse.ui.actions.ActionFactory; |
| 43 | +import org.eclipse.ui.preferences.ScopedPreferenceStore; |
| 44 | +import org.hamcrest.CoreMatchers; |
| 45 | +import org.junit.After; |
| 46 | +import org.junit.Before; |
| 47 | +import org.junit.BeforeClass; |
| 48 | +import org.junit.Test; |
| 49 | + |
| 50 | +public class FontChangeTest { |
| 51 | + |
| 52 | + private static final SWTWorkbenchBot bot = new SWTWorkbenchBot(); |
| 53 | + |
| 54 | + private FontData expected; |
| 55 | + |
| 56 | + @BeforeClass |
| 57 | + public static void closeWelcomeView() { |
| 58 | + try { |
| 59 | + bot.viewByTitle("Welcome").close(); |
| 60 | + } catch (WidgetNotFoundException e) { |
| 61 | + // ignore |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @Before |
| 66 | + public void changeFont() { |
| 67 | + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.ui.workbench"); |
| 68 | + expected = new FontData(store.getString(JFaceResources.DIALOG_FONT)); |
| 69 | + expected.setHeight(expected.getHeight() + 1); |
| 70 | + store.setValue(JFaceResources.DIALOG_FONT, expected.toString()); |
| 71 | + } |
| 72 | + |
| 73 | + @After |
| 74 | + public void resetWorkbench() { |
| 75 | + bot.resetWorkbench(); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Test for {@link org.eclipse.eclemma.internal.ui.dialogs.CoveragePreferencePage}. |
| 80 | + */ |
| 81 | + @Test |
| 82 | + public void preferencePage() { |
| 83 | + // This does not work on Mac |
| 84 | + // bot.menu("Window").menu("Preferences").click(); |
| 85 | + // Launch preferences programmatically instead |
| 86 | + UIThreadRunnable.asyncExec(new VoidResult() { |
| 87 | + public void run() { |
| 88 | + ActionFactory.PREFERENCES.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run(); |
| 89 | + } |
| 90 | + }); |
| 91 | + |
| 92 | + bot.shell("Preferences").activate(); |
| 93 | + bot.tree().getTreeItem("Java").expand().getNode("Code Coverage").select(); |
| 94 | + |
| 95 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_preferences_context"))); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Test for {@link org.eclipse.eclemma.internal.ui.wizards.SessionImportPage1} and {@link org.eclipse.eclemma.internal.ui.wizards.SessionImportPage2}. |
| 100 | + */ |
| 101 | + @Test |
| 102 | + public void importWizard() { |
| 103 | + bot.menu("File").menu("Import...").click(); |
| 104 | + bot.shell("Import").activate(); |
| 105 | + |
| 106 | + SWTBotTreeItem treeItem = bot.tree().getTreeItem("Run/Debug").expand(); |
| 107 | + treeItem.getNode("Coverage Session").select(); |
| 108 | + bot.button("Next >").click(); |
| 109 | + |
| 110 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_import_context"))); |
| 111 | + |
| 112 | + bot.radio("Agent address:").click(); |
| 113 | + bot.button("Next >").click(); |
| 114 | + |
| 115 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_import_context"))); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Test for {@link org.eclipse.eclemma.internal.ui.wizards.SessionExportPage1}. |
| 120 | + */ |
| 121 | + @Test |
| 122 | + public void exportWizard() { |
| 123 | + bot.menu("File").menu("Export...").click(); |
| 124 | + bot.shell("Export").activate(); |
| 125 | + |
| 126 | + SWTBotTreeItem treeItem = bot.tree().getTreeItem("Run/Debug").expand(); |
| 127 | + treeItem.getNode("Coverage Session").select(); |
| 128 | + bot.button("Next >").click(); |
| 129 | + |
| 130 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.session_export_context"))); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Test for {@link org.eclipse.eclemma.internal.ui.dialogs.CoveragePropertyPage}. |
| 135 | + */ |
| 136 | + @Test |
| 137 | + public void propertyPage() throws CoreException { |
| 138 | + createProject(); |
| 139 | + |
| 140 | + bot.viewByTitle("Project Explorer").bot().tree().select("prj").contextMenu().menu("Properties", false, 0).click(); |
| 141 | + bot.shell("Properties for prj").activate(); |
| 142 | + bot.tree().select("Coverage"); |
| 143 | + |
| 144 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_properties_context"))); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Test for {@link org.eclipse.eclemma.ui.launching.CoverageTab}. |
| 149 | + */ |
| 150 | + @Test |
| 151 | + public void launchingTab() throws CoreException { |
| 152 | + createProject(); |
| 153 | + |
| 154 | + bot.viewByTitle("Project Explorer").bot().tree().select("prj").contextMenu("Coverage As").menu("Coverage Configurations...").click(); |
| 155 | + bot.shell("Coverage Configurations").activate(); |
| 156 | + bot.tree().getTreeItem("Java Application").contextMenu("New").click(); |
| 157 | + bot.cTabItem("Coverage").activate(); |
| 158 | + |
| 159 | + assertFont(expected, bot.widget(WidgetMatcherFactory.withId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.coverage_launch_tab_context"))); |
| 160 | + } |
| 161 | + |
| 162 | + private static void createProject() throws CoreException { |
| 163 | + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("prj"); |
| 164 | + if (project.exists()) { |
| 165 | + project.delete(true, null); |
| 166 | + } |
| 167 | + project.create(null); |
| 168 | + project.open(null); |
| 169 | + IProjectDescription description = project.getDescription(); |
| 170 | + description.setNatureIds(new String[] { JavaCore.NATURE_ID }); |
| 171 | + project.setDescription(description, null); |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Test for {@link org.eclipse.eclemma.internal.ui.dialogs.MergeSessionsDialog}. |
| 176 | + */ |
| 177 | + @Test |
| 178 | + public void mergeSessionsDialog() { |
| 179 | + UIThreadRunnable.asyncExec(new VoidResult() { |
| 180 | + public void run() { |
| 181 | + new MergeSessionsDialog(bot.activeShell().widget, new ArrayList<ICoverageSession>(), "").open(); |
| 182 | + } |
| 183 | + }); |
| 184 | + |
| 185 | + UIThreadRunnable.syncExec(new VoidResult() { |
| 186 | + public void run() { |
| 187 | + assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.merge_sessions_context").widget.getChildren()[0]); |
| 188 | + } |
| 189 | + }); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Test for {@link org.eclipse.eclemma.internal.ui.handlers.SelectActiveSessionHandler}. |
| 194 | + */ |
| 195 | + @Test |
| 196 | + public void selectActiveSessionDialog() throws ExecutionException { |
| 197 | + UIThreadRunnable.asyncExec(new VoidResult() { |
| 198 | + public void run() { |
| 199 | + try { |
| 200 | + new SelectActiveSessionHandler().execute(new ExecutionEvent()); |
| 201 | + } catch (ExecutionException e) { |
| 202 | + throw new RuntimeException(e); |
| 203 | + } |
| 204 | + } |
| 205 | + }); |
| 206 | + |
| 207 | + assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.select_active_session_context").widget); |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * Test for {@link org.eclipse.eclemma.internal.ui.handlers.DumpExecutionDataHandler#openDialog(ExecutionEvent, java.util.List)}. |
| 212 | + */ |
| 213 | + @Test |
| 214 | + public void selectLaunchDialog() { |
| 215 | + UIThreadRunnable.asyncExec(new VoidResult() { |
| 216 | + public void run() { |
| 217 | + DumpExecutionDataHandler.openDialog(new ExecutionEvent(), new ArrayList<ICoverageLaunch>()); |
| 218 | + } |
| 219 | + }); |
| 220 | + |
| 221 | + assertFont(expected, bot.shellWithId("org.eclipse.ui.help", "org.eclipse.eclemma.ui.dump_execution_data").widget); |
| 222 | + } |
| 223 | + |
| 224 | + private static void assertFont(final FontData expected, final Widget parentWidget) { |
| 225 | + UIThreadRunnable.syncExec(new VoidResult() { |
| 226 | + public void run() { |
| 227 | + for (Control widget : bot.widgets(CoreMatchers.any(Control.class), parentWidget)) { |
| 228 | + FontData actual = widget.getFont().getFontData()[0]; |
| 229 | + assertEquals(widget + " font", expected, actual); |
| 230 | + } |
| 231 | + } |
| 232 | + }); |
| 233 | + } |
| 234 | + |
| 235 | +} |
0 commit comments