1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
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 |
|
13 * distribution. |
|
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. |
|
17 * |
|
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. |
|
29 */ |
|
30 |
|
31 #include "config.h" |
|
32 #include "TestShell.h" |
|
33 |
|
34 #include "webkit/support/webkit_support.h" |
|
35 #include <fontconfig/fontconfig.h> |
|
36 #include <signal.h> |
|
37 |
|
38 static void AlarmHandler(int signatl) |
|
39 { |
|
40 // If the alarm alarmed, kill the process since we have a really bad hang. |
|
41 puts("\n#TEST_TIMED_OUT\n"); |
|
42 puts("#EOF\n"); |
|
43 fflush(stdout); |
|
44 exit(0); |
|
45 } |
|
46 |
|
47 static void setupFontconfig() |
|
48 { |
|
49 // We wish to make the layout tests reproducable with respect to fonts. Skia |
|
50 // uses fontconfig to resolve font family names from WebKit into actual font |
|
51 // files found on the current system. This means that fonts vary based on the |
|
52 // system and also on the fontconfig configuration. |
|
53 // |
|
54 // To avoid this we initialise fontconfig here and install a configuration |
|
55 // which only knows about a few, select, fonts. |
|
56 |
|
57 // We have fontconfig parse a config file from our resources file. This |
|
58 // sets a number of aliases ("sans"->"Arial" etc), but doesn't include any |
|
59 // font directories. |
|
60 FcInit(); |
|
61 |
|
62 char drtPath[PATH_MAX + 1]; |
|
63 int drtPathSize = readlink("/proc/self/exe", drtPath, PATH_MAX); |
|
64 if (drtPathSize < 0 || drtPathSize > PATH_MAX) { |
|
65 fputs("Unable to resolve /proc/self/exe.", stderr); |
|
66 exit(1); |
|
67 } |
|
68 drtPath[drtPathSize] = 0; |
|
69 std::string drtDirPath(drtPath); |
|
70 size_t lastPathPos = drtDirPath.rfind("/"); |
|
71 ASSERT(lastPathPos != std::string::npos); |
|
72 drtDirPath.erase(lastPathPos + 1); |
|
73 |
|
74 FcConfig* fontcfg = FcConfigCreate(); |
|
75 std::string fontconfigPath = drtDirPath + "fonts.conf"; |
|
76 if (!FcConfigParseAndLoad(fontcfg, reinterpret_cast<const FcChar8*>(fontconfigPath.c_str()), true)) { |
|
77 fputs("Failed to parse fontconfig config file\n", stderr); |
|
78 exit(1); |
|
79 } |
|
80 |
|
81 // This is the list of fonts that fontconfig will know about. It |
|
82 // will try its best to match based only on the fonts here in. The |
|
83 // paths are where these fonts are found on our Ubuntu boxes. |
|
84 static const char *const fonts[] = { |
|
85 "/usr/share/fonts/truetype/kochi/kochi-gothic.ttf", |
|
86 "/usr/share/fonts/truetype/kochi/kochi-mincho.ttf", |
|
87 "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", |
|
88 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf", |
|
89 "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf", |
|
90 "/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf", |
|
91 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", |
|
92 "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS_Bold.ttf", |
|
93 "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf", |
|
94 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf", |
|
95 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold_Italic.ttf", |
|
96 "/usr/share/fonts/truetype/msttcorefonts/Courier_New_Italic.ttf", |
|
97 "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", |
|
98 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold.ttf", |
|
99 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Bold_Italic.ttf", |
|
100 "/usr/share/fonts/truetype/msttcorefonts/Georgia_Italic.ttf", |
|
101 "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf", |
|
102 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf", |
|
103 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold.ttf", |
|
104 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Bold_Italic.ttf", |
|
105 "/usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS_Italic.ttf", |
|
106 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf", |
|
107 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf", |
|
108 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold_Italic.ttf", |
|
109 "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Italic.ttf", |
|
110 "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf", |
|
111 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold.ttf", |
|
112 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Bold_Italic.ttf", |
|
113 "/usr/share/fonts/truetype/msttcorefonts/Verdana_Italic.ttf", |
|
114 // The DejaVuSans font is used by the css2.1 tests. |
|
115 "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", |
|
116 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf", |
|
117 "/usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf", |
|
118 }; |
|
119 for (size_t i = 0; i < arraysize(fonts); ++i) { |
|
120 if (access(fonts[i], R_OK)) { |
|
121 fprintf(stderr, "You are missing %s. Try installing msttcorefonts. Also see " |
|
122 "http://code.google.com/p/chromium/wiki/LinuxBuildInstructions", |
|
123 fonts[i]); |
|
124 exit(1); |
|
125 } |
|
126 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) fonts[i])) { |
|
127 fprintf(stderr, "Failed to load font %s\n", fonts[i]); |
|
128 exit(1); |
|
129 } |
|
130 } |
|
131 |
|
132 // We special case these fonts because they're only needed in a |
|
133 // few layout tests. |
|
134 static const char* const optionalFonts[] = { |
|
135 "/usr/share/fonts/truetype/ttf-lucida/LucidaSansRegular.ttf", |
|
136 |
|
137 // This font changed paths across Ubuntu releases. |
|
138 "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf", |
|
139 "/usr/share/fonts/truetype/ttf-punjabi-fonts/lohit_pa.ttf", |
|
140 }; |
|
141 for (size_t i = 0; i < arraysize(optionalFonts); ++i) { |
|
142 const char* font = optionalFonts[i]; |
|
143 if (access(font, R_OK) < 0) { |
|
144 fprintf(stderr, "You are missing %s. Without this, some layout tests may fail. " |
|
145 "See http://code.google.com/p/chromium/wiki/LinuxBuildInstructionsPrerequisites " |
|
146 "for more.\n", font); |
|
147 } else { |
|
148 if (!FcConfigAppFontAddFile(fontcfg, (FcChar8 *) font)) { |
|
149 fprintf(stderr, "Failed to load font %s\n", font); |
|
150 exit(1); |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 // Also load the layout-test-specific "Ahem" font. |
|
156 std::string ahemPath = drtDirPath + "AHEM____.TTF"; |
|
157 if (!FcConfigAppFontAddFile(fontcfg, reinterpret_cast<const FcChar8*>(ahemPath.c_str()))) { |
|
158 fprintf(stderr, "Failed to load font %s\n", ahemPath.c_str()); |
|
159 exit(1); |
|
160 } |
|
161 |
|
162 if (!FcConfigSetCurrent(fontcfg)) { |
|
163 fputs("Failed to set the default font configuration\n", stderr); |
|
164 exit(1); |
|
165 } |
|
166 } |
|
167 |
|
168 void TestShell::waitTestFinished() |
|
169 { |
|
170 ASSERT(!m_testIsPending); |
|
171 |
|
172 m_testIsPending = true; |
|
173 |
|
174 // Install an alarm signal handler that will kill us if we time out. |
|
175 signal(SIGALRM, AlarmHandler); |
|
176 alarm(layoutTestTimeoutForWatchDog() / 1000); |
|
177 |
|
178 // TestFinished() will post a quit message to break this loop when the page |
|
179 // finishes loading. |
|
180 while (m_testIsPending) |
|
181 webkit_support::RunMessageLoop(); |
|
182 |
|
183 // Remove the alarm. |
|
184 alarm(0); |
|
185 signal(SIGALRM, SIG_DFL); |
|
186 } |
|
187 |
|
188 void platformInit() |
|
189 { |
|
190 setupFontconfig(); |
|
191 } |
|