Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest.cc
blob30b6053091da9a52bd5fa1bedc5a16bcea7c1e7d
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_paths.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/test/nacl/nacl_browsertest_util.h"
24 #include "components/nacl/browser/nacl_browser.h"
25 #include "components/nacl/common/nacl_switches.h"
26 #include "content/public/common/content_switches.h"
28 namespace {
30 #if defined(OS_WIN)
31 // crbug.com/98721
32 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
33 #else
34 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
35 #endif
37 NACL_BROWSER_TEST_F(NaClBrowserTest, SimpleLoad, {
38 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
41 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode, MAYBE_NONSFI(Messaging)) {
42 RunLoadTest(FILE_PATH_LITERAL("libc_free.html"));
45 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode, MAYBE_NONSFI(Irt)) {
46 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_test.html"));
49 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus0, {
50 RunNaClIntegrationTest(FILE_PATH_LITERAL(
51 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
54 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus254, {
55 RunNaClIntegrationTest(FILE_PATH_LITERAL(
56 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
59 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatusNeg2, {
60 RunNaClIntegrationTest(FILE_PATH_LITERAL(
61 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
64 #if defined(ADDRESS_SANITIZER)
65 #define Maybe_PPAPICore DISABLED_PPAPICore
66 #else
67 #define Maybe_PPAPICore PPAPICore
68 #endif
69 NACL_BROWSER_TEST_F(NaClBrowserTest, Maybe_PPAPICore, {
70 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
73 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPBInstance, {
74 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
77 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPPInstance, {
78 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
81 NACL_BROWSER_TEST_F(NaClBrowserTest, ProgressEvents, {
82 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
85 // Note: currently not run on PNaCl because crash throttling causes the last few
86 // tests to fail for the wrong reasons. Enabling this test would also require
87 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
88 // allowed. Also not run on GLibc because it's a large test that is at risk of
89 // causing timeouts.
90 // crbug/338444
91 #if defined(OS_WIN)
92 #define MAYBE_Bad DISABLED_Bad
93 #else
94 #define MAYBE_Bad Bad
95 #endif
96 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, MAYBE_Bad) {
97 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
100 // partially_invalid.c does not have an ARM version of its asm.
101 #if !defined(__arm__)
102 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, BadNative) {
103 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
105 #endif
107 #if defined(OS_WIN)
108 // crbug.com/98721
109 # define MAYBE_Crash DISABLED_Crash
110 #elif defined(OS_LINUX)
111 // crbug.com/366334
112 # define MAYBE_Crash DISABLED_Crash
113 #else
114 # define MAYBE_Crash Crash
115 #endif
116 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
117 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
120 // PNaCl version does not work.
121 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, ManifestFile) {
122 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
124 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, MAYBE_GLIBC(ManifestFile)) {
125 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
127 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, PreInitManifestFile) {
128 RunNaClIntegrationTest(FILE_PATH_LITERAL(
129 "pm_pre_init_manifest_file_test.html"));
131 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc,
132 MAYBE_GLIBC(PreInitManifestFile)) {
133 RunNaClIntegrationTest(FILE_PATH_LITERAL(
134 "pm_pre_init_manifest_file_test.html"));
136 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtManifestFile) {
137 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
139 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
140 MAYBE_PNACL_NONSFI(IrtManifestFile)) {
141 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
144 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtException) {
145 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
147 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
148 MAYBE_PNACL_NONSFI(IrtException)) {
149 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
152 NACL_BROWSER_TEST_F(NaClBrowserTest, Nameservice, {
153 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_nameservice_test.html"));
156 // Some versions of Visual Studio does not like preprocessor
157 // conditionals inside the argument of a macro, so we put the
158 // conditionals on a helper function. We are already in an anonymous
159 // namespace, so the name of the helper is not visible in external
160 // scope.
161 #if defined(OS_POSIX)
162 base::FilePath::StringType NumberOfCoresAsFilePathString() {
163 char string_rep[23];
164 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
165 #if TELEMETRY
166 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
167 fflush(NULL);
168 #endif
169 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
170 return string_rep;
172 #elif defined(OS_WIN)
173 base::FilePath::StringType NumberOfCoresAsFilePathString() {
174 wchar_t string_rep[23];
175 SYSTEM_INFO system_info;
176 GetSystemInfo(&system_info);
177 #if TELEMETRY
178 fprintf(stderr, "browser says nprocessors = %lu\n",
179 system_info.dwNumberOfProcessors);
180 fflush(NULL);
181 #endif
182 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
183 L"%u", system_info.dwNumberOfProcessors);
184 return string_rep;
186 #endif
188 #if TELEMETRY
189 static void PathTelemetry(base::FilePath::StringType const &path) {
190 # if defined(OS_WIN)
191 fwprintf(stderr, L"path = %s\n", path.c_str());
192 # else
193 fprintf(stderr, "path = %s\n", path.c_str());
194 # endif
195 fflush(NULL);
197 #else
198 static void PathTelemetry(base::FilePath::StringType const &path) {
199 (void) path;
201 #endif
203 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
204 base::FilePath::StringType path =
205 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
206 path = path + NumberOfCoresAsFilePathString();
207 PathTelemetry(path);
208 RunNaClIntegrationTest(path);
211 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
212 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
215 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
216 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
219 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
220 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
223 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
224 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
227 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, RelativeManifest) {
228 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
231 // Test with the NaCl debug flag turned on.
232 class NaClBrowserTestPnaclDebug : public NaClBrowserTestPnacl {
233 public:
234 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
235 NaClBrowserTestPnacl::SetUpCommandLine(command_line);
236 // Turn on debugging to influence the PNaCl URL loaded
237 command_line->AppendSwitch(switches::kEnableNaClDebug);
238 // On windows, the debug stub requires --no-sandbox:
239 // crbug.com/265624
240 #if defined(OS_WIN)
241 command_line->AppendSwitch(switches::kNoSandbox);
242 #endif
245 // On some platforms this test does not work.
246 bool TestIsBroken() {
247 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
248 // is used, the required 1GB sandbox address space is not reserved.
249 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
250 #if defined(OS_WIN)
251 if (base::win::OSInfo::GetInstance()->wow64_status() ==
252 base::win::OSInfo::WOW64_DISABLED &&
253 base::win::OSInfo::GetInstance()->architecture() ==
254 base::win::OSInfo::X86_ARCHITECTURE) {
255 return true;
257 #endif
258 return false;
261 void StartTestScript(base::ProcessHandle* test_process,
262 int debug_stub_port) {
263 // We call a python script that speaks to the debug stub, and
264 // lets the app continue, so that the load progress event completes.
265 CommandLine cmd(base::FilePath(FILE_PATH_LITERAL("python")));
266 base::FilePath script;
267 PathService::Get(chrome::DIR_TEST_DATA, &script);
268 script = script.AppendASCII("nacl/debug_stub_browser_tests.py");
269 cmd.AppendArgPath(script);
270 cmd.AppendArg(base::IntToString(debug_stub_port));
271 cmd.AppendArg("continue");
272 LOG(INFO) << cmd.GetCommandLineString();
273 base::LaunchProcess(cmd, base::LaunchOptions(), test_process);
276 void RunWithTestDebugger(const base::FilePath::StringType& test_url) {
277 base::ProcessHandle test_script;
278 scoped_ptr<base::Environment> env(base::Environment::Create());
279 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
280 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript,
281 base::Unretained(this), &test_script));
282 // Turn on debug stub logging.
283 env->SetVar("NACLVERBOSITY", "1");
284 RunLoadTest(test_url);
285 env->UnSetVar("NACLVERBOSITY");
286 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
287 int exit_code;
288 LOG(INFO) << "Waiting for script to exit (which waits for embed to die).";
289 base::WaitForExitCode(test_script, &exit_code);
290 EXPECT_EQ(0, exit_code);
294 // Test with the NaCl debug flag turned on, but mask off every URL
295 // so that nothing is actually debugged.
296 class NaClBrowserTestPnaclDebugMasked : public NaClBrowserTestPnaclDebug {
297 public:
298 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
299 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line);
300 command_line->AppendSwitchASCII(switches::kNaClDebugMask,
301 "!<all_urls>");
305 // The tests which actually start a debug session must use the debug stub
306 // to continue the app startup. However, NaCl on windows can't open the
307 // debug stub socket in the browser process as needed by the test.
308 // See http://crbug.com/157312.
309 #if defined(OS_WIN)
310 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
311 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
312 #else
313 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
314 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
315 #endif
316 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
317 MAYBE_PnaclDebugURLFlagAndURL) {
318 RunWithTestDebugger(FILE_PATH_LITERAL(
319 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
322 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
323 MAYBE_PnaclDebugURLFlagNoURL) {
324 RunWithTestDebugger(FILE_PATH_LITERAL(
325 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
328 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
329 MAYBE_PNACL(PnaclDebugURLFlagOff)) {
330 RunLoadTest(FILE_PATH_LITERAL(
331 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
334 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked,
335 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff)) {
336 if (TestIsBroken()) {
337 return;
339 // If the mask excludes debugging, it's as if the flag was off.
340 RunLoadTest(FILE_PATH_LITERAL(
341 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
344 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
345 MAYBE_PNACL(PnaclErrorHandling)) {
346 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
349 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
350 MAYBE_PNACL(PnaclNMFOptionsO0)) {
351 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
354 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
355 MAYBE_PNACL(PnaclNMFOptionsO2)) {
356 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
359 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
360 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
361 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
364 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
365 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
366 RunNaClIntegrationTest(FILE_PATH_LITERAL(
367 "pnacl_dyncode_syscall_disabled.html"));
370 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
371 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
372 RunNaClIntegrationTest(FILE_PATH_LITERAL(
373 "pnacl_hw_eh_disabled.html"));
376 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
377 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
380 class NaClBrowserTestNewlibStdoutPM : public NaClBrowserTestNewlib {
381 public:
382 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
383 // Env needs to be set early because nacl_helper is spawned before the test
384 // body on Linux.
385 scoped_ptr<base::Environment> env(base::Environment::Create());
386 env->SetVar("NACL_EXE_STDOUT", "DEBUG_ONLY:dev://postmessage");
387 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
391 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg0) {
392 RunNaClIntegrationTest(FILE_PATH_LITERAL(
393 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=0"));
396 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg0) {
397 RunNaClIntegrationTest(FILE_PATH_LITERAL(
398 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=0"));
401 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg1) {
402 RunNaClIntegrationTest(FILE_PATH_LITERAL(
403 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=1000000"));
406 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg1) {
407 RunNaClIntegrationTest(FILE_PATH_LITERAL(
408 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=1000000"));
411 class NaClBrowserTestNewlibStderrPM : public NaClBrowserTestNewlib {
412 public:
413 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
414 // Env needs to be set early because nacl_helper is spawned before the test
415 // body on Linux.
416 scoped_ptr<base::Environment> env(base::Environment::Create());
417 env->SetVar("NACL_EXE_STDERR", "DEBUG_ONLY:dev://postmessage");
418 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
422 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg0) {
423 RunNaClIntegrationTest(FILE_PATH_LITERAL(
424 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=0"));
427 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg0) {
428 RunNaClIntegrationTest(FILE_PATH_LITERAL(
429 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=0"));
432 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg1) {
433 RunNaClIntegrationTest(FILE_PATH_LITERAL(
434 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=1000000"));
437 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg1) {
438 RunNaClIntegrationTest(FILE_PATH_LITERAL(
439 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=1000000"));
442 // TODO(ncbray) support glibc and PNaCl
443 // flaky: crbug.com/375894
444 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension, DISABLED_MimeHandler) {
445 RunNaClIntegrationTest(FILE_PATH_LITERAL(
446 "ppapi_extension_mime_handler.html"));
449 } // namespace