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 "chrome/common/chrome_switches.h"
18 #include "chrome/test/nacl/nacl_browsertest_util.h"
19 #include "components/nacl/common/nacl_switches.h"
20 #include "content/public/common/content_switches.h"
26 # define MAYBE_Crash DISABLED_Crash
27 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
29 # define MAYBE_Crash Crash
30 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
33 NACL_BROWSER_TEST_F(NaClBrowserTest
, SimpleLoad
, {
34 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
38 # define MAYBE_NonSfiLoad NonSfiLoad
40 # define MAYBE_NonSfiLoad DISABLED_NonSfiLoad
43 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNonSfiMode
, MAYBE_NonSfiLoad
) {
44 RunLoadTest(FILE_PATH_LITERAL("libc_free.html"));
47 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus0
, {
48 RunNaClIntegrationTest(FILE_PATH_LITERAL(
49 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
52 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatus254
, {
53 RunNaClIntegrationTest(FILE_PATH_LITERAL(
54 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
57 NACL_BROWSER_TEST_F(NaClBrowserTest
, ExitStatusNeg2
, {
58 RunNaClIntegrationTest(FILE_PATH_LITERAL(
59 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
62 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPICore
, {
63 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
66 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPBInstance
, {
67 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
70 NACL_BROWSER_TEST_F(NaClBrowserTest
, PPAPIPPPInstance
, {
71 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
74 NACL_BROWSER_TEST_F(NaClBrowserTest
, ProgressEvents
, {
75 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
78 // Note: currently not run on PNaCl because crash throttling causes the last few
79 // tests to fail for the wrong reasons. Enabling this test would also require
80 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
81 // allowed. Also not run on GLibc because it's a large test that is at risk of
85 #define MAYBE_Bad DISABLED_Bad
89 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, MAYBE_Bad
) {
90 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
93 // partially_invalid.c does not have an ARM version of its asm.
95 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, BadNative
) {
96 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
100 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_Crash
, {
101 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
104 // PNaCl version does not work.
105 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, ManifestFile
) {
106 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
108 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc
, ManifestFile
) {
109 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
111 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, PreInitManifestFile
) {
112 RunNaClIntegrationTest(FILE_PATH_LITERAL(
113 "pm_pre_init_manifest_file_test.html"));
115 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc
, PreInitManifestFile
) {
116 RunNaClIntegrationTest(FILE_PATH_LITERAL(
117 "pm_pre_init_manifest_file_test.html"));
119 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib
, IrtManifestFile
) {
120 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
123 NACL_BROWSER_TEST_F(NaClBrowserTest
, Nameservice
, {
124 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_nameservice_test.html"));
127 // Some versions of Visual Studio does not like preprocessor
128 // conditionals inside the argument of a macro, so we put the
129 // conditionals on a helper function. We are already in an anonymous
130 // namespace, so the name of the helper is not visible in external
132 #if defined(OS_POSIX)
133 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
135 long nprocessors
= sysconf(_SC_NPROCESSORS_ONLN
);
137 fprintf(stderr
, "browser says nprocessors = %ld\n", nprocessors
);
140 snprintf(string_rep
, sizeof string_rep
, "%ld", nprocessors
);
143 #elif defined(OS_WIN)
144 base::FilePath::StringType
NumberOfCoresAsFilePathString() {
145 wchar_t string_rep
[23];
146 SYSTEM_INFO system_info
;
147 GetSystemInfo(&system_info
);
149 fprintf(stderr
, "browser says nprocessors = %d\n",
150 system_info
.dwNumberOfProcessors
);
153 _snwprintf_s(string_rep
, sizeof string_rep
/ sizeof string_rep
[0], _TRUNCATE
,
154 L
"%u", system_info
.dwNumberOfProcessors
);
160 static void PathTelemetry(base::FilePath::StringType
const &path
) {
162 fwprintf(stderr
, L
"path = %s\n", path
.c_str());
164 fprintf(stderr
, "path = %s\n", path
.c_str());
169 static void PathTelemetry(base::FilePath::StringType
const &path
) {
174 NACL_BROWSER_TEST_F(NaClBrowserTest
, MAYBE_SysconfNprocessorsOnln
, {
175 base::FilePath::StringType path
=
176 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
177 path
= path
+ NumberOfCoresAsFilePathString();
179 RunNaClIntegrationTest(path
);
182 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginCORS
) {
183 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
186 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CrossOriginFail
) {
187 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
190 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, SameOriginCookie
) {
191 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
194 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, CORSNoCookie
) {
195 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
198 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic
, RelativeManifest
) {
199 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
202 class NaClBrowserTestPnaclDebugURL
: public NaClBrowserTestPnacl
{
204 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
205 NaClBrowserTestPnacl::SetUpCommandLine(command_line
);
206 // Turn on debugging to influence the PNaCl URL loaded
207 command_line
->AppendSwitch(switches::kEnableNaClDebug
);
208 // On windows, the debug stub requires --no-sandbox:
211 command_line
->AppendSwitch(switches::kNoSandbox
);
213 // Don't actually debug the app though.
214 command_line
->AppendSwitchASCII(switches::kNaClDebugMask
,
220 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
221 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
223 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
224 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
227 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugURL
,
228 MAYBE_PnaclDebugURLFlagAndURL
) {
229 RunLoadTest(FILE_PATH_LITERAL(
230 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
233 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugURL
,
234 MAYBE_PnaclDebugURLFlagNoURL
) {
235 RunLoadTest(FILE_PATH_LITERAL(
236 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
239 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
240 MAYBE_PNACL(PnaclDebugURLFlagOff
)) {
241 RunLoadTest(FILE_PATH_LITERAL(
242 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
245 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
246 MAYBE_PNACL(PnaclErrorHandling
)) {
247 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
250 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
251 MAYBE_PNACL(PnaclNMFOptionsO0
)) {
252 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
255 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
256 MAYBE_PNACL(PnaclNMFOptionsO2
)) {
257 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
260 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
261 MAYBE_PNACL(PnaclNMFOptionsOlarge
)) {
262 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
265 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
266 MAYBE_PNACL(PnaclDyncodeSyscallDisabled
)) {
267 RunNaClIntegrationTest(FILE_PATH_LITERAL(
268 "pnacl_dyncode_syscall_disabled.html"));
271 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
,
272 MAYBE_PNACL(PnaclExceptionHandlingDisabled
)) {
273 RunNaClIntegrationTest(FILE_PATH_LITERAL(
274 "pnacl_exception_handling_disabled.html"));
277 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl
, PnaclMimeType
) {
278 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
281 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDisabled
, PnaclMimeType
) {
282 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
285 class NaClBrowserTestNewlibStdoutPM
: public NaClBrowserTestNewlib
{
287 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
288 // Env needs to be set early because nacl_helper is spawned before the test
290 scoped_ptr
<base::Environment
> env(base::Environment::Create());
291 env
->SetVar("NACL_EXE_STDOUT", "DEBUG_ONLY:dev://postmessage");
292 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
296 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM
, RedirectFg0
) {
297 RunNaClIntegrationTest(FILE_PATH_LITERAL(
298 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=0"));
301 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM
, RedirectBg0
) {
302 RunNaClIntegrationTest(FILE_PATH_LITERAL(
303 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=0"));
306 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM
, RedirectFg1
) {
307 RunNaClIntegrationTest(FILE_PATH_LITERAL(
308 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=1000000"));
311 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM
, RedirectBg1
) {
312 RunNaClIntegrationTest(FILE_PATH_LITERAL(
313 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=1000000"));
316 class NaClBrowserTestNewlibStderrPM
: public NaClBrowserTestNewlib
{
318 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
319 // Env needs to be set early because nacl_helper is spawned before the test
321 scoped_ptr
<base::Environment
> env(base::Environment::Create());
322 env
->SetVar("NACL_EXE_STDERR", "DEBUG_ONLY:dev://postmessage");
323 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
327 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM
, RedirectFg0
) {
328 RunNaClIntegrationTest(FILE_PATH_LITERAL(
329 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=0"));
332 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM
, RedirectBg0
) {
333 RunNaClIntegrationTest(FILE_PATH_LITERAL(
334 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=0"));
337 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM
, RedirectFg1
) {
338 RunNaClIntegrationTest(FILE_PATH_LITERAL(
339 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=1000000"));
342 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM
, RedirectBg1
) {
343 RunNaClIntegrationTest(FILE_PATH_LITERAL(
344 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=1000000"));
347 class NaClBrowserTestNewlibExtension
: public NaClBrowserTestNewlib
{
349 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
350 NaClBrowserTestNewlib::SetUpCommandLine(command_line
);
351 base::FilePath src_root
;
352 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT
, &src_root
));
354 base::FilePath document_root
;
355 ASSERT_TRUE(GetDocumentRoot(&document_root
));
357 // Document root is relative to source root, and source root may not be CWD.
358 command_line
->AppendSwitchPath(switches::kLoadExtension
,
359 src_root
.Append(document_root
));
363 // TODO(ncbray) support glibc and PNaCl
364 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension
, MimeHandler
) {
365 RunNaClIntegrationTest(FILE_PATH_LITERAL(
366 "ppapi_extension_mime_handler.html"));