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.
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/process/process.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/win/windows_version.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/nacl/nacl_browsertest_util.h"
25 #include "components/nacl/browser/nacl_browser.h"
26 #include "components/nacl/common/nacl_switches.h"
27 #include "content/public/common/content_switches.h"
33 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
35 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
38 NACL_BROWSER_TEST_F(NaClBrowserTest
, SimpleLoad
, {
39 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
42 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode
, MAYBE_NONSFI(Messaging
)) {
43 RunLoadTest(FILE_PATH_LITERAL("libc_free.html"));
46 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode
, MAYBE_NONSFI(Irt
)) {
47 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_test.html"));
50 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus0
, {
51 RunNaClIntegrationTest(FILE_PATH_LITERAL(
52 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
55 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus254
, {
56 RunNaClIntegrationTest(FILE_PATH_LITERAL(
57 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
60 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatusNeg2
, {
61 RunNaClIntegrationTest(FILE_PATH_LITERAL(
62 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
65 #if defined(ADDRESS_SANITIZER)
66 #define Maybe_PPAPICore DISABLED_PPAPICore
68 #define Maybe_PPAPICore PPAPICore
70 NACL_BROWSER_TEST_F(NaClBrowserTest
, Maybe_PPAPICore
, {
71 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
74 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPBInstance
, {
75 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
78 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPPInstance
, {
79 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
82 NACL_BROWSER_TEST_F(NaClBrowserTest
, ProgressEvents
, {
83 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
86 // Note: currently not run on PNaCl because crash throttling causes the last few
87 // tests to fail for the wrong reasons. Enabling this test would also require
88 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
89 // allowed. Also not run on GLibc because it's a large test that is at risk of
93 #define MAYBE_Bad DISABLED_Bad
97 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_Bad
) {
98 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
101 // partially_invalid.c does not have an ARM version of its asm.
102 #if !defined(__arm__)
103 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, BadNative
) {
104 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
110 # define MAYBE_CrashViaCheckFailure DISABLED_CrashViaCheckFailure
111 # define MAYBE_CrashViaExitCall DISABLED_CrashViaExitCall
112 # define MAYBE_CrashInCallback DISABLED_CrashInCallback
113 # define MAYBE_CrashOffMainThread DISABLED_CrashOffMainThread
114 # define MAYBE_CrashPPAPIOffMainThread DISABLED_CrashPPAPIOffMainThread
115 #elif defined(OS_MACOSX)
117 # define MAYBE_CrashViaCheckFailure DISABLED_CrashViaCheckFailure
118 # define MAYBE_CrashViaExitCall DISABLED_CrashViaExitCall
119 # define MAYBE_CrashInCallback DISABLED_CrashInCallback
120 # define MAYBE_CrashOffMainThread DISABLED_CrashOffMainThread
121 # define MAYBE_CrashPPAPIOffMainThread DISABLED_CrashPPAPIOffMainThread
123 # define MAYBE_CrashViaCheckFailure CrashViaCheckFailure
124 # define MAYBE_CrashViaExitCall CrashViaExitCall
125 # define MAYBE_CrashInCallback CrashInCallback
126 # define MAYBE_CrashOffMainThread CrashOffMainThread
127 # define MAYBE_CrashPPAPIOffMainThread CrashPPAPIOffMainThread
129 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashViaCheckFailure
, {
130 RunNaClIntegrationTest(
131 FILE_PATH_LITERAL("ppapi_crash_via_check_failure.html"));
134 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashViaExitCall
, {
135 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash_via_exit_call.html"));
138 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashInCallback
, {
139 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash_in_callback.html"));
142 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashOffMainThread
, {
143 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash_off_main_thread.html"));
146 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashPPAPIOffMainThread
, {
147 RunNaClIntegrationTest(
148 FILE_PATH_LITERAL("ppapi_crash_ppapi_off_main_thread.html"));
151 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, IrtManifestFile
) {
152 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
154 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
155 MAYBE_PNACL_NONSFI(IrtManifestFile
)) {
156 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
160 // http://crbug.com/416272
161 #define MAYBE_IrtException DISABLED_IrtException
163 #define MAYBE_IrtException IrtException
165 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_IrtException
) {
166 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
168 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
169 MAYBE_PNACL_NONSFI(IrtException
)) {
170 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
173 // Some versions of Visual Studio does not like preprocessor
174 // conditionals inside the argument of a macro, so we put the
175 // conditionals on a helper function. We are already in an anonymous
176 // namespace, so the name of the helper is not visible in external
178 #if defined(OS_POSIX)
179 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
181 long nprocessors
= sysconf(_SC_NPROCESSORS_ONLN
);
183 fprintf(stderr
, "browser says nprocessors = %ld\n", nprocessors
);
186 snprintf(string_rep
, sizeof string_rep
, "%ld", nprocessors
);
189 #elif defined(OS_WIN)
190 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
191 wchar_t string_rep
[23];
192 SYSTEM_INFO system_info
;
193 GetSystemInfo(&system_info
);
195 fprintf(stderr
, "browser says nprocessors = %lu\n",
196 system_info
.dwNumberOfProcessors
);
199 _snwprintf_s(string_rep
, sizeof string_rep
/ sizeof string_rep
[0], _TRUNCATE
,
200 L
"%u", system_info
.dwNumberOfProcessors
);
206 static void PathTelemetry(base::FilePath::StringType
const &path
) {
208 fwprintf(stderr
, L
"path = %s\n", path
.c_str());
210 fprintf(stderr
, "path = %s\n", path
.c_str());
215 static void PathTelemetry(base::FilePath::StringType
const &path
) {
220 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_SysconfNprocessorsOnln
, {
221 base::FilePath::StringType path
=
222 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
223 path
= path
+ NumberOfCoresAsFilePathString();
225 RunNaClIntegrationTest(path
);
228 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginCORS
) {
229 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
232 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginFail
) {
233 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
236 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, SameOriginCookie
) {
237 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
240 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CORSNoCookie
) {
241 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
244 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, RelativeManifest
) {
245 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
248 // Test with the NaCl debug flag turned on.
249 class NaClBrowserTestPnaclDebug
: public NaClBrowserTestPnacl
{
251 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
252 NaClBrowserTestPnacl::SetUpCommandLine(command_line
);
253 // Turn on debugging to influence the PNaCl URL loaded
254 command_line
->AppendSwitch(switches::kEnableNaClDebug
);
255 // On windows, the debug stub requires --no-sandbox:
258 command_line
->AppendSwitch(switches::kNoSandbox
);
262 // On some platforms this test does not work.
263 bool TestIsBroken() {
264 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
265 // is used, the required 1GB sandbox address space is not reserved.
266 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
268 if (base::win::OSInfo::GetInstance()->wow64_status() ==
269 base::win::OSInfo::WOW64_DISABLED
&&
270 base::win::OSInfo::GetInstance()->architecture() ==
271 base::win::OSInfo::X86_ARCHITECTURE
) {
278 void StartTestScript(base::Process
* test_process
,
279 int debug_stub_port
) {
280 // We call a python script that speaks to the debug stub, and
281 // lets the app continue, so that the load progress event completes.
282 base::CommandLine
cmd(base::FilePath(FILE_PATH_LITERAL("python")));
283 base::FilePath script
;
284 PathService::Get(chrome::DIR_TEST_DATA
, &script
);
285 script
= script
.AppendASCII("nacl/debug_stub_browser_tests.py");
286 cmd
.AppendArgPath(script
);
287 cmd
.AppendArg(base::IntToString(debug_stub_port
));
288 cmd
.AppendArg("continue");
289 LOG(INFO
) << cmd
.GetCommandLineString();
290 *test_process
= base::LaunchProcess(cmd
, base::LaunchOptions());
293 void RunWithTestDebugger(const base::FilePath::StringType
& test_url
) {
294 base::Process test_script
;
295 scoped_ptr
<base::Environment
> env(base::Environment::Create());
296 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
297 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript
,
298 base::Unretained(this), &test_script
));
299 // Turn on debug stub logging.
300 env
->SetVar("NACLVERBOSITY", "1");
301 RunLoadTest(test_url
);
302 env
->UnSetVar("NACLVERBOSITY");
303 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
305 LOG(INFO
) << "Waiting for script to exit (which waits for embed to die).";
306 test_script
.WaitForExit(&exit_code
);
307 EXPECT_EQ(0, exit_code
);
311 // Test with the NaCl debug flag turned on, but mask off every URL
312 // so that nothing is actually debugged.
313 class NaClBrowserTestPnaclDebugMasked
: public NaClBrowserTestPnaclDebug
{
315 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
316 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line
);
317 command_line
->AppendSwitchASCII(switches::kNaClDebugMask
,
322 // The tests which actually start a debug session must use the debug stub
323 // to continue the app startup. However, NaCl on windows can't open the
324 // debug stub socket in the browser process as needed by the test.
325 // See http://crbug.com/157312.
327 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
328 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
330 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
331 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
333 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
334 MAYBE_PnaclDebugURLFlagAndURL
) {
335 RunWithTestDebugger(FILE_PATH_LITERAL(
336 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
339 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
340 MAYBE_PnaclDebugURLFlagNoURL
) {
341 RunWithTestDebugger(FILE_PATH_LITERAL(
342 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
345 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
346 MAYBE_PNACL(PnaclDebugURLFlagOff
)) {
347 RunLoadTest(FILE_PATH_LITERAL(
348 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
351 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked
,
352 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff
)) {
353 if (TestIsBroken()) {
356 // If the mask excludes debugging, it's as if the flag was off.
357 RunLoadTest(FILE_PATH_LITERAL(
358 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
361 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
362 MAYBE_PNACL(PnaclErrorHandling
)) {
363 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
366 // NaClBrowserTestPnaclSubzero.PnaclErrorHandling is flaky on Win XP.
367 // http://crbug.com/499878
369 #define MAYBE_PnaclErrorHandling DISABLED_PnaclErrorHandling
371 #define MAYBE_PnaclErrorHandling PnaclErrorHandling
374 // Test Subzero. Subzero is triggered by the O0 option so reuse
375 // test harnesses that use "optlevel": 0.
376 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclSubzero
,
377 MAYBE_PnaclErrorHandling
) {
378 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
381 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
382 MAYBE_PNACL(PnaclNMFOptionsO0
)) {
383 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
386 // Test Subzero. Subzero is triggered by the O0 option so reuse
387 // test harnesses that use "optlevel": 0.
388 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclSubzero
,
389 MAYBE_PNACL(PnaclNMFOptionsO0
)) {
390 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
393 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
394 MAYBE_PNACL(PnaclNMFOptionsO2
)) {
395 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
398 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
399 MAYBE_PNACL(PnaclNMFOptionsOlarge
)) {
400 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
403 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
404 MAYBE_PNACL(PnaclDyncodeSyscallDisabled
)) {
405 RunNaClIntegrationTest(FILE_PATH_LITERAL(
406 "pnacl_dyncode_syscall_disabled.html"));
409 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
410 MAYBE_PNACL(PnaclExceptionHandlingDisabled
)) {
411 RunNaClIntegrationTest(FILE_PATH_LITERAL(
412 "pnacl_hw_eh_disabled.html"));
415 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
, PnaclMimeType
) {
416 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
419 // TODO(ncbray) support glibc and PNaCl
420 // flaky: crbug.com/375894
421 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension
, DISABLED_MimeHandler
) {
422 RunNaClIntegrationTest(FILE_PATH_LITERAL(
423 "ppapi_extension_mime_handler.html"));