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(NaClBrowserTestTransitionalNonSfi
,
47 MAYBE_TRANSITIONAL_NONSFI(Messaging
)) {
48 RunLoadTest(FILE_PATH_LITERAL("libc_free.html"));
51 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode
, MAYBE_NONSFI(Irt
)) {
52 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_test.html"));
55 IN_PROC_BROWSER_TEST_F(NaClBrowserTestTransitionalNonSfi
,
56 MAYBE_TRANSITIONAL_NONSFI(Irt
)) {
57 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_test.html"));
60 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus0
, {
61 RunNaClIntegrationTest(FILE_PATH_LITERAL(
62 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
65 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus254
, {
66 RunNaClIntegrationTest(FILE_PATH_LITERAL(
67 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
70 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatusNeg2
, {
71 RunNaClIntegrationTest(FILE_PATH_LITERAL(
72 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
75 #if defined(ADDRESS_SANITIZER)
76 #define Maybe_PPAPICore DISABLED_PPAPICore
78 #define Maybe_PPAPICore PPAPICore
80 NACL_BROWSER_TEST_F(NaClBrowserTest
, Maybe_PPAPICore
, {
81 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
84 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPBInstance
, {
85 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
88 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPPInstance
, {
89 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
92 NACL_BROWSER_TEST_F(NaClBrowserTest
, ProgressEvents
, {
93 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
96 // Note: currently not run on PNaCl because crash throttling causes the last few
97 // tests to fail for the wrong reasons. Enabling this test would also require
98 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
99 // allowed. Also not run on GLibc because it's a large test that is at risk of
103 #define MAYBE_Bad DISABLED_Bad
105 #define MAYBE_Bad Bad
107 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_Bad
) {
108 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
111 // partially_invalid.c does not have an ARM version of its asm.
112 #if !defined(__arm__)
113 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, BadNative
) {
114 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
120 # define MAYBE_CrashViaCheckFailure DISABLED_CrashViaCheckFailure
121 # define MAYBE_CrashViaExitCall DISABLED_CrashViaExitCall
122 # define MAYBE_CrashInCallback DISABLED_CrashInCallback
123 # define MAYBE_CrashOffMainThread DISABLED_CrashOffMainThread
124 # define MAYBE_CrashPPAPIOffMainThread DISABLED_CrashPPAPIOffMainThread
125 #elif defined(OS_MACOSX)
127 # define MAYBE_CrashViaCheckFailure DISABLED_CrashViaCheckFailure
128 # define MAYBE_CrashViaExitCall DISABLED_CrashViaExitCall
129 # define MAYBE_CrashInCallback DISABLED_CrashInCallback
130 # define MAYBE_CrashOffMainThread DISABLED_CrashOffMainThread
131 # define MAYBE_CrashPPAPIOffMainThread DISABLED_CrashPPAPIOffMainThread
133 # define MAYBE_CrashViaCheckFailure CrashViaCheckFailure
134 # define MAYBE_CrashViaExitCall CrashViaExitCall
135 # define MAYBE_CrashInCallback CrashInCallback
136 # define MAYBE_CrashOffMainThread CrashOffMainThread
137 # define MAYBE_CrashPPAPIOffMainThread CrashPPAPIOffMainThread
139 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashViaCheckFailure
, {
140 RunNaClIntegrationTest(
141 FILE_PATH_LITERAL("ppapi_crash_via_check_failure.html"));
144 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashViaExitCall
, {
145 RunNaClIntegrationTest( FILE_PATH_LITERAL("ppapi_crash_via_exit_call.html"));
148 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashInCallback
, {
149 RunNaClIntegrationTest( FILE_PATH_LITERAL("ppapi_crash_in_callback.html"));
152 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashOffMainThread
, {
153 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash_off_main_thread.html"));
156 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_CrashPPAPIOffMainThread
, {
157 RunNaClIntegrationTest(
158 FILE_PATH_LITERAL("ppapi_crash_ppapi_off_main_thread.html"));
161 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, IrtManifestFile
) {
162 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
164 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
165 MAYBE_PNACL_NONSFI(IrtManifestFile
)) {
166 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
168 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclTransitionalNonSfi
,
169 MAYBE_PNACL_TRANSITIONAL_NONSFI(IrtManifestFile
)) {
170 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
174 // http://crbug.com/416272
175 #define MAYBE_IrtException DISABLED_IrtException
177 #define MAYBE_IrtException IrtException
179 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_IrtException
) {
180 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
182 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
183 MAYBE_PNACL_NONSFI(IrtException
)) {
184 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
186 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclTransitionalNonSfi
,
187 MAYBE_PNACL_TRANSITIONAL_NONSFI(IrtException
)) {
188 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
191 // Some versions of Visual Studio does not like preprocessor
192 // conditionals inside the argument of a macro, so we put the
193 // conditionals on a helper function. We are already in an anonymous
194 // namespace, so the name of the helper is not visible in external
196 #if defined(OS_POSIX)
197 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
199 long nprocessors
= sysconf(_SC_NPROCESSORS_ONLN
);
201 fprintf(stderr
, "browser says nprocessors = %ld\n", nprocessors
);
204 snprintf(string_rep
, sizeof string_rep
, "%ld", nprocessors
);
207 #elif defined(OS_WIN)
208 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
209 wchar_t string_rep
[23];
210 SYSTEM_INFO system_info
;
211 GetSystemInfo(&system_info
);
213 fprintf(stderr
, "browser says nprocessors = %lu\n",
214 system_info
.dwNumberOfProcessors
);
217 _snwprintf_s(string_rep
, sizeof string_rep
/ sizeof string_rep
[0], _TRUNCATE
,
218 L
"%u", system_info
.dwNumberOfProcessors
);
224 static void PathTelemetry(base::FilePath::StringType
const &path
) {
226 fwprintf(stderr
, L
"path = %s\n", path
.c_str());
228 fprintf(stderr
, "path = %s\n", path
.c_str());
233 static void PathTelemetry(base::FilePath::StringType
const &path
) {
238 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_SysconfNprocessorsOnln
, {
239 base::FilePath::StringType path
=
240 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
241 path
= path
+ NumberOfCoresAsFilePathString();
243 RunNaClIntegrationTest(path
);
246 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginCORS
) {
247 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
250 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginFail
) {
251 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
254 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, SameOriginCookie
) {
255 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
258 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CORSNoCookie
) {
259 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
262 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, RelativeManifest
) {
263 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
266 // Test with the NaCl debug flag turned on.
267 class NaClBrowserTestPnaclDebug
: public NaClBrowserTestPnacl
{
269 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
270 NaClBrowserTestPnacl::SetUpCommandLine(command_line
);
271 // Turn on debugging to influence the PNaCl URL loaded
272 command_line
->AppendSwitch(switches::kEnableNaClDebug
);
273 // On windows, the debug stub requires --no-sandbox:
276 command_line
->AppendSwitch(switches::kNoSandbox
);
280 // On some platforms this test does not work.
281 bool TestIsBroken() {
282 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
283 // is used, the required 1GB sandbox address space is not reserved.
284 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
286 if (base::win::OSInfo::GetInstance()->wow64_status() ==
287 base::win::OSInfo::WOW64_DISABLED
&&
288 base::win::OSInfo::GetInstance()->architecture() ==
289 base::win::OSInfo::X86_ARCHITECTURE
) {
296 void StartTestScript(base::Process
* test_process
,
297 int debug_stub_port
) {
298 // We call a python script that speaks to the debug stub, and
299 // lets the app continue, so that the load progress event completes.
300 base::CommandLine
cmd(base::FilePath(FILE_PATH_LITERAL("python")));
301 base::FilePath script
;
302 PathService::Get(chrome::DIR_TEST_DATA
, &script
);
303 script
= script
.AppendASCII("nacl/debug_stub_browser_tests.py");
304 cmd
.AppendArgPath(script
);
305 cmd
.AppendArg(base::IntToString(debug_stub_port
));
306 cmd
.AppendArg("continue");
307 LOG(INFO
) << cmd
.GetCommandLineString();
308 *test_process
= base::LaunchProcess(cmd
, base::LaunchOptions());
311 void RunWithTestDebugger(const base::FilePath::StringType
& test_url
) {
312 base::Process test_script
;
313 scoped_ptr
<base::Environment
> env(base::Environment::Create());
314 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
315 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript
,
316 base::Unretained(this), &test_script
));
317 // Turn on debug stub logging.
318 env
->SetVar("NACLVERBOSITY", "1");
319 RunLoadTest(test_url
);
320 env
->UnSetVar("NACLVERBOSITY");
321 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
323 LOG(INFO
) << "Waiting for script to exit (which waits for embed to die).";
324 test_script
.WaitForExit(&exit_code
);
325 EXPECT_EQ(0, exit_code
);
329 // Test with the NaCl debug flag turned on, but mask off every URL
330 // so that nothing is actually debugged.
331 class NaClBrowserTestPnaclDebugMasked
: public NaClBrowserTestPnaclDebug
{
333 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
334 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line
);
335 command_line
->AppendSwitchASCII(switches::kNaClDebugMask
,
340 // The tests which actually start a debug session must use the debug stub
341 // to continue the app startup. However, NaCl on windows can't open the
342 // debug stub socket in the browser process as needed by the test.
343 // See http://crbug.com/157312.
345 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
346 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
348 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
349 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
351 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
352 MAYBE_PnaclDebugURLFlagAndURL
) {
353 RunWithTestDebugger(FILE_PATH_LITERAL(
354 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
357 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
358 MAYBE_PnaclDebugURLFlagNoURL
) {
359 RunWithTestDebugger(FILE_PATH_LITERAL(
360 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
363 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
364 MAYBE_PNACL(PnaclDebugURLFlagOff
)) {
365 RunLoadTest(FILE_PATH_LITERAL(
366 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
369 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked
,
370 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff
)) {
371 if (TestIsBroken()) {
374 // If the mask excludes debugging, it's as if the flag was off.
375 RunLoadTest(FILE_PATH_LITERAL(
376 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
379 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
380 MAYBE_PNACL(PnaclErrorHandling
)) {
381 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
384 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
385 MAYBE_PNACL(PnaclNMFOptionsO0
)) {
386 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
389 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
390 MAYBE_PNACL(PnaclNMFOptionsO2
)) {
391 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
394 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
395 MAYBE_PNACL(PnaclNMFOptionsOlarge
)) {
396 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
399 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
400 MAYBE_PNACL(PnaclDyncodeSyscallDisabled
)) {
401 RunNaClIntegrationTest(FILE_PATH_LITERAL(
402 "pnacl_dyncode_syscall_disabled.html"));
405 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
406 MAYBE_PNACL(PnaclExceptionHandlingDisabled
)) {
407 RunNaClIntegrationTest(FILE_PATH_LITERAL(
408 "pnacl_hw_eh_disabled.html"));
411 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
, PnaclMimeType
) {
412 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
415 // TODO(ncbray) support glibc and PNaCl
416 // flaky: crbug.com/375894
417 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension
, DISABLED_MimeHandler
) {
418 RunNaClIntegrationTest(FILE_PATH_LITERAL(
419 "ppapi_extension_mime_handler.html"));