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/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"
32 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
34 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
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
67 #define Maybe_PPAPICore PPAPICore
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
92 #define MAYBE_Bad DISABLED_Bad
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"));
109 # define MAYBE_Crash DISABLED_Crash
110 #elif defined(OS_MACOSX)
112 # define MAYBE_Crash DISABLED_Crash
114 # define MAYBE_Crash Crash
116 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_Crash
, {
117 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
120 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, IrtManifestFile
) {
121 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
123 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
124 MAYBE_PNACL_NONSFI(IrtManifestFile
)) {
125 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
129 // http://crbug.com/416272
130 #define MAYBE_IrtException DISABLED_IrtException
132 #define MAYBE_IrtException IrtException
134 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_IrtException
) {
135 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
137 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi
,
138 MAYBE_PNACL_NONSFI(IrtException
)) {
139 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
142 // Some versions of Visual Studio does not like preprocessor
143 // conditionals inside the argument of a macro, so we put the
144 // conditionals on a helper function. We are already in an anonymous
145 // namespace, so the name of the helper is not visible in external
147 #if defined(OS_POSIX)
148 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
150 long nprocessors
= sysconf(_SC_NPROCESSORS_ONLN
);
152 fprintf(stderr
, "browser says nprocessors = %ld\n", nprocessors
);
155 snprintf(string_rep
, sizeof string_rep
, "%ld", nprocessors
);
158 #elif defined(OS_WIN)
159 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
160 wchar_t string_rep
[23];
161 SYSTEM_INFO system_info
;
162 GetSystemInfo(&system_info
);
164 fprintf(stderr
, "browser says nprocessors = %lu\n",
165 system_info
.dwNumberOfProcessors
);
168 _snwprintf_s(string_rep
, sizeof string_rep
/ sizeof string_rep
[0], _TRUNCATE
,
169 L
"%u", system_info
.dwNumberOfProcessors
);
175 static void PathTelemetry(base::FilePath::StringType
const &path
) {
177 fwprintf(stderr
, L
"path = %s\n", path
.c_str());
179 fprintf(stderr
, "path = %s\n", path
.c_str());
184 static void PathTelemetry(base::FilePath::StringType
const &path
) {
189 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_SysconfNprocessorsOnln
, {
190 base::FilePath::StringType path
=
191 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
192 path
= path
+ NumberOfCoresAsFilePathString();
194 RunNaClIntegrationTest(path
);
197 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginCORS
) {
198 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
201 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginFail
) {
202 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
205 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, SameOriginCookie
) {
206 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
209 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CORSNoCookie
) {
210 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
213 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, RelativeManifest
) {
214 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
217 // Test with the NaCl debug flag turned on.
218 class NaClBrowserTestPnaclDebug
: public NaClBrowserTestPnacl
{
220 void SetUpCommandLine(CommandLine
* command_line
) override
{
221 NaClBrowserTestPnacl::SetUpCommandLine(command_line
);
222 // Turn on debugging to influence the PNaCl URL loaded
223 command_line
->AppendSwitch(switches::kEnableNaClDebug
);
224 // On windows, the debug stub requires --no-sandbox:
227 command_line
->AppendSwitch(switches::kNoSandbox
);
231 // On some platforms this test does not work.
232 bool TestIsBroken() {
233 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
234 // is used, the required 1GB sandbox address space is not reserved.
235 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
237 if (base::win::OSInfo::GetInstance()->wow64_status() ==
238 base::win::OSInfo::WOW64_DISABLED
&&
239 base::win::OSInfo::GetInstance()->architecture() ==
240 base::win::OSInfo::X86_ARCHITECTURE
) {
247 void StartTestScript(base::ProcessHandle
* test_process
,
248 int debug_stub_port
) {
249 // We call a python script that speaks to the debug stub, and
250 // lets the app continue, so that the load progress event completes.
251 CommandLine
cmd(base::FilePath(FILE_PATH_LITERAL("python")));
252 base::FilePath script
;
253 PathService::Get(chrome::DIR_TEST_DATA
, &script
);
254 script
= script
.AppendASCII("nacl/debug_stub_browser_tests.py");
255 cmd
.AppendArgPath(script
);
256 cmd
.AppendArg(base::IntToString(debug_stub_port
));
257 cmd
.AppendArg("continue");
258 LOG(INFO
) << cmd
.GetCommandLineString();
259 base::LaunchProcess(cmd
, base::LaunchOptions(), test_process
);
262 void RunWithTestDebugger(const base::FilePath::StringType
& test_url
) {
263 base::ProcessHandle test_script
;
264 scoped_ptr
<base::Environment
> env(base::Environment::Create());
265 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
266 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript
,
267 base::Unretained(this), &test_script
));
268 // Turn on debug stub logging.
269 env
->SetVar("NACLVERBOSITY", "1");
270 RunLoadTest(test_url
);
271 env
->UnSetVar("NACLVERBOSITY");
272 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
274 LOG(INFO
) << "Waiting for script to exit (which waits for embed to die).";
275 base::WaitForExitCode(test_script
, &exit_code
);
276 EXPECT_EQ(0, exit_code
);
280 // Test with the NaCl debug flag turned on, but mask off every URL
281 // so that nothing is actually debugged.
282 class NaClBrowserTestPnaclDebugMasked
: public NaClBrowserTestPnaclDebug
{
284 void SetUpCommandLine(CommandLine
* command_line
) override
{
285 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line
);
286 command_line
->AppendSwitchASCII(switches::kNaClDebugMask
,
291 // The tests which actually start a debug session must use the debug stub
292 // to continue the app startup. However, NaCl on windows can't open the
293 // debug stub socket in the browser process as needed by the test.
294 // See http://crbug.com/157312.
296 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
297 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
299 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
300 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
302 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
303 MAYBE_PnaclDebugURLFlagAndURL
) {
304 RunWithTestDebugger(FILE_PATH_LITERAL(
305 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
308 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug
,
309 MAYBE_PnaclDebugURLFlagNoURL
) {
310 RunWithTestDebugger(FILE_PATH_LITERAL(
311 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
314 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
315 MAYBE_PNACL(PnaclDebugURLFlagOff
)) {
316 RunLoadTest(FILE_PATH_LITERAL(
317 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
320 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked
,
321 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff
)) {
322 if (TestIsBroken()) {
325 // If the mask excludes debugging, it's as if the flag was off.
326 RunLoadTest(FILE_PATH_LITERAL(
327 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
330 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
331 MAYBE_PNACL(PnaclErrorHandling
)) {
332 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
335 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
336 MAYBE_PNACL(PnaclNMFOptionsO0
)) {
337 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
340 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
341 MAYBE_PNACL(PnaclNMFOptionsO2
)) {
342 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
345 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
346 MAYBE_PNACL(PnaclNMFOptionsOlarge
)) {
347 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
350 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
351 MAYBE_PNACL(PnaclDyncodeSyscallDisabled
)) {
352 RunNaClIntegrationTest(FILE_PATH_LITERAL(
353 "pnacl_dyncode_syscall_disabled.html"));
356 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
357 MAYBE_PNACL(PnaclExceptionHandlingDisabled
)) {
358 RunNaClIntegrationTest(FILE_PATH_LITERAL(
359 "pnacl_hw_eh_disabled.html"));
362 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
, PnaclMimeType
) {
363 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
366 // TODO(ncbray) support glibc and PNaCl
367 // flaky: crbug.com/375894
368 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension
, DISABLED_MimeHandler
) {
369 RunNaClIntegrationTest(FILE_PATH_LITERAL(
370 "ppapi_extension_mime_handler.html"));