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

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
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"
brettw 2012/03/13 05:57:49 Unless I missed something, I don't see any new tes
halyavin 2012/03/13 12:48:27 There is no new tests here. But I use this code in
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 int timeout_s_; 106 int timeout_s_;
105 std::string result_; 107 std::string result_;
106 content::NotificationRegistrar registrar_; 108 content::NotificationRegistrar registrar_;
107 base::RepeatingTimer<TestFinishObserver> timer_; 109 base::RepeatingTimer<TestFinishObserver> timer_;
108 110
109 DISALLOW_COPY_AND_ASSIGN(TestFinishObserver); 111 DISALLOW_COPY_AND_ASSIGN(TestFinishObserver);
110 }; 112 };
111 113
112 } // namespace 114 } // namespace
113 115
114 class PPAPITestBase : public InProcessBrowserTest { 116 PPAPITestBase::PPAPITestBase() {
115 public: 117 EnableDOMAutomation();
116 PPAPITestBase() { 118 }
117 EnableDOMAutomation(); 119
120 void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) {
121 // The test sends us the result via a cookie.
122 command_line->AppendSwitch(switches::kEnableFileCookies);
123
124 // Some stuff is hung off of the testing interface which is not enabled
125 // by default.
126 command_line->AppendSwitch(switches::kEnablePepperTesting);
127
128 // Smooth scrolling confuses the scrollbar test.
129 command_line->AppendSwitch(switches::kDisableSmoothScrolling);
130 }
131
132 GURL PPAPITestBase::GetTestFileUrl(const std::string& test_case) {
133 FilePath test_path;
134 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
135 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
136 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
137 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
138
139 // Sanity check the file name.
140 EXPECT_TRUE(file_util::PathExists(test_path));
141
142 GURL test_url = net::FilePathToFileURL(test_path);
143
144 GURL::Replacements replacements;
145 std::string query = BuildQuery("", test_case);
146 replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size()));
147 return test_url.ReplaceComponents(replacements);
148 }
149
150 void PPAPITestBase::RunTest(const std::string& test_case) {
151 GURL url = GetTestFileUrl(test_case);
152 RunTestURL(url);
153 }
154
155 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) {
156 // For HTTP tests, we use the output DIR to grab the generated files such
157 // as the NEXEs.
158 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName();
159 FilePath src_dir;
160 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
161 // TestServer expects a path relative to source. So we must first
162 // generate absolute paths to SRC and EXE and from there generate
163 // a relative path.
164 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir);
165 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir);
166 ASSERT_TRUE(exe_dir.IsAbsolute());
167 ASSERT_TRUE(src_dir.IsAbsolute());
168
169 size_t match, exe_size, src_size;
170 std::vector<FilePath::StringType> src_parts, exe_parts;
171
172 // Determine point at which src and exe diverge, and create a relative path.
173 exe_dir.GetComponents(&exe_parts);
174 src_dir.GetComponents(&src_parts);
175 exe_size = exe_parts.size();
176 src_size = src_parts.size();
177 for (match = 0; match < exe_size && match < src_size; ++match) {
178 if (exe_parts[match] != src_parts[match])
179 break;
118 } 180 }
119 181 FilePath web_dir;
120 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 182 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) {
121 // The test sends us the result via a cookie. 183 web_dir = web_dir.Append(FILE_PATH_LITERAL(".."));
122 command_line->AppendSwitch(switches::kEnableFileCookies);
123
124 // Some stuff is hung off of the testing interface which is not enabled
125 // by default.
126 command_line->AppendSwitch(switches::kEnablePepperTesting);
127
128 // Smooth scrolling confuses the scrollbar test.
129 command_line->AppendSwitch(switches::kDisableSmoothScrolling);
130 } 184 }
131 185 for (; match < exe_size; ++match) {
132 virtual std::string BuildQuery(const std::string& base, 186 web_dir = web_dir.Append(exe_parts[match]);
133 const std::string& test_case) = 0;
134
135 // Returns the URL to load for file: tests.
136 GURL GetTestFileUrl(const std::string& test_case) {
137 FilePath test_path;
138 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_path));
139 test_path = test_path.Append(FILE_PATH_LITERAL("ppapi"));
140 test_path = test_path.Append(FILE_PATH_LITERAL("tests"));
141 test_path = test_path.Append(FILE_PATH_LITERAL("test_case.html"));
142
143 // Sanity check the file name.
144 EXPECT_TRUE(file_util::PathExists(test_path));
145
146 GURL test_url = net::FilePathToFileURL(test_path);
147
148 GURL::Replacements replacements;
149 std::string query = BuildQuery("", test_case);
150 replacements.SetQuery(query.c_str(), url_parse::Component(0, query.size()));
151 return test_url.ReplaceComponents(replacements);
152 } 187 }
153 188
154 void RunTest(const std::string& test_case) { 189 net::TestServer test_server(net::TestServer::TYPE_HTTP,
155 GURL url = GetTestFileUrl(test_case); 190 net::TestServer::kLocalhost,
156 RunTestURL(url); 191 web_dir);
157 } 192 ASSERT_TRUE(test_server.Start());
158 193 std::string query = BuildQuery("files/test_case.html?", test_case);
159 void RunTestViaHTTP(const std::string& test_case) { 194
160 // For HTTP tests, we use the output DIR to grab the generated files such 195 GURL url = test_server.GetURL(query);
161 // as the NEXEs. 196 RunTestURL(url);
162 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); 197 }
163 FilePath src_dir; 198
164 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); 199 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) {
165 200 FilePath websocket_root_dir;
166 // TestServer expects a path relative to source. So we must first 201 ASSERT_TRUE(
167 // generate absolute paths to SRC and EXE and from there generate 202 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir));
168 // a relative path. 203
169 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); 204 ui_test_utils::TestWebSocketServer server;
170 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); 205 ASSERT_TRUE(server.Start(websocket_root_dir));
171 ASSERT_TRUE(exe_dir.IsAbsolute()); 206 RunTestViaHTTP(test_case);
172 ASSERT_TRUE(src_dir.IsAbsolute()); 207 }
173 208
174 size_t match, exe_size, src_size; 209 std::string PPAPITestBase::StripPrefixes(const std::string& test_name) {
175 std::vector<FilePath::StringType> src_parts, exe_parts; 210 const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" };
176 211 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i)
177 // Determine point at which src and exe diverge, and create a relative path. 212 if (test_name.find(prefixes[i]) == 0)
178 exe_dir.GetComponents(&exe_parts); 213 return test_name.substr(strlen(prefixes[i]));
179 src_dir.GetComponents(&src_parts); 214 return test_name;
180 exe_size = exe_parts.size(); 215 }
181 src_size = src_parts.size(); 216
182 for (match = 0; match < exe_size && match < src_size; ++match) { 217 void PPAPITestBase::RunTestURL(const GURL& test_url) {
183 if (exe_parts[match] != src_parts[match]) 218 // See comment above TestingInstance in ppapi/test/testing_instance.h.
184 break; 219 // Basically it sends messages using the DOM automation controller. The
185 } 220 // value of "..." means it's still working and we should continue to wait,
186 FilePath web_dir; 221 // any other value indicates completion (in this case it will start with
187 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { 222 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
188 web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); 223 TestFinishObserver observer(
189 } 224 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs);
190 for (; match < exe_size; ++match) { 225
191 web_dir = web_dir.Append(exe_parts[match]); 226 ui_test_utils::NavigateToURL(browser(), test_url);
192 } 227
193 228 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out.";
194 net::TestServer test_server(net::TestServer::TYPE_HTTP, 229
195 net::TestServer::kLocalhost, 230 EXPECT_STREQ("PASS", observer.result().c_str());
196 web_dir); 231 }
197 ASSERT_TRUE(test_server.Start()); 232
198 std::string query = BuildQuery("files/test_case.html?", test_case); 233 PPAPITest::PPAPITest() {
199 234 }
200 GURL url = test_server.GetURL(query); 235
201 RunTestURL(url); 236 void PPAPITest::SetUpCommandLine(CommandLine* command_line) {
202 } 237 PPAPITestBase::SetUpCommandLine(command_line);
203 238
204 void RunTestWithWebSocketServer(const std::string& test_case) { 239 // Append the switch to register the pepper plugin.
205 FilePath websocket_root_dir; 240 // library name = <out dir>/<test_name>.<library_extension>
206 ASSERT_TRUE( 241 // MIME type = application/x-ppapi-<test_name>
207 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); 242 FilePath plugin_dir;
208 243 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
209 ui_test_utils::TestWebSocketServer server; 244
210 ASSERT_TRUE(server.Start(websocket_root_dir)); 245 FilePath plugin_lib = plugin_dir.Append(library_name);
211 RunTestViaHTTP(test_case); 246 EXPECT_TRUE(file_util::PathExists(plugin_lib));
212 } 247 FilePath::StringType pepper_plugin = plugin_lib.value();
213 248 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
214 std::string StripPrefixes(const std::string& test_name) { 249 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
215 const char* const prefixes[] = { "FAILS_", "FLAKY_", "DISABLED_" }; 250 pepper_plugin);
216 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) 251 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
217 if (test_name.find(prefixes[i]) == 0) 252 }
218 return test_name.substr(strlen(prefixes[i])); 253
219 return test_name; 254 std::string PPAPITest::BuildQuery(const std::string& base,
220 } 255 const std::string& test_case){
221 256 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str());
222 protected: 257 }
223 // Runs the test for a tab given the tab that's already navigated to the 258
224 // given URL. 259 OutOfProcessPPAPITest::OutOfProcessPPAPITest() {
225 void RunTestURL(const GURL& test_url) { 260 }
226 // See comment above TestingInstance in ppapi/test/testing_instance.h. 261
227 // Basically it sends messages using the DOM automation controller. The 262 void OutOfProcessPPAPITest::SetUpCommandLine(CommandLine* command_line) {
228 // value of "..." means it's still working and we should continue to wait, 263 PPAPITest::SetUpCommandLine(command_line);
229 // any other value indicates completion (in this case it will start with 264
230 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. 265 // Run PPAPI out-of-process to exercise proxy implementations.
231 TestFinishObserver observer( 266 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
232 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); 267 }
233 268
234 ui_test_utils::NavigateToURL(browser(), test_url); 269 PPAPINaClTest::PPAPINaClTest() {
235 270 }
236 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; 271
237 272 void PPAPINaClTest::SetUpCommandLine(CommandLine* command_line) {
238 EXPECT_STREQ("PASS", observer.result().c_str()); 273 PPAPITestBase::SetUpCommandLine(command_line);
239 } 274
240 }; 275 FilePath plugin_lib;
241 276 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
242 // In-process plugin test runner. See OutOfProcessPPAPITest below for the 277 EXPECT_TRUE(file_util::PathExists(plugin_lib));
243 // out-of-process version. 278
244 class PPAPITest : public PPAPITestBase { 279 // Enable running NaCl outside of the store.
245 public: 280 command_line->AppendSwitch(switches::kEnableNaCl);
246 PPAPITest() { 281 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
247 } 282 }
248 283
249 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 284 // Append the correct mode and testcase string
250 PPAPITestBase::SetUpCommandLine(command_line); 285 std::string PPAPINaClTest::BuildQuery(const std::string& base,
251 286 const std::string& test_case) {
252 // Append the switch to register the pepper plugin. 287 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
253 // library name = <out dir>/<test_name>.<library_extension> 288 test_case.c_str());
254 // MIME type = application/x-ppapi-<test_name> 289 }
255 FilePath plugin_dir; 290
256 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); 291 PPAPINaClTestDisallowedSockets::PPAPINaClTestDisallowedSockets() {
257 292 }
258 FilePath plugin_lib = plugin_dir.Append(library_name); 293
259 EXPECT_TRUE(file_util::PathExists(plugin_lib)); 294 void PPAPINaClTestDisallowedSockets::SetUpCommandLine(
260 FilePath::StringType pepper_plugin = plugin_lib.value(); 295 CommandLine* command_line) {
261 pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests")); 296 PPAPITestBase::SetUpCommandLine(command_line);
262 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 297
263 pepper_plugin); 298 FilePath plugin_lib;
264 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1"); 299 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
265 } 300 EXPECT_TRUE(file_util::PathExists(plugin_lib));
266 301
267 std::string BuildQuery(const std::string& base, 302 // Enable running NaCl outside of the store.
268 const std::string& test_case){ 303 command_line->AppendSwitch(switches::kEnableNaCl);
269 return StringPrintf("%stestcase=%s", base.c_str(), test_case.c_str()); 304 }
270 } 305
271 306 // Append the correct mode and testcase string
272 }; 307 std::string PPAPINaClTestDisallowedSockets::
273 308 BuildQuery(const std::string& base, const std::string& test_case) {
brettw 2012/03/13 05:57:49 BuildQuery should be on the previous line, then th
halyavin 2012/03/13 12:48:27 Done.
274 // Variant of PPAPITest that runs plugins out-of-process to test proxy 309 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
275 // codepaths. 310 test_case.c_str());
276 class OutOfProcessPPAPITest : public PPAPITest { 311 }
277 public:
278 OutOfProcessPPAPITest() {
279
280 }
281
282 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
283 PPAPITest::SetUpCommandLine(command_line);
284
285 // Run PPAPI out-of-process to exercise proxy implementations.
286 command_line->AppendSwitch(switches::kPpapiOutOfProcess);
287 }
288 };
289
290 // NaCl plugin test runner.
291 class PPAPINaClTest : public PPAPITestBase {
292 public:
293 PPAPINaClTest() {
294 }
295
296 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
297 PPAPITestBase::SetUpCommandLine(command_line);
298
299 FilePath plugin_lib;
300 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
301 EXPECT_TRUE(file_util::PathExists(plugin_lib));
302
303 // Enable running NaCl outside of the store.
304 command_line->AppendSwitch(switches::kEnableNaCl);
305 command_line->AppendSwitchASCII(switches::kAllowNaClSocketAPI, "127.0.0.1");
306 }
307
308 // Append the correct mode and testcase string
309 std::string BuildQuery(const std::string& base,
310 const std::string& test_case) {
311 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
312 test_case.c_str());
313 }
314 };
315
316 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
317 public:
318 PPAPINaClTestDisallowedSockets() {
319 }
320
321 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
322 PPAPITestBase::SetUpCommandLine(command_line);
323
324 FilePath plugin_lib;
325 EXPECT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib));
326 EXPECT_TRUE(file_util::PathExists(plugin_lib));
327
328 // Enable running NaCl outside of the store.
329 command_line->AppendSwitch(switches::kEnableNaCl);
330 }
331
332 // Append the correct mode and testcase string
333 std::string BuildQuery(const std::string& base,
334 const std::string& test_case) {
335 return StringPrintf("%smode=nacl&testcase=%s", base.c_str(),
336 test_case.c_str());
337 }
338 };
339 312
340 // This macro finesses macro expansion to do what we want. 313 // This macro finesses macro expansion to do what we want.
341 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name) 314 #define STRIP_PREFIXES(test_name) StripPrefixes(#test_name)
342 315
343 // Use these macros to run the tests for a specific interface. 316 // Use these macros to run the tests for a specific interface.
344 // Most interfaces should be tested with both macros. 317 // Most interfaces should be tested with both macros.
345 #define TEST_PPAPI_IN_PROCESS(test_name) \ 318 #define TEST_PPAPI_IN_PROCESS(test_name) \
346 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ 319 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
347 RunTest(STRIP_PREFIXES(test_name)); \ 320 RunTest(STRIP_PREFIXES(test_name)); \
348 } 321 }
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) 924 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess)
952 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) 925 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray)
953 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) 926 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement)
954 927
955 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) 928 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics)
956 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) 929 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit)
957 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) 930 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics)
958 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) 931 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit)
959 932
960 #endif // ADDRESS_SANITIZER 933 #endif // ADDRESS_SANITIZER
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698