Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/test/ui/ppapi_uitest.cc

Issue 9662055: Test for --nacl-gdb functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/ui/ppapi_uitest.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/ui/ppapi_uitest.h"
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
6 #include "base/file_util.h" 8 #include "base/file_util.h"
7 #include "base/path_service.h" 9 #include "base/path_service.h"
8 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
9 #include "base/string_util.h" 11 #include "base/string_util.h"
10 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
11 #include "base/timer.h" 13 #include "base/timer.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_navigator.h" 16 #include "chrome/browser/ui/browser_navigator.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 int timeout_s_; 105 int timeout_s_;
104 std::string result_; 106 std::string result_;
105 content::NotificationRegistrar registrar_; 107 content::NotificationRegistrar registrar_;
106 base::RepeatingTimer<TestFinishObserver> timer_; 108 base::RepeatingTimer<TestFinishObserver> timer_;
107 109
108 DISALLOW_COPY_AND_ASSIGN(TestFinishObserver); 110 DISALLOW_COPY_AND_ASSIGN(TestFinishObserver);
109 }; 111 };
110 112
111 } // namespace 113 } // namespace
112 114
113 class PPAPITestBase : public InProcessBrowserTest { 115 PPAPITestBase::PPAPITestBase() {
114 public: 116 EnableDOMAutomation();
115 PPAPITestBase() { 117 }
116 EnableDOMAutomation(); 118
119 void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) {
120 // The test sends us the result via a cookie.
121 command_line->AppendSwitch(switches::kEnableFileCookies);
122
123 // Some stuff is hung off of the testing interface which is not enabled
124 // by default.
125 command_line->AppendSwitch(switches::kEnablePepperTesting);
126
127 // Smooth scrolling confuses the scrollbar test.
128 command_line->AppendSwitch(switches::kDisableSmoothScrolling);
129 }
130
131 GURL PPAPITestBase::GetTestFileUrl(const std::string& test_case) {
132 FilePath test_path;
133 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
134 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
135 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
136 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
137
138 // Sanity check the file name.
139 EXPECT_TRUE(file_util::PathExists(test_path));
140
141 GURL test_url = net::FilePathToFileURL(test_path);
142
143 GURL::Replacements replacements;
144 std::string query = BuildQuery("", test_case);
145 replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size()));
146 return test_url.ReplaceComponents(replacements);
147 }
148
149 void PPAPITestBase::RunTest(const std::string& test_case) {
150 GURL url = GetTestFileUrl(test_case);
151 RunTestURL(url);
152 }
153
154 void PPAPITestBase::RunTestAndReload(const std::string& test_case) {
155 GURL url = GetTestFileUrl(test_case);
156 RunTestURL(url);
157 // If that passed, we simply run the test again, which navigates again.
158 RunTestURL(url);
159 }
160
161 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) {
162 // For HTTP tests, we use the output DIR to grab the generated files such
163 // as the NEXEs.
164 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName();
165 FilePath src_dir;
166 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
167
168 // TestServer expects a path relative to source. So we must first
169 // generate absolute paths to SRC and EXE and from there generate
170 // a relative path.
171 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir);
172 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir);
173 ASSERT_TRUE(exe_dir.IsAbsolute());
174 ASSERT_TRUE(src_dir.IsAbsolute());
175
176 size_t match, exe_size, src_size;
177 std::vector<FilePath::StringType> src_parts, exe_parts;
178
179 // Determine point at which src and exe diverge, and create a relative path.
180 exe_dir.GetComponents(&exe_parts);
181 src_dir.GetComponents(&src_parts);
182 exe_size = exe_parts.size();
183 src_size = src_parts.size();
184 for (match = 0; match < exe_size && match < src_size; ++match) {
185 if (exe_parts[match] != src_parts[match])
186 break;
117 } 187 }
118 188 FilePath web_dir;
119 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 189 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) {
120 // The test sends us the result via a cookie. 190 web_dir = web_dir.Append(FILE_PATH_LITERAL(".."));
121 command_line->AppendSwitch(switches::kEnableFileCookies);
122
123 // Some stuff is hung off of the testing interface which is not enabled
124 // by default.
125 command_line->AppendSwitch(switches::kEnablePepperTesting);
126
127 // Smooth scrolling confuses the scrollbar test.
128 command_line->AppendSwitch(switches::kDisableSmoothScrolling);
129 } 191 }
130 192 for (; match < exe_size; ++match) {
131 virtual std::string BuildQuery(const std::string& base, 193 web_dir = web_dir.Append(exe_parts[match]);
132 const std::string& test_case) = 0;
133
134 // Returns the URL to load for file: tests.
135 GURL GetTestFileUrl(const std::string& test_case) {
136 FilePath test_path;
137 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
138 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
139 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
140 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
141
142 // Sanity check the file name.
143 EXPECT_TRUE(file_util::PathExists(test_path));
144
145 GURL test_url = net::FilePathToFileURL(test_path);
146
147 GURL::Replacements replacements;
148 std::string query = BuildQuery("", test_case);
149 replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size()));
150 return test_url.ReplaceComponents(replacements);
151 } 194 }
152 195
153 void RunTest(const std::string& test_case) { 196 net::TestServer test_server(net::TestServer::TYPE_HTTP,
154 GURL url = GetTestFileUrl(test_case); 197 net::TestServer::kLocalhost,
155 RunTestURL(url); 198 web_dir);
156 } 199 ASSERT_TRUE(test_server.Start());
157 200 std::string query = BuildQuery("files/test_case.html?", test_case);
158 // Run the test and reload. This can test for clean shutdown, including leaked 201
159 // instance object vars. 202 GURL url = test_server.GetURL(query);
160 void RunTestAndReload(const std::string& test_case) { 203 RunTestURL(url);
161 GURL url = GetTestFileUrl(test_case); 204 }
162 RunTestURL(url); 205
163 // If that passed, we simply run the test again, which navigates again. 206 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) {
164 RunTestURL(url); 207 FilePath websocket_root_dir;
165 } 208 ASSERT_TRUE(
166 209 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir));
167 void RunTestViaHTTP(const std::string& test_case) { 210
168 // For HTTP tests, we use the output DIR to grab the generated files such 211 ui_test_utils::TestWebSocketServer server;
169 // as the NEXEs. 212 int port = server.UseRandomPort();
170 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); 213 ASSERT_TRUE(server.Start(websocket_root_dir));
171 FilePath src_dir; 214 std::string url = StringPrintf("%s&websocket_port=%d",
172 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); 215 test_case.c_str(), port);
173 216 RunTestViaHTTP(url);
174 // TestServer expects a path relative to source. So we must first 217 }
175 // generate absolute paths to SRC and EXE and from there generate 218
176 // a relative path. 219 std::string PPAPITestBase::StripPrefixes(const std::string& test_name) {
177 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); 220 const char* const prefixes[] = {
178 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); 221 "FAILS_", "FLAKY_", "DISABLED_", "SLOW_" };
179 ASSERT_TRUE(exe_dir.IsAbsolute()); 222 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i)
180 ASSERT_TRUE(src_dir.IsAbsolute()); 223 if (test_name.find(prefixes[i]) == 0)
181 224 return test_name.substr(strlen(prefixes[i]));
182 size_t match, exe_size, src_size; 225 return test_name;
183 std::vector<FilePath::StringType> src_parts, exe_parts; 226 }
184 227
185 // Determine point at which src and exe diverge, and create a relative path. 228 void PPAPITestBase::RunTestURL(const GURL& test_url) {
186 exe_dir.GetComponents(&exe_parts); 229 // See comment above TestingInstance in ppapi/test/testing_instance.h.
187 src_dir.GetComponents(&src_parts); 230 // Basically it sends messages using the DOM automation controller. The
188 exe_size = exe_parts.size(); 231 // value of "..." means it's still working and we should continue to wait,
189 src_size = src_parts.size(); 232 // any other value indicates completion (in this case it will start with
190 for (match = 0; match < exe_size && match < src_size; ++match) { 233 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
191 if (exe_parts[match] != src_parts[match]) 234 TestFinishObserver observer(
192 break; 235 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs);
193 } 236
194 FilePath web_dir; 237 ui_test_utils::NavigateToURL(browser(), test_url);
195 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { 238
196 web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); 239 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out.";
197 } 240
198 for (; match < exe_size; ++match) { 241 EXPECT_STREQ("PASS", observer.result().c_str());
199 web_dir = web_dir.Append(exe_parts[match]); 242 }
200 } 243
201 244 PPAPITest::PPAPITest() {
202 net::TestServer test_server(net::TestServer::TYPE_HTTP, 245 }
203 net::TestServer::kLocalhost, 246
204 web_dir); 247 void PPAPITest::SetUpCommandLine(CommandLine* command_line) {
205 ASSERT_TRUE(test_server.Start()); 248 PPAPITestBase::SetUpCommandLine(command_line);
206 std::string query = BuildQuery("files/test_case.html?", test_case); 249
207 250 // Append the switch to register the pepper plugin.
208 GURL url = test_server.GetURL(query); 251 // library name = <out dir>/<test_name>.<library_extension>
209 RunTestURL(url); 252 // MIME type = application/x-ppapi-<test_name>
210 } 253 FilePath plugin_dir;
211 254 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
212 void RunTestWithWebSocketServer(const std::string& test_case) { 255
213 FilePath websocket_root_dir; 256 FilePath plugin_lib = plugin_dir.Append(library_name);
214 ASSERT_TRUE( 257 EXPECT_TRUE(file_util::PathExists(plugin_lib));
215 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); 258 FilePath::StringType pepper_plugin = plugin_lib.value();
216 259 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
217 ui_test_utils::TestWebSocketServer server; 260 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
218 int port = server.UseRandomPort(); 261 pepper_plugin);
219 ASSERT_TRUE(server.Start(websocket_root_dir)); 262 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
220 std::string url = StringPrintf("%s&websocket_port=%d", 263 }
221 test_case.c_str(), port); 264
222 RunTestViaHTTP(url); 265 std::string PPAPITest::BuildQuery(const std::string& base,
223 } 266 const std::string& test_case){
224 267 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
225 std::string StripPrefixes(const std::string& test_name) { 268 }
226 const char* const prefixes[] = { 269
227 "FAILS_", "FLAKY_", "DISABLED_", "SLOW_" }; 270 OutOfProcessPPAPITest::OutOfProcessPPAPITest() {
228 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) 271 }
229 if (test_name.find(prefixes[i]) == 0) 272
230 return test_name.substr(strlen(prefixes[i])); 273 void OutOfProcessPPAPITest::SetUpCommandLine(CommandLine* command_line) {
231 return test_name; 274 PPAPITest::SetUpCommandLine(command_line);
232 } 275
233 276 // Run PPAPI out-of-process to exercise proxy implementations.
234 protected: 277 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
235 // Runs the test for a tab given the tab that's already navigated to the 278 }
236 // given URL. 279
237 void RunTestURL(const GURL& test_url) { 280 PPAPINaClTest::PPAPINaClTest() {
238 // See comment above TestingInstance in ppapi/test/testing_instance.h. 281 }
239 // Basically it sends messages using the DOM automation controller. The 282
240 // value of "..." means it's still working and we should continue to wait, 283 void PPAPINaClTest::SetUpCommandLine(CommandLine* command_line) {
241 // any other value indicates completion (in this case it will start with 284 PPAPITestBase::SetUpCommandLine(command_line);
242 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. 285
243 TestFinishObserver observer( 286 FilePath plugin_lib;
244 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); 287 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
245 288 EXPECT_TRUE(file_util::PathExists(plugin_lib));
246 ui_test_utils::NavigateToURL(browser(), test_url); 289
247 290 // Enable running NaCl outside of the store.
248 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; 291 command_line->AppendSwitch(switches::kEnableNaCl);
249 292 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
250 EXPECT_STREQ("PASS", observer.result().c_str()); 293 }
251 } 294
252 }; 295 // Append the correct mode and testcase string
253 296 std::string PPAPINaClTest::BuildQuery(const std::string& base,
254 // In-process plugin test runner. See OutOfProcessPPAPITest below for the 297 const std::string& test_case) {
255 // out-of-process version. 298 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
256 class PPAPITest : public PPAPITestBase { 299 test_case.c_str());
257 public: 300 }
258 PPAPITest() { 301
259 } 302 PPAPINaClTestDisallowedSockets::PPAPINaClTestDisallowedSockets() {
260 303 }
261 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 304
262 PPAPITestBase::SetUpCommandLine(command_line); 305 void PPAPINaClTestDisallowedSockets::SetUpCommandLine(
263 306 CommandLine* command_line) {
264 // Append the switch to register the pepper plugin. 307 PPAPITestBase::SetUpCommandLine(command_line);
265 // library name = <out dir>/<test_name>.<library_extension> 308
266 // MIME type = application/x-ppapi-<test_name> 309 FilePath plugin_lib;
267 FilePath plugin_dir; 310 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
268 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 311 EXPECT_TRUE(file_util::PathExists(plugin_lib));
269 312
270 FilePath plugin_lib = plugin_dir.Append(library_name); 313 // Enable running NaCl outside of the store.
271 EXPECT_TRUE(file_util::PathExists(plugin_lib)); 314 command_line->AppendSwitch(switches::kEnableNaCl);
272 FilePath::StringType pepper_plugin = plugin_lib.value(); 315 }
273 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); 316
274 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 317 // Append the correct mode and testcase string
275 pepper_plugin); 318 std::string PPAPINaClTestDisallowedSockets::BuildQuery(
276 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); 319 const std::string& base,
277 } 320 const std::string& test_case) {
278 321 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
279 std::string BuildQuery(const std::string& base, 322 test_case.c_str());
280 const std::string& test_case){ 323 }
281 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
282 }
283
284 };
285
286 // Variant of PPAPITest that runs plugins out-of-process to test proxy
287 // codepaths.
288 class OutOfProcessPPAPITest : public PPAPITest {
289 public:
290 OutOfProcessPPAPITest() {
291 }
292
293 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
294 PPAPITest::SetUpCommandLine(command_line);
295
296 // Run PPAPI out-of-process to exercise proxy implementations.
297 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
298 }
299 };
300
301 // NaCl plugin test runner.
302 class PPAPINaClTest : public PPAPITestBase {
303 public:
304 PPAPINaClTest() {
305 }
306
307 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
308 PPAPITestBase::SetUpCommandLine(command_line);
309
310 FilePath plugin_lib;
311 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
312 EXPECT_TRUE(file_util::PathExists(plugin_lib));
313
314 // Enable running NaCl outside of the store.
315 command_line->AppendSwitch(switches::kEnableNaCl);
316 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
317 }
318
319 // Append the correct mode and testcase string
320 std::string BuildQuery(const std::string& base,
321 const std::string& test_case) {
322 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
323 test_case.c_str());
324 }
325 };
326
327 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
328 public:
329 PPAPINaClTestDisallowedSockets() {
330 }
331
332 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
333 PPAPITestBase::SetUpCommandLine(command_line);
334
335 FilePath plugin_lib;
336 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
337 EXPECT_TRUE(file_util::PathExists(plugin_lib));
338
339 // Enable running NaCl outside of the store.
340 command_line->AppendSwitch(switches::kEnableNaCl);
341 }
342
343 // Append the correct mode and testcase string
344 std::string BuildQuery(const std::string& base,
345 const std::string& test_case) {
346 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
347 test_case.c_str());
348 }
349 };
350 324
351 // This macro finesses macro expansion to do what we want. 325 // This macro finesses macro expansion to do what we want.
352 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name) 326 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name)
353 327
354 // Use these macros to run the tests for a specific interface. 328 // Use these macros to run the tests for a specific interface.
355 // Most interfaces should be tested with both macros. 329 // Most interfaces should be tested with both macros.
356 #define TEST_PPAPI_IN_PROCESS(test_name) \ 330 #define TEST_PPAPI_IN_PROCESS(test_name) \
357 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ 331 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
358 RunTest(STRIP_PREFIXES(test_name)); \ 332 RunTest(STRIP_PREFIXES(test_name)); \
359 } 333 }
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) 957 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess)
984 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) 958 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray)
985 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) 959 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement)
986 960
987 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) 961 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics)
988 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) 962 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit)
989 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) 963 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics)
990 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) 964 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit)
991 965
992 #endif // ADDRESS_SANITIZER 966 #endif // ADDRESS_SANITIZER
OLDNEW
« no previous file with comments | « chrome/test/ui/ppapi_uitest.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698