2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "TestShell.h"
34 #include "SkTypeface.h"
36 #include "webkit/support/webkit_support.h"
39 #include <fontconfig/fontconfig.h>
48 static void AlarmHandler(int)
50 // If the alarm alarmed, kill the process since we have a really bad hang.
51 puts("\n#TEST_TIMED_OUT\n");
57 void TestShell::waitTestFinished()
59 ASSERT(!m_testIsPending);
60 m_testIsPending = true;
62 // Install an alarm signal handler that will kill us if we time out.
63 struct sigaction alarmAction;
64 alarmAction.sa_handler = AlarmHandler;
65 sigemptyset(&alarmAction.sa_mask);
66 alarmAction.sa_flags = 0;
68 struct sigaction oldAction;
69 sigaction(SIGALRM, &alarmAction, &oldAction);
70 alarm(layoutTestTimeoutForWatchDog() / 1000);
72 // TestFinished() will post a quit message to break this loop when the page
74 while (m_testIsPending)
75 webkit_support::RunMessageLoop();
79 sigaction(SIGALRM, &oldAction, 0);
83 static void setupFontconfig()
85 // We wish to make the layout tests reproducable with respect to fonts. Skia
86 // uses fontconfig to resolve font family names from WebKit into actual font
87 // files found on the current system. This means that fonts vary based on the
88 // system and also on the fontconfig configuration.
90 // To avoid this we initialise fontconfig here and install a configuration
91 // which only knows about a few, select, fonts.
93 // We have fontconfig parse a config file from our resources file. This
94 // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any
98 char drtPath[PATH_MAX + 1];
99 int drtPathSize = readlink("/proc/self/exe", drtPath, PATH_MAX);
100 if (drtPathSize < 0 || drtPathSize > PATH_MAX) {
101 fputs("Unable to resolve /proc/self/exe.", stderr);
104 drtPath[drtPathSize] = 0;
105 std::string drtDirPath(drtPath);
106 size_t lastPathPos = drtDirPath.rfind("/");
107 ASSERT(lastPathPos != std::string::npos);
108 drtDirPath.erase(lastPathPos + 1);
110 FcConfig* fontcfg = FcConfigCreate();
111 std::string fontconfigPath = drtDirPath + "fonts.conf";
112 if (!FcConfigParseAndLoad(fontcfg, reinterpret_cast<const FcChar8*>(fontconfigPath.c_str()), true)) {
113 fputs("Failed to parse fontconfig config file\n", stderr);
117 // This is the list of fonts that fontconfig will know about. It
118 // will try its best to match based only on the fonts here in. The
119 // paths are where these fonts are found on our Ubuntu boxes.
120 static const char *const fonts[] = {
121 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf",
122 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf",
123 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
124 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf",
125 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf",
126 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf",
127 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf",
128 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf",
129 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf",
130 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf",
131 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf",
132 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf",
133 "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf",
134 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf",
135 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf",
136 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf",
137 "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf",
138 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf",
139 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf",
140 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf",
141 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf",
142 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",
143 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf",
144 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf",
145 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf",
146 "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf",
147 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf",
148 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf",
149 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf",
150 "/usr/share/fonts/truetype/thai/Garuda.ttf",
151 // The DejaVuSans font is used by the css2.1 tests.
152 "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
153 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf",
154 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf",
155 "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf",
157 for (size_t i = 0; i < arraysize(fonts); ++i) {
158 if (access(fonts[i], R_OK)) {
159 fprintf(stderr, "You are missing %s. Try re-running build/install-build-deps.sh. Also see "
160 "http://code.google.com/p/chromium/wiki/LayoutTestsLinux",
164 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) fonts[i])) {
165 fprintf(stderr, "Failed to load font %s\n", fonts[i]);
170 // We special case these fonts because they're only needed in a
172 static const char* const optionalFonts[] = {
173 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf",
175 for (size_t i = 0; i < arraysize(optionalFonts); ++i) {
176 const char* font = optionalFonts[i];
178 // This font changed paths across Ubuntu releases, so try checking in both locations.
179 if (!strcmp(font, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf")
180 && access(font, R_OK) < 0)
181 font = "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf";
183 if (access(font, R_OK) < 0) {
184 fprintf(stderr, "You are missing %s. Without this, some layout tests may fail. "
185 "See http://code.google.com/p/chromium/wiki/LayoutTestsLinux "
186 "for more.\n", font);
187 } else if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) {
188 fprintf(stderr, "Failed to load font %s\n", font);
193 // Also load the layout-test-specific "Ahem" font.
194 std::string ahemPath = drtDirPath + "AHEM____.TTF";
195 if (!FcConfigAppFontAddFile(fontcfg, reinterpret_cast<const FcChar8*>(ahemPath.c_str()))) {
196 fprintf(stderr, "Failed to load font %s\n", ahemPath.c_str());
200 if (!FcConfigSetCurrent(fontcfg)) {
201 fputs("Failed to set the default font configuration\n", stderr);
205 #endif // !OS(ANDROID)
207 void platformInit(int* argc, char*** argv)
209 // FIXME: It's better call gtk_init() only when we run plugin tests.
210 // See http://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/633ea167cde196ca#
212 gtk_init(argc, argv);