Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest.cc
blob1e48883240fc886f6f73455cc20d1b4014356509
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
3 // found in the LICENSE file.
5 #include <stdio.h>
6 #if defined(OS_POSIX)
7 #include <unistd.h>
8 #elif defined(OS_WIN)
9 #include <windows.h>
10 #endif
12 #define TELEMETRY 1
14 #include "base/command_line.h"
15 #include "base/environment.h"
16 #include "base/path_service.h"
17 #include "base/process/kill.h"
18 #include "base/process/launch.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/win/windows_version.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/nacl/nacl_browsertest_util.h"
23 #include "components/nacl/browser/nacl_browser.h"
24 #include "components/nacl/common/nacl_switches.h"
25 #include "content/public/common/content_switches.h"
27 namespace {
29 #if defined(OS_WIN)
30 // crbug.com/98721
31 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
32 #else
33 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
34 #endif
36 NACL_BROWSER_TEST_F(NaClBrowserTest, SimpleLoad, {
37 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
40 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode, MAYBE_NONSFI(Messaging)) {
41 RunLoadTest(FILE_PATH_LITERAL("libc_free.html"));
44 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode, MAYBE_NONSFI(Irt)) {
45 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_test.html"));
48 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus0, {
49 RunNaClIntegrationTest(FILE_PATH_LITERAL(
50 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
53 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus254, {
54 RunNaClIntegrationTest(FILE_PATH_LITERAL(
55 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
58 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatusNeg2, {
59 RunNaClIntegrationTest(FILE_PATH_LITERAL(
60 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
63 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPICore, {
64 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
67 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPBInstance, {
68 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
71 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPPInstance, {
72 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
75 NACL_BROWSER_TEST_F(NaClBrowserTest, ProgressEvents, {
76 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
79 // Note: currently not run on PNaCl because crash throttling causes the last few
80 // tests to fail for the wrong reasons. Enabling this test would also require
81 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
82 // allowed. Also not run on GLibc because it's a large test that is at risk of
83 // causing timeouts.
84 // crbug/338444
85 #if defined(OS_WIN)
86 #define MAYBE_Bad DISABLED_Bad
87 #else
88 #define MAYBE_Bad Bad
89 #endif
90 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, MAYBE_Bad) {
91 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
94 // partially_invalid.c does not have an ARM version of its asm.
95 #if !defined(__arm__)
96 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, BadNative) {
97 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
99 #endif
101 #if defined(OS_WIN)
102 // crbug.com/98721
103 # define MAYBE_Crash DISABLED_Crash
104 #elif defined(OS_LINUX)
105 // crbug.com/366334
106 # define MAYBE_Crash DISABLED_Crash
107 #else
108 # define MAYBE_Crash Crash
109 #endif
110 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
111 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
114 // PNaCl version does not work.
115 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, ManifestFile) {
116 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
118 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, ManifestFile) {
119 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
121 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, PreInitManifestFile) {
122 RunNaClIntegrationTest(FILE_PATH_LITERAL(
123 "pm_pre_init_manifest_file_test.html"));
125 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, PreInitManifestFile) {
126 RunNaClIntegrationTest(FILE_PATH_LITERAL(
127 "pm_pre_init_manifest_file_test.html"));
129 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtManifestFile) {
130 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
132 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
133 MAYBE_PNACL_NONSFI(IrtManifestFile)) {
134 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
137 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtException) {
138 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
140 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
141 MAYBE_PNACL_NONSFI(IrtException)) {
142 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
145 NACL_BROWSER_TEST_F(NaClBrowserTest, Nameservice, {
146 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_nameservice_test.html"));
149 // Some versions of Visual Studio does not like preprocessor
150 // conditionals inside the argument of a macro, so we put the
151 // conditionals on a helper function. We are already in an anonymous
152 // namespace, so the name of the helper is not visible in external
153 // scope.
154 #if defined(OS_POSIX)
155 base::FilePath::StringType NumberOfCoresAsFilePathString() {
156 char string_rep[23];
157 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
158 #if TELEMETRY
159 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
160 fflush(NULL);
161 #endif
162 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
163 return string_rep;
165 #elif defined(OS_WIN)
166 base::FilePath::StringType NumberOfCoresAsFilePathString() {
167 wchar_t string_rep[23];
168 SYSTEM_INFO system_info;
169 GetSystemInfo(&system_info);
170 #if TELEMETRY
171 fprintf(stderr, "browser says nprocessors = %d\n",
172 system_info.dwNumberOfProcessors);
173 fflush(NULL);
174 #endif
175 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
176 L"%u", system_info.dwNumberOfProcessors);
177 return string_rep;
179 #endif
181 #if TELEMETRY
182 static void PathTelemetry(base::FilePath::StringType const &path) {
183 # if defined(OS_WIN)
184 fwprintf(stderr, L"path = %s\n", path.c_str());
185 # else
186 fprintf(stderr, "path = %s\n", path.c_str());
187 # endif
188 fflush(NULL);
190 #else
191 static void PathTelemetry(base::FilePath::StringType const &path) {
192 (void) path;
194 #endif
196 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
197 base::FilePath::StringType path =
198 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
199 path = path + NumberOfCoresAsFilePathString();
200 PathTelemetry(path);
201 RunNaClIntegrationTest(path);
204 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
205 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
208 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
209 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
212 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
213 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
216 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
217 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
220 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, RelativeManifest) {
221 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
224 // Test with the NaCl debug flag turned on.
225 class NaClBrowserTestPnaclDebug : public NaClBrowserTestPnacl {
226 public:
227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
228 NaClBrowserTestPnacl::SetUpCommandLine(command_line);
229 // Turn on debugging to influence the PNaCl URL loaded
230 command_line->AppendSwitch(switches::kEnableNaClDebug);
231 // On windows, the debug stub requires --no-sandbox:
232 // crbug.com/265624
233 #if defined(OS_WIN)
234 command_line->AppendSwitch(switches::kNoSandbox);
235 #endif
238 // On some platforms this test does not work.
239 bool TestIsBroken() {
240 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
241 // is used, the required 1GB sandbox address space is not reserved.
242 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
243 #if defined(OS_WIN)
244 if (base::win::OSInfo::GetInstance()->wow64_status() ==
245 base::win::OSInfo::WOW64_DISABLED &&
246 base::win::OSInfo::GetInstance()->architecture() ==
247 base::win::OSInfo::X86_ARCHITECTURE) {
248 return true;
250 #endif
251 return false;
254 void StartTestScript(base::ProcessHandle* test_process,
255 int debug_stub_port) {
256 // We call a python script that speaks to the debug stub, and
257 // lets the app continue, so that the load progress event completes.
258 CommandLine cmd(base::FilePath(FILE_PATH_LITERAL("python")));
259 base::FilePath script;
260 PathService::Get(base::DIR_SOURCE_ROOT, &script);
261 script = script.AppendASCII(
262 "chrome/browser/nacl_host/test/debug_stub_browser_tests.py");
263 cmd.AppendArgPath(script);
264 cmd.AppendArg(base::IntToString(debug_stub_port));
265 cmd.AppendArg("continue");
266 LOG(INFO) << cmd.GetCommandLineString();
267 base::LaunchProcess(cmd, base::LaunchOptions(), test_process);
270 void RunWithTestDebugger(const base::FilePath::StringType& test_url) {
271 base::ProcessHandle test_script;
272 scoped_ptr<base::Environment> env(base::Environment::Create());
273 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
274 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript,
275 base::Unretained(this), &test_script));
276 // Turn on debug stub logging.
277 env->SetVar("NACLVERBOSITY", "1");
278 RunLoadTest(test_url);
279 env->UnSetVar("NACLVERBOSITY");
280 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
281 int exit_code;
282 LOG(INFO) << "Waiting for script to exit (which waits for embed to die).";
283 base::WaitForExitCode(test_script, &exit_code);
284 EXPECT_EQ(0, exit_code);
288 // Test with the NaCl debug flag turned on, but mask off every URL
289 // so that nothing is actually debugged.
290 class NaClBrowserTestPnaclDebugMasked : public NaClBrowserTestPnaclDebug {
291 public:
292 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
293 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line);
294 command_line->AppendSwitchASCII(switches::kNaClDebugMask,
295 "!<all_urls>");
299 // The tests which actually start a debug session must use the debug stub
300 // to continue the app startup. However, NaCl on windows can't open the
301 // debug stub socket in the browser process as needed by the test.
302 // See http://crbug.com/157312.
303 #if defined(OS_WIN)
304 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
305 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
306 #else
307 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
308 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
309 #endif
310 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
311 MAYBE_PnaclDebugURLFlagAndURL) {
312 RunWithTestDebugger(FILE_PATH_LITERAL(
313 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
316 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
317 MAYBE_PnaclDebugURLFlagNoURL) {
318 RunWithTestDebugger(FILE_PATH_LITERAL(
319 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
322 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
323 MAYBE_PNACL(PnaclDebugURLFlagOff)) {
324 RunLoadTest(FILE_PATH_LITERAL(
325 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
328 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked,
329 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff)) {
330 if (TestIsBroken()) {
331 return;
333 // If the mask excludes debugging, it's as if the flag was off.
334 RunLoadTest(FILE_PATH_LITERAL(
335 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
338 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
339 MAYBE_PNACL(PnaclErrorHandling)) {
340 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
343 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
344 MAYBE_PNACL(PnaclNMFOptionsO0)) {
345 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
348 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
349 MAYBE_PNACL(PnaclNMFOptionsO2)) {
350 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
353 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
354 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
355 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
358 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
359 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
360 RunNaClIntegrationTest(FILE_PATH_LITERAL(
361 "pnacl_dyncode_syscall_disabled.html"));
364 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
365 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
366 RunNaClIntegrationTest(FILE_PATH_LITERAL(
367 "pnacl_exception_handling_disabled.html"));
370 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
371 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
374 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDisabled, PnaclMimeType) {
375 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
378 class NaClBrowserTestNewlibStdoutPM : public NaClBrowserTestNewlib {
379 public:
380 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
381 // Env needs to be set early because nacl_helper is spawned before the test
382 // body on Linux.
383 scoped_ptr<base::Environment> env(base::Environment::Create());
384 env->SetVar("NACL_EXE_STDOUT", "DEBUG_ONLY:dev://postmessage");
385 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
389 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg0) {
390 RunNaClIntegrationTest(FILE_PATH_LITERAL(
391 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=0"));
394 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg0) {
395 RunNaClIntegrationTest(FILE_PATH_LITERAL(
396 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=0"));
399 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg1) {
400 RunNaClIntegrationTest(FILE_PATH_LITERAL(
401 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=1000000"));
404 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg1) {
405 RunNaClIntegrationTest(FILE_PATH_LITERAL(
406 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=1000000"));
409 class NaClBrowserTestNewlibStderrPM : public NaClBrowserTestNewlib {
410 public:
411 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
412 // Env needs to be set early because nacl_helper is spawned before the test
413 // body on Linux.
414 scoped_ptr<base::Environment> env(base::Environment::Create());
415 env->SetVar("NACL_EXE_STDERR", "DEBUG_ONLY:dev://postmessage");
416 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
420 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg0) {
421 RunNaClIntegrationTest(FILE_PATH_LITERAL(
422 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=0"));
425 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg0) {
426 RunNaClIntegrationTest(FILE_PATH_LITERAL(
427 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=0"));
430 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg1) {
431 RunNaClIntegrationTest(FILE_PATH_LITERAL(
432 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=1000000"));
435 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg1) {
436 RunNaClIntegrationTest(FILE_PATH_LITERAL(
437 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=1000000"));
440 class NaClBrowserTestNewlibExtension : public NaClBrowserTestNewlib {
441 public:
442 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
443 NaClBrowserTestNewlib::SetUpCommandLine(command_line);
444 base::FilePath src_root;
445 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_root));
447 base::FilePath document_root;
448 ASSERT_TRUE(GetDocumentRoot(&document_root));
450 // Document root is relative to source root, and source root may not be CWD.
451 command_line->AppendSwitchPath(switches::kLoadExtension,
452 src_root.Append(document_root));
456 // TODO(ncbray) support glibc and PNaCl
457 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension, MimeHandler) {
458 RunNaClIntegrationTest(FILE_PATH_LITERAL(
459 "ppapi_extension_mime_handler.html"));
462 } // namespace