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.
4
5 #include <stdio.h>
6 #if defined(OS_POSIX)
7 #include <unistd.h>
8 #elif defined(OS_WIN)
9 #include <windows.h>
10 #endif
11
12 #define TELEMETRY 1
13
14 #include "base/environment.h"
15 #include "chrome/test/nacl/nacl_browsertest_util.h"
16
17 namespace {
18
19 #if defined(OS_WIN)
20 // crbug.com/98721
21 # define MAYBE_Crash DISABLED_Crash
22 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
23 #else
24 # define MAYBE_Crash Crash
25 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
26 #endif
27
28 NACL_BROWSER_TEST_F(NaClBrowserTest, SimpleLoad, {
29 RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
30 })
31
32 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus0, {
33 RunNaClIntegrationTest(FILE_PATH_LITERAL(
34 "pm_exit_status_test.html?trigger=exit0&expected_exit=0"));
35 })
36
37 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatus254, {
38 RunNaClIntegrationTest(FILE_PATH_LITERAL(
39 "pm_exit_status_test.html?trigger=exit254&expected_exit=254"));
40 })
41
42 NACL_BROWSER_TEST_F(NaClBrowserTest, ExitStatusNeg2, {
43 RunNaClIntegrationTest(FILE_PATH_LITERAL(
44 "pm_exit_status_test.html?trigger=exitneg2&expected_exit=254"));
45 })
46
47 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPICore, {
48 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_core.html"));
49 })
50
51 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPBInstance, {
52 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppb_instance.html"));
53 })
54
55 NACL_BROWSER_TEST_F(NaClBrowserTest, PPAPIPPPInstance, {
56 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_ppp_instance.html"));
57 })
58
59 NACL_BROWSER_TEST_F(NaClBrowserTest, ProgressEvents, {
60 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_progress_events.html"));
61 })
62
63 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
64 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
65 })
66
67 // Some versions of Visual Studio does not like preprocessor
68 // conditionals inside the argument of a macro, so we put the
69 // conditionals on a helper function. We are already in an anonymous
70 // namespace, so the name of the helper is not visible in external
71 // scope.
72 #if defined(OS_POSIX)
NumberOfCoresAsFilePathString()73 base::FilePath::StringType NumberOfCoresAsFilePathString() {
74 char string_rep[23];
75 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
76 #if TELEMETRY
77 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
78 fflush(NULL);
79 #endif
80 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
81 return string_rep;
82 }
83 #elif defined(OS_WIN)
84 base::FilePath::StringType NumberOfCoresAsFilePathString() {
85 wchar_t string_rep[23];
86 SYSTEM_INFO system_info;
87 GetSystemInfo(&system_info);
88 #if TELEMETRY
89 fprintf(stderr, "browser says nprocessors = %d\n",
90 system_info.dwNumberOfProcessors);
91 fflush(NULL);
92 #endif
93 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
94 L"%u", system_info.dwNumberOfProcessors);
95 return string_rep;
96 }
97 #endif
98
99 #if TELEMETRY
PathTelemetry(base::FilePath::StringType const & path)100 static void PathTelemetry(base::FilePath::StringType const &path) {
101 # if defined(OS_WIN)
102 fwprintf(stderr, L"path = %s\n", path.c_str());
103 # else
104 fprintf(stderr, "path = %s\n", path.c_str());
105 # endif
106 fflush(NULL);
107 }
108 #else
PathTelemetry(base::FilePath::StringType const & path)109 static void PathTelemetry(base::FilePath::StringType const &path) {
110 (void) path;
111 }
112 #endif
113
114 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
115 base::FilePath::StringType path =
116 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
117 path = path + NumberOfCoresAsFilePathString();
118 PathTelemetry(path);
119 RunNaClIntegrationTest(path);
120 })
121
IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic,CrossOriginCORS)122 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
123 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
124 }
125
IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic,CrossOriginFail)126 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
127 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
128 }
129
IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic,SameOriginCookie)130 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
131 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
132 }
133
IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic,CORSNoCookie)134 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
135 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
136 }
137
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclErrorHandling))138 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
139 MAYBE_PNACL(PnaclErrorHandling)) {
140 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
141 }
142
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclNMFOptionsO0))143 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
144 MAYBE_PNACL(PnaclNMFOptionsO0)) {
145 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
146 }
147
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclNMFOptionsO2))148 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
149 MAYBE_PNACL(PnaclNMFOptionsO2)) {
150 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
151 }
152
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclNMFOptionsOlarge))153 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
154 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
155 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
156 }
157
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclDyncodeSyscallDisabled))158 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
159 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
160 RunNaClIntegrationTest(FILE_PATH_LITERAL(
161 "pnacl_dyncode_syscall_disabled.html"));
162 }
163
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,MAYBE_PNACL (PnaclExceptionHandlingDisabled))164 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
165 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
166 RunNaClIntegrationTest(FILE_PATH_LITERAL(
167 "pnacl_exception_handling_disabled.html"));
168 }
169
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,PnaclMimeType)170 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
171 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
172 }
173
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDisabled,PnaclMimeType)174 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDisabled, PnaclMimeType) {
175 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
176 }
177
178 class NaClBrowserTestNewlibStdoutPM : public NaClBrowserTestNewlib {
179 public:
SetUpInProcessBrowserTestFixture()180 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
181 // Env needs to be set early because nacl_helper is spawned before the test
182 // body on Linux.
183 scoped_ptr<base::Environment> env(base::Environment::Create());
184 env->SetVar("NACL_EXE_STDOUT", "DEBUG_ONLY:dev://postmessage");
185 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
186 }
187 };
188
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM,RedirectFg0)189 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg0) {
190 RunNaClIntegrationTest(FILE_PATH_LITERAL(
191 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=0"));
192 }
193
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM,RedirectBg0)194 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg0) {
195 RunNaClIntegrationTest(FILE_PATH_LITERAL(
196 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=0"));
197 }
198
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM,RedirectFg1)199 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectFg1) {
200 RunNaClIntegrationTest(FILE_PATH_LITERAL(
201 "pm_redir_test.html?stream=stdout&thread=fg&delay_us=1000000"));
202 }
203
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM,RedirectBg1)204 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStdoutPM, RedirectBg1) {
205 RunNaClIntegrationTest(FILE_PATH_LITERAL(
206 "pm_redir_test.html?stream=stdout&thread=bg&delay_us=1000000"));
207 }
208
209 class NaClBrowserTestNewlibStderrPM : public NaClBrowserTestNewlib {
210 public:
SetUpInProcessBrowserTestFixture()211 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
212 // Env needs to be set early because nacl_helper is spawned before the test
213 // body on Linux.
214 scoped_ptr<base::Environment> env(base::Environment::Create());
215 env->SetVar("NACL_EXE_STDERR", "DEBUG_ONLY:dev://postmessage");
216 NaClBrowserTestNewlib::SetUpInProcessBrowserTestFixture();
217 }
218 };
219
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM,RedirectFg0)220 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg0) {
221 RunNaClIntegrationTest(FILE_PATH_LITERAL(
222 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=0"));
223 }
224
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM,RedirectBg0)225 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg0) {
226 RunNaClIntegrationTest(FILE_PATH_LITERAL(
227 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=0"));
228 }
229
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM,RedirectFg1)230 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectFg1) {
231 RunNaClIntegrationTest(FILE_PATH_LITERAL(
232 "pm_redir_test.html?stream=stderr&thread=fg&delay_us=1000000"));
233 }
234
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM,RedirectBg1)235 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibStderrPM, RedirectBg1) {
236 RunNaClIntegrationTest(FILE_PATH_LITERAL(
237 "pm_redir_test.html?stream=stderr&thread=bg&delay_us=1000000"));
238 }
239
240 } // namespace
241