swtbot: Introducing ImageHelper
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / FontEventEditorTest.java
CommitLineData
67797deb
MK
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.fail;
18import static org.junit.Assume.assumeTrue;
19
20import java.io.File;
21import java.io.IOException;
22import java.net.URI;
23import java.net.URISyntaxException;
24import java.net.URL;
25
26import org.apache.log4j.ConsoleAppender;
27import org.apache.log4j.Logger;
28import org.apache.log4j.SimpleLayout;
29import org.eclipse.core.runtime.FileLocator;
30import org.eclipse.core.runtime.Path;
31import org.eclipse.jface.bindings.keys.IKeyLookup;
32import org.eclipse.jface.bindings.keys.KeyStroke;
33import org.eclipse.jface.bindings.keys.ParseException;
34import org.eclipse.swt.graphics.FontData;
35import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
36import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
37import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
38import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
39import org.eclipse.swtbot.swt.finder.results.Result;
40import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
41import org.eclipse.swtbot.swt.finder.waits.Conditions;
42import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
43import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
44import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
45import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
46import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
47import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
48import org.junit.AfterClass;
49import org.junit.BeforeClass;
50import org.junit.Test;
51import org.junit.runner.RunWith;
52
53/**
54 * SWTBot test for testing movable column feature.
55 */
56@RunWith(SWTBotJunit4ClassRunner.class)
57public class FontEventEditorTest {
58
59 private static final String TRACE_PROJECT_NAME = "test";
60 private static final String COLUMN_TRACE = "syslog_collapse";
61 private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
62 private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
63
64 private static File fTestFile = null;
65
66 private static SWTWorkbenchBot fBot;
67
68 /** The Log4j logger instance. */
69 private static final Logger fLogger = Logger.getRootLogger();
70
71 /**
72 * Test Class setup
73 */
74 @BeforeClass
75 public static void init() {
76 SWTBotUtils.failIfUIThread();
77
78 /* set up test trace */
79 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
80 URI uri;
81 try {
82 uri = FileLocator.toFileURL(location).toURI();
83 fTestFile = new File(uri);
84 } catch (URISyntaxException | IOException e) {
85 fail(e.getMessage());
86 }
87
88 assumeTrue(fTestFile.exists());
89
90 /* Set up for swtbot */
91 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
92 fLogger.removeAllAppenders();
93 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
94 fBot = new SWTWorkbenchBot();
95
96 /* Close welcome view */
97 SWTBotUtils.closeView("Welcome", fBot);
98
99 /* Switch perspectives */
100 SWTBotUtils.switchToTracingPerspective();
101
102 /* Finish waiting for eclipse to load */
103 SWTBotUtils.waitForJobs();
104 }
105
106 /**
107 * Test class tear down method.
108 */
109 @AfterClass
110 public static void tearDown() {
111 fLogger.removeAllAppenders();
112 }
113
114 /**
115 * Switch the font to system then back to default.
116 */
117 @Test
118 public void testChangeFont() {
119 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
120
121 // Open the actual trace
122 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
123 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
124
125 SWTBotTable tableBot = editorBot.bot().table();
126
127 // Maximize editor area
128 maximizeTable(tableBot);
129 tableBot.contextMenu("Show Raw").click();
130 tableBot.setFocus();
131 tableBot.click(4, 1);
132 tableBot.select(4);
133
134 SWTBotStyledText rawText = editorBot.bot().styledText();
135
136 FontData font = getFont(rawText);
137
138 fBot.menu("Window").menu("Preferences").click();
139
140 fBot.waitUntil(Conditions.shellIsActive("Preferences"));
141 SWTWorkbenchBot bot = new SWTWorkbenchBot();
142 bot.activeShell().activate();
143 bot.text().setText("color");
144
145 SWTBotTreeItem generalItem = bot.tree().getTreeItem("General");
146 generalItem.click();
147 generalItem.select();
148 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Appearance", generalItem));
149 SWTBotTreeItem appearanceNode = generalItem.getNode("Appearance");
150 appearanceNode.click();
151 appearanceNode.select();
152 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Colors and Fonts", appearanceNode));
153 SWTBotTreeItem colorAndFontNode = appearanceNode.getNode("Colors and Fonts");
154 colorAndFontNode.click();
155 colorAndFontNode.select();
156 SWTBotTreeItem tracingItem = bot.tree(1).getTreeItem("Tracing");
157 tracingItem.click();
158 tracingItem.select();
159 tracingItem.expand();
160 // Get the raw viewer default which is "Text Font" and change it to "System Font"
161 SWTBotTreeItem traceEventTableFont = tracingItem.getNode("Trace event raw text font (set to default: Text Font)");
162 traceEventTableFont.click();
163 traceEventTableFont.select();
164 bot.button("Use System Font").click();
165 bot.button("Apply").click();
166 FontData font2 = getFont(rawText);
167 assertFalse(font2.equals(font));
168 // Reset the raw viewer to the "Text Font"
169 bot.button("Reset").click();
170 bot.button("Apply").click();
171 assertEquals(getFont(rawText), font);
172 fBot.closeAllEditors();
173 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
174 }
175
176 private static FontData getFont(final SWTBotStyledText rawText) {
177 return UIThreadRunnable.syncExec(new Result<FontData>() {
178 @Override
179 public FontData run() {
180 return rawText.widget.getFont().getFontData()[0];
181 }
182 });
183 }
184
185 private static void maximizeTable(SWTBotTable tableBot) {
186 try {
187 tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
188 } catch (ParseException e) {
189 fail();
190 }
191 }
192
193}
This page took 0.032127 seconds and 5 git commands to generate.