Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest.cc
blobe0f3ed01e1bdae8321642f7cf66d1d0e1446c261
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 "chrome/common/chrome_switches.h"
18 #include "chrome/test/nacl/nacl_browsertest_util.h"
20 namespace {
22 #if defined(OS_WIN)
23 // crbug.com/98721
24 # define MAYBE_Crash DISABLED_Crash
25 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
26 #else
27 # define MAYBE_Crash Crash
28 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
29 #endif
31 NACL_BROWSER_TEST_F(NaClBrowserTest, SimpleLoad, {
32 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
35 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus0, {
36 RunNaClIntegrationTest(FILE_PATH_LITERAL(
37 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
40 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus254, {
41 RunNaClIntegrationTest(FILE_PATH_LITERAL(
42 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
45 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatusNeg2, {
46 RunNaClIntegrationTest(FILE_PATH_LITERAL(
47 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
50 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPICore, {
51 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
54 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPBInstance, {
55 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
58 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPPInstance, {
59 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
62 NACL_BROWSER_TEST_F(NaClBrowserTest, ProgressEvents, {
63 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
66 // Note: currently not run on PNaCl because crash throttling causes the last few
67 // tests to fail for the wrong reasons. Enabling this test would also require
68 // creating a new set of manifests because shared NaCl/PNaCl manifests are not
69 // allowed. Also not run on GLibc because it's a large test that is at risk of
70 // causing timeouts.
71 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, Bad) {
72 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad.html"));
75 // partially_invalid.c does not have an ARM version of its asm.
76 #if !defined(__arm__)
77 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, BadNative) {
78 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_bad_native.html"));
80 #endif
82 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
83 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
86 // PNaCl version does not work.
87 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, ManifestFile) {
88 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
90 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, ManifestFile) {
91 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_manifest_file_test.html"));
93 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, PreInitManifestFile) {
94 RunNaClIntegrationTest(FILE_PATH_LITERAL(
95 "pm_pre_init_manifest_file_test.html"));
97 IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibc, PreInitManifestFile) {
98 RunNaClIntegrationTest(FILE_PATH_LITERAL(
99 "pm_pre_init_manifest_file_test.html"));
101 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtManifestFile) {
102 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
105 NACL_BROWSER_TEST_F(NaClBrowserTest, Nameservice, {
106 RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_nameservice_test.html"));
109 // Some versions of Visual Studio does not like preprocessor
110 // conditionals inside the argument of a macro, so we put the
111 // conditionals on a helper function. We are already in an anonymous
112 // namespace, so the name of the helper is not visible in external
113 // scope.
114 #if defined(OS_POSIX)
115 base::FilePath::StringType NumberOfCoresAsFilePathString() {
116 char string_rep[23];
117 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
118 #if TELEMETRY
119 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
120 fflush(NULL);
121 #endif
122 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
123 return string_rep;
125 #elif defined(OS_WIN)
126 base::FilePath::StringType NumberOfCoresAsFilePathString() {
127 wchar_t string_rep[23];
128 SYSTEM_INFO system_info;
129 GetSystemInfo(&system_info);
130 #if TELEMETRY
131 fprintf(stderr, "browser says nprocessors = %d\n",
132 system_info.dwNumberOfProcessors);
133 fflush(NULL);
134 #endif
135 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
136 L"%u", system_info.dwNumberOfProcessors);
137 return string_rep;
139 #endif
141 #if TELEMETRY
142 static void PathTelemetry(base::FilePath::StringType const &path) {
143 # if defined(OS_WIN)
144 fwprintf(stderr, L"path = %s\n", path.c_str());
145 # else
146 fprintf(stderr, "path = %s\n", path.c_str());
147 # endif
148 fflush(NULL);
150 #else
151 static void PathTelemetry(base::FilePath::StringType const &path) {
152 (void) path;
154 #endif
156 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
157 base::FilePath::StringType path =
158 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
159 path = path + NumberOfCoresAsFilePathString();
160 PathTelemetry(path);
161 RunNaClIntegrationTest(path);
164 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
165 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
168 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
169 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
172 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
173 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
176 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
177 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
180 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, RelativeManifest) {
181 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
184 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
185 MAYBE_PNACL(PnaclErrorHandling)) {
186 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
189 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
190 MAYBE_PNACL(PnaclNMFOptionsO0)) {
191 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
194 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
195 MAYBE_PNACL(PnaclNMFOptionsO2)) {
196 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
199 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
200 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
201 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
204 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
205 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
206 RunNaClIntegrationTest(FILE_PATH_LITERAL(
207 "pnacl_dyncode_syscall_disabled.html"));
210 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
211 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
212 RunNaClIntegrationTest(FILE_PATH_LITERAL(
213 "pnacl_exception_handling_disabled.html"));
216 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
217 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
220 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDisabled, PnaclMimeType) {
221 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
224 class NaClBrowserTestNewlibStdoutPM : public NaClBrowserTestNewlib {
225 public:
226 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
227 // Env needs to be set early because nacl_helper is spawned before the test
228 // body on Linux.
229 scoped_ptr<base::Environment> env(base::Environment::Create());
230 env->SetVar("NACL_EXE_STDOUT", "DEBUG_ONLY:dev://postmessage");
231 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
235 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg0) {
236 RunNaClIntegrationTest(FILE_PATH_LITERAL(
237 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=0"));
240 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg0) {
241 RunNaClIntegrationTest(FILE_PATH_LITERAL(
242 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=0"));
245 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg1) {
246 RunNaClIntegrationTest(FILE_PATH_LITERAL(
247 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=1000000"));
250 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg1) {
251 RunNaClIntegrationTest(FILE_PATH_LITERAL(
252 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=1000000"));
255 class NaClBrowserTestNewlibStderrPM : public NaClBrowserTestNewlib {
256 public:
257 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
258 // Env needs to be set early because nacl_helper is spawned before the test
259 // body on Linux.
260 scoped_ptr<base::Environment> env(base::Environment::Create());
261 env->SetVar("NACL_EXE_STDERR", "DEBUG_ONLY:dev://postmessage");
262 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
266 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg0) {
267 RunNaClIntegrationTest(FILE_PATH_LITERAL(
268 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=0"));
271 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg0) {
272 RunNaClIntegrationTest(FILE_PATH_LITERAL(
273 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=0"));
276 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg1) {
277 RunNaClIntegrationTest(FILE_PATH_LITERAL(
278 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=1000000"));
281 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg1) {
282 RunNaClIntegrationTest(FILE_PATH_LITERAL(
283 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=1000000"));
286 class NaClBrowserTestNewlibExtension : public NaClBrowserTestNewlib {
287 public:
288 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
289 NaClBrowserTestNewlib::SetUpCommandLine(command_line);
290 base::FilePath src_root;
291 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_root));
293 base::FilePath document_root;
294 ASSERT_TRUE(GetDocumentRoot(&document_root));
296 // Document root is relative to source root, and source root may not be CWD.
297 command_line->AppendSwitchPath(switches::kLoadExtension,
298 src_root.Append(document_root));
302 // TODO(ncbray) support glibc and PNaCl
303 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension, MimeHandler) {
304 RunNaClIntegrationTest(FILE_PATH_LITERAL(
305 "ppapi_extension_mime_handler.html"));
308 } // namespace