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

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: Use environment variable to pass file between test and mock_nacl_gdb 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
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::RunTestViaHTTP(const std::string& test_case) {
155 // For HTTP tests, we use the output DIR to grab the generated files such
156 // as the NEXEs.
157 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName();
158 FilePath src_dir;
159 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
160 // TestServer expects a path relative to source. So we must first
Mark Seaborn 2012/03/16 17:47:11 You've changed the whitespace with your move here.
halyavin 2012/03/16 17:57:42 Done.
161 // generate absolute paths to SRC and EXE and from there generate
162 // a relative path.
163 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir);
164 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir);
165 ASSERT_TRUE(exe_dir.IsAbsolute());
166 ASSERT_TRUE(src_dir.IsAbsolute());
167
168 size_t match, exe_size, src_size;
169 std::vector<FilePath::StringType> src_parts, exe_parts;
170
171 // Determine point at which src and exe diverge, and create a relative path.
172 exe_dir.GetComponents(&exe_parts);
173 src_dir.GetComponents(&src_parts);
174 exe_size = exe_parts.size();
175 src_size = src_parts.size();
176 for (match = 0; match < exe_size && match < src_size; ++match) {
177 if (exe_parts[match] != src_parts[match])
178 break;
117 } 179 }
118 180 FilePath web_dir;
119 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 181 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) {
120 // The test sends us the result via a cookie. 182 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 } 183 }
130 184 for (; match < exe_size; ++match) {
131 virtual std::string BuildQuery(const std::string& base, 185 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 } 186 }
152 187
153 void RunTest(const std::string& test_case) { 188 net::TestServer test_server(net::TestServer::TYPE_HTTP,
154 GURL url = GetTestFileUrl(test_case); 189 net::TestServer::kLocalhost,
155 RunTestURL(url); 190 web_dir);
156 } 191 ASSERT_TRUE(test_server.Start());
157 192 std::string query = BuildQuery("files/test_case.html?", test_case);
158 void RunTestViaHTTP(const std::string& test_case) { 193
159 // For HTTP tests, we use the output DIR to grab the generated files such 194 GURL url = test_server.GetURL(query);
160 // as the NEXEs. 195 RunTestURL(url);
161 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); 196 }
162 FilePath src_dir; 197
163 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); 198 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) {
164 199 FilePath websocket_root_dir;
165 // TestServer expects a path relative to source. So we must first 200 ASSERT_TRUE(
166 // generate absolute paths to SRC and EXE and from there generate 201 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir));
167 // a relative path. 202
168 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); 203 ui_test_utils::TestWebSocketServer server;
169 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); 204 ASSERT_TRUE(server.Start(websocket_root_dir));
170 ASSERT_TRUE(exe_dir.IsAbsolute()); 205 RunTestViaHTTP(test_case);
171 ASSERT_TRUE(src_dir.IsAbsolute()); 206 }
172 207
173 size_t match, exe_size, src_size; 208 std::string PPAPITestBase::StripPrefixes(const std::string& test_name) {
174 std::vector<FilePath::StringType> src_parts, exe_parts; 209 const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" };
175 210 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i)
176 // Determine point at which src and exe diverge, and create a relative path. 211 if (test_name.find(prefixes[i]) == 0)
177 exe_dir.GetComponents(&exe_parts); 212 return test_name.substr(strlen(prefixes[i]));
178 src_dir.GetComponents(&src_parts); 213 return test_name;
179 exe_size = exe_parts.size(); 214 }
180 src_size = src_parts.size(); 215
181 for (match = 0; match < exe_size && match < src_size; ++match) { 216 void PPAPITestBase::RunTestURL(const GURL& test_url) {
182 if (exe_parts[match] != src_parts[match]) 217 // See comment above TestingInstance in ppapi/test/testing_instance.h.
183 break; 218 // Basically it sends messages using the DOM automation controller. The
184 } 219 // value of "..." means it's still working and we should continue to wait,
185 FilePath web_dir; 220 // any other value indicates completion (in this case it will start with
186 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { 221 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
187 web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); 222 TestFinishObserver observer(
188 } 223 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs);
189 for (; match < exe_size; ++match) { 224
190 web_dir = web_dir.Append(exe_parts[match]); 225 ui_test_utils::NavigateToURL(browser(), test_url);
191 } 226
192 227 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out.";
193 net::TestServer test_server(net::TestServer::TYPE_HTTP, 228
194 net::TestServer::kLocalhost, 229 EXPECT_STREQ("PASS", observer.result().c_str());
195 web_dir); 230 }
196 ASSERT_TRUE(test_server.Start()); 231
197 std::string query = BuildQuery("files/test_case.html?", test_case); 232 PPAPITest::PPAPITest() {
198 233 }
199 GURL url = test_server.GetURL(query); 234
200 RunTestURL(url); 235 void PPAPITest::SetUpCommandLine(CommandLine* command_line) {
201 } 236 PPAPITestBase::SetUpCommandLine(command_line);
202 237
203 void RunTestWithWebSocketServer(const std::string& test_case) { 238 // Append the switch to register the pepper plugin.
204 FilePath websocket_root_dir; 239 // library name = <out dir>/<test_name>.<library_extension>
205 ASSERT_TRUE( 240 // MIME type = application/x-ppapi-<test_name>
206 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); 241 FilePath plugin_dir;
207 242 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
208 ui_test_utils::TestWebSocketServer server; 243
209 ASSERT_TRUE(server.Start(websocket_root_dir)); 244 FilePath plugin_lib = plugin_dir.Append(library_name);
210 RunTestViaHTTP(test_case); 245 EXPECT_TRUE(file_util::PathExists(plugin_lib));
211 } 246 FilePath::StringType pepper_plugin = plugin_lib.value();
212 247 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
213 std::string StripPrefixes(const std::string& test_name) { 248 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
214 const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" }; 249 pepper_plugin);
215 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) 250 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
216 if (test_name.find(prefixes[i]) == 0) 251 }
217 return test_name.substr(strlen(prefixes[i])); 252
218 return test_name; 253 std::string PPAPITest::BuildQuery(const std::string& base,
219 } 254 const std::string& test_case){
220 255 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
221 protected: 256 }
222 // Runs the test for a tab given the tab that's already navigated to the 257
223 // given URL. 258 OutOfProcessPPAPITest::OutOfProcessPPAPITest() {
224 void RunTestURL(const GURL& test_url) { 259 }
225 // See comment above TestingInstance in ppapi/test/testing_instance.h. 260
226 // Basically it sends messages using the DOM automation controller. The 261 void OutOfProcessPPAPITest::SetUpCommandLine(CommandLine* command_line) {
227 // value of "..." means it's still working and we should continue to wait, 262 PPAPITest::SetUpCommandLine(command_line);
228 // any other value indicates completion (in this case it will start with 263
229 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. 264 // Run PPAPI out-of-process to exercise proxy implementations.
230 TestFinishObserver observer( 265 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
231 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); 266 }
232 267
233 ui_test_utils::NavigateToURL(browser(), test_url); 268 PPAPINaClTest::PPAPINaClTest() {
234 269 }
235 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; 270
236 271 void PPAPINaClTest::SetUpCommandLine(CommandLine* command_line) {
237 EXPECT_STREQ("PASS", observer.result().c_str()); 272 PPAPITestBase::SetUpCommandLine(command_line);
238 } 273
239 }; 274 FilePath plugin_lib;
240 275 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
241 // In-process plugin test runner. See OutOfProcessPPAPITest below for the 276 EXPECT_TRUE(file_util::PathExists(plugin_lib));
242 // out-of-process version. 277
243 class PPAPITest : public PPAPITestBase { 278 // Enable running NaCl outside of the store.
244 public: 279 command_line->AppendSwitch(switches::kEnableNaCl);
245 PPAPITest() { 280 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
246 } 281 }
247 282
248 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 283 // Append the correct mode and testcase string
249 PPAPITestBase::SetUpCommandLine(command_line); 284 std::string PPAPINaClTest::BuildQuery(const std::string& base,
250 285 const std::string& test_case) {
251 // Append the switch to register the pepper plugin. 286 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
252 // library name = <out dir>/<test_name>.<library_extension> 287 test_case.c_str());
253 // MIME type = application/x-ppapi-<test_name> 288 }
254 FilePath plugin_dir; 289
255 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 290 PPAPINaClTestDisallowedSockets::PPAPINaClTestDisallowedSockets() {
256 291 }
257 FilePath plugin_lib = plugin_dir.Append(library_name); 292
258 EXPECT_TRUE(file_util::PathExists(plugin_lib)); 293 void PPAPINaClTestDisallowedSockets::SetUpCommandLine(
259 FilePath::StringType pepper_plugin = plugin_lib.value(); 294 CommandLine* command_line) {
260 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); 295 PPAPITestBase::SetUpCommandLine(command_line);
261 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 296
262 pepper_plugin); 297 FilePath plugin_lib;
263 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); 298 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
264 } 299 EXPECT_TRUE(file_util::PathExists(plugin_lib));
265 300
266 std::string BuildQuery(const std::string& base, 301 // Enable running NaCl outside of the store.
267 const std::string& test_case){ 302 command_line->AppendSwitch(switches::kEnableNaCl);
268 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str()); 303 }
269 } 304
270 305 // Append the correct mode and testcase string
271 }; 306 std::string PPAPINaClTestDisallowedSockets::BuildQuery(
272 307 const std::string& base,
273 // Variant of PPAPITest that runs plugins out-of-process to test proxy 308 const std::string& test_case) {
274 // codepaths. 309 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
275 class OutOfProcessPPAPITest : public PPAPITest { 310 test_case.c_str());
276 public: 311 }
277 OutOfProcessPPAPITest() {
278
279 }
280
281 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
282 PPAPITest::SetUpCommandLine(command_line);
283
284 // Run PPAPI out-of-process to exercise proxy implementations.
285 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
286 }
287 };
288
289 // NaCl plugin test runner.
290 class PPAPINaClTest : public PPAPITestBase {
291 public:
292 PPAPINaClTest() {
293 }
294
295 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
296 PPAPITestBase::SetUpCommandLine(command_line);
297
298 FilePath plugin_lib;
299 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
300 EXPECT_TRUE(file_util::PathExists(plugin_lib));
301
302 // Enable running NaCl outside of the store.
303 command_line->AppendSwitch(switches::kEnableNaCl);
304 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
305 }
306
307 // Append the correct mode and testcase string
308 std::string BuildQuery(const std::string& base,
309 const std::string& test_case) {
310 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
311 test_case.c_str());
312 }
313 };
314
315 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
316 public:
317 PPAPINaClTestDisallowedSockets() {
318 }
319
320 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
321 PPAPITestBase::SetUpCommandLine(command_line);
322
323 FilePath plugin_lib;
324 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
325 EXPECT_TRUE(file_util::PathExists(plugin_lib));
326
327 // Enable running NaCl outside of the store.
328 command_line->AppendSwitch(switches::kEnableNaCl);
329 }
330
331 // Append the correct mode and testcase string
332 std::string BuildQuery(const std::string& base,
333 const std::string& test_case) {
334 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
335 test_case.c_str());
336 }
337 };
338 312
339 // This macro finesses macro expansion to do what we want. 313 // This macro finesses macro expansion to do what we want.
340 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name) 314 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name)
341 315
342 // Use these macros to run the tests for a specific interface. 316 // Use these macros to run the tests for a specific interface.
343 // Most interfaces should be tested with both macros. 317 // Most interfaces should be tested with both macros.
344 #define TEST_PPAPI_IN_PROCESS(test_name) \ 318 #define TEST_PPAPI_IN_PROCESS(test_name) \
345 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ 319 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
346 RunTest(STRIP_PREFIXES(test_name)); \ 320 RunTest(STRIP_PREFIXES(test_name)); \
347 } 321 }
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) 930 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess)
957 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) 931 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray)
958 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) 932 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement)
959 933
960 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) 934 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics)
961 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) 935 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit)
962 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) 936 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics)
963 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) 937 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit)
964 938
965 #endif // ADDRESS_SANITIZER 939 #endif // ADDRESS_SANITIZER
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698