tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / tmf / 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;
67797deb
MK
31import org.eclipse.swt.graphics.FontData;
32import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
33import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
747d62e1 34import org.eclipse.swtbot.swt.finder.SWTBot;
67797deb
MK
35import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
36import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
37import org.eclipse.swtbot.swt.finder.results.Result;
38import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
747d62e1 39import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
67797deb
MK
40import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
41import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
42import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
43import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
44import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
f0beeb4a 46import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
67797deb
MK
47import org.junit.AfterClass;
48import org.junit.BeforeClass;
49import org.junit.Test;
50import org.junit.runner.RunWith;
51
52/**
53 * SWTBot test for testing movable column feature.
54 */
55@RunWith(SWTBotJunit4ClassRunner.class)
56public class FontEventEditorTest {
57
58 private static final String TRACE_PROJECT_NAME = "test";
59 private static final String COLUMN_TRACE = "syslog_collapse";
60 private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
61 private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
62
63 private static File fTestFile = null;
64
65 private static SWTWorkbenchBot fBot;
66
67 /** The Log4j logger instance. */
68 private static final Logger fLogger = Logger.getRootLogger();
69
70 /**
71 * Test Class setup
72 */
73 @BeforeClass
74 public static void init() {
5785ab49 75 SWTBotUtils.initialize();
67797deb
MK
76
77 /* set up test trace */
78 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
79 URI uri;
80 try {
81 uri = FileLocator.toFileURL(location).toURI();
82 fTestFile = new File(uri);
83 } catch (URISyntaxException | IOException e) {
84 fail(e.getMessage());
85 }
86
87 assumeTrue(fTestFile.exists());
88
89 /* Set up for swtbot */
90 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
91 fLogger.removeAllAppenders();
92 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
93 fBot = new SWTWorkbenchBot();
94
95 /* Close welcome view */
96 SWTBotUtils.closeView("Welcome", fBot);
97
98 /* Switch perspectives */
99 SWTBotUtils.switchToTracingPerspective();
100
101 /* Finish waiting for eclipse to load */
f0beeb4a 102 WaitUtils.waitForJobs();
67797deb
MK
103 }
104
105 /**
106 * Test class tear down method.
107 */
108 @AfterClass
109 public static void tearDown() {
110 fLogger.removeAllAppenders();
111 }
112
113 /**
114 * Switch the font to system then back to default.
115 */
116 @Test
117 public void testChangeFont() {
118 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
119
120 // Open the actual trace
121 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
122 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
123
124 SWTBotTable tableBot = editorBot.bot().table();
125
126 // Maximize editor area
328e5fe4 127 SWTBotUtils.maximizeTable(tableBot);
67797deb
MK
128 tableBot.contextMenu("Show Raw").click();
129 tableBot.setFocus();
130 tableBot.click(4, 1);
131 tableBot.select(4);
132
133 SWTBotStyledText rawText = editorBot.bot().styledText();
134
135 FontData font = getFont(rawText);
136
747d62e1 137 SWTBotShell preferencesShell = SWTBotUtils.openPreferences(fBot);
67797deb 138
747d62e1
MAL
139 SWTBot bot = preferencesShell.bot();
140 preferencesShell.activate();
67797deb
MK
141 bot.text().setText("color");
142
143 SWTBotTreeItem generalItem = bot.tree().getTreeItem("General");
144 generalItem.click();
145 generalItem.select();
146 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Appearance", generalItem));
147 SWTBotTreeItem appearanceNode = generalItem.getNode("Appearance");
148 appearanceNode.click();
149 appearanceNode.select();
150 bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable("Colors and Fonts", appearanceNode));
151 SWTBotTreeItem colorAndFontNode = appearanceNode.getNode("Colors and Fonts");
152 colorAndFontNode.click();
153 colorAndFontNode.select();
154 SWTBotTreeItem tracingItem = bot.tree(1).getTreeItem("Tracing");
155 tracingItem.click();
156 tracingItem.select();
157 tracingItem.expand();
158 // Get the raw viewer default which is "Text Font" and change it to "System Font"
159 SWTBotTreeItem traceEventTableFont = tracingItem.getNode("Trace event raw text font (set to default: Text Font)");
160 traceEventTableFont.click();
161 traceEventTableFont.select();
162 bot.button("Use System Font").click();
163 bot.button("Apply").click();
164 FontData font2 = getFont(rawText);
165 assertFalse(font2.equals(font));
166 // Reset the raw viewer to the "Text Font"
167 bot.button("Reset").click();
dd71d1c4 168 bot.button("OK").click();
67797deb
MK
169 assertEquals(getFont(rawText), font);
170 fBot.closeAllEditors();
171 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
172 }
173
174 private static FontData getFont(final SWTBotStyledText rawText) {
175 return UIThreadRunnable.syncExec(new Result<FontData>() {
176 @Override
177 public FontData run() {
178 return rawText.widget.getFont().getFontData()[0];
179 }
180 });
181 }
67797deb 182}
This page took 0.0563709999999999 seconds and 5 git commands to generate.