Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest.cc
blobb8e4af890c7c4cec810b377bf06f5f0b4e17a188
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 "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"
28 namespace {
30 #if defined(OS_WIN)
31 // crbug.com/98721
32 # define MAYBE_SysconfNprocessorsOnln DISABLED_SysconfNprocessorsOnln
33 #else
34 # define MAYBE_SysconfNprocessorsOnln SysconfNprocessorsOnln
35 #endif
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
66 #else
67 #define Maybe_PPAPICore PPAPICore
68 #endif
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
89 // causing timeouts.
90 // crbug/338444
91 #if defined(OS_WIN)
92 #define MAYBE_Bad DISABLED_Bad
93 #else
94 #define MAYBE_Bad Bad
95 #endif
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"));
105 #endif
107 #if defined(OS_WIN)
108 // crbug.com/98721
109 # define MAYBE_Crash DISABLED_Crash
110 #elif defined(OS_MACOSX)
111 // crbug.com/425570
112 # define MAYBE_Crash DISABLED_Crash
113 #elif defined(OS_LINUX)
114 // crbug.com/428838
115 # define MAYBE_Crash DISABLED_Crash
116 #else
117 # define MAYBE_Crash Crash
118 #endif
119 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
120 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
123 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtManifestFile) {
124 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
126 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
127 MAYBE_PNACL_NONSFI(IrtManifestFile)) {
128 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
131 #if defined(OS_WIN)
132 // http://crbug.com/416272
133 #define MAYBE_IrtException DISABLED_IrtException
134 #else
135 #define MAYBE_IrtException IrtException
136 #endif
137 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, MAYBE_IrtException) {
138 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
140 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
141 MAYBE_PNACL_NONSFI(IrtException)) {
142 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
145 // Some versions of Visual Studio does not like preprocessor
146 // conditionals inside the argument of a macro, so we put the
147 // conditionals on a helper function. We are already in an anonymous
148 // namespace, so the name of the helper is not visible in external
149 // scope.
150 #if defined(OS_POSIX)
151 base::FilePath::StringType NumberOfCoresAsFilePathString() {
152 char string_rep[23];
153 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
154 #if TELEMETRY
155 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
156 fflush(NULL);
157 #endif
158 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
159 return string_rep;
161 #elif defined(OS_WIN)
162 base::FilePath::StringType NumberOfCoresAsFilePathString() {
163 wchar_t string_rep[23];
164 SYSTEM_INFO system_info;
165 GetSystemInfo(&system_info);
166 #if TELEMETRY
167 fprintf(stderr, "browser says nprocessors = %lu\n",
168 system_info.dwNumberOfProcessors);
169 fflush(NULL);
170 #endif
171 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
172 L"%u", system_info.dwNumberOfProcessors);
173 return string_rep;
175 #endif
177 #if TELEMETRY
178 static void PathTelemetry(base::FilePath::StringType const &path) {
179 # if defined(OS_WIN)
180 fwprintf(stderr, L"path = %s\n", path.c_str());
181 # else
182 fprintf(stderr, "path = %s\n", path.c_str());
183 # endif
184 fflush(NULL);
186 #else
187 static void PathTelemetry(base::FilePath::StringType const &path) {
188 (void) path;
190 #endif
192 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
193 base::FilePath::StringType path =
194 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
195 path = path + NumberOfCoresAsFilePathString();
196 PathTelemetry(path);
197 RunNaClIntegrationTest(path);
200 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
201 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
204 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
205 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
208 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
209 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
212 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
213 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
216 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, RelativeManifest) {
217 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
220 // Test with the NaCl debug flag turned on.
221 class NaClBrowserTestPnaclDebug : public NaClBrowserTestPnacl {
222 public:
223 void SetUpCommandLine(CommandLine* command_line) override {
224 NaClBrowserTestPnacl::SetUpCommandLine(command_line);
225 // Turn on debugging to influence the PNaCl URL loaded
226 command_line->AppendSwitch(switches::kEnableNaClDebug);
227 // On windows, the debug stub requires --no-sandbox:
228 // crbug.com/265624
229 #if defined(OS_WIN)
230 command_line->AppendSwitch(switches::kNoSandbox);
231 #endif
234 // On some platforms this test does not work.
235 bool TestIsBroken() {
236 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
237 // is used, the required 1GB sandbox address space is not reserved.
238 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
239 #if defined(OS_WIN)
240 if (base::win::OSInfo::GetInstance()->wow64_status() ==
241 base::win::OSInfo::WOW64_DISABLED &&
242 base::win::OSInfo::GetInstance()->architecture() ==
243 base::win::OSInfo::X86_ARCHITECTURE) {
244 return true;
246 #endif
247 return false;
250 void StartTestScript(base::ProcessHandle* test_process,
251 int debug_stub_port) {
252 // We call a python script that speaks to the debug stub, and
253 // lets the app continue, so that the load progress event completes.
254 CommandLine cmd(base::FilePath(FILE_PATH_LITERAL("python")));
255 base::FilePath script;
256 PathService::Get(chrome::DIR_TEST_DATA, &script);
257 script = script.AppendASCII("nacl/debug_stub_browser_tests.py");
258 cmd.AppendArgPath(script);
259 cmd.AppendArg(base::IntToString(debug_stub_port));
260 cmd.AppendArg("continue");
261 LOG(INFO) << cmd.GetCommandLineString();
262 base::LaunchProcess(cmd, base::LaunchOptions(), test_process);
265 void RunWithTestDebugger(const base::FilePath::StringType& test_url) {
266 base::ProcessHandle test_script;
267 scoped_ptr<base::Environment> env(base::Environment::Create());
268 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
269 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript,
270 base::Unretained(this), &test_script));
271 // Turn on debug stub logging.
272 env->SetVar("NACLVERBOSITY", "1");
273 RunLoadTest(test_url);
274 env->UnSetVar("NACLVERBOSITY");
275 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
276 int exit_code;
277 LOG(INFO) << "Waiting for script to exit (which waits for embed to die).";
278 base::WaitForExitCode(test_script, &exit_code);
279 EXPECT_EQ(0, exit_code);
283 // Test with the NaCl debug flag turned on, but mask off every URL
284 // so that nothing is actually debugged.
285 class NaClBrowserTestPnaclDebugMasked : public NaClBrowserTestPnaclDebug {
286 public:
287 void SetUpCommandLine(CommandLine* command_line) override {
288 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line);
289 command_line->AppendSwitchASCII(switches::kNaClDebugMask,
290 "!<all_urls>");
294 // The tests which actually start a debug session must use the debug stub
295 // to continue the app startup. However, NaCl on windows can't open the
296 // debug stub socket in the browser process as needed by the test.
297 // See http://crbug.com/157312.
298 #if defined(OS_WIN)
299 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
300 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
301 #else
302 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
303 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
304 #endif
305 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
306 MAYBE_PnaclDebugURLFlagAndURL) {
307 RunWithTestDebugger(FILE_PATH_LITERAL(
308 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
311 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
312 MAYBE_PnaclDebugURLFlagNoURL) {
313 RunWithTestDebugger(FILE_PATH_LITERAL(
314 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
317 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
318 MAYBE_PNACL(PnaclDebugURLFlagOff)) {
319 RunLoadTest(FILE_PATH_LITERAL(
320 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
323 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked,
324 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff)) {
325 if (TestIsBroken()) {
326 return;
328 // If the mask excludes debugging, it's as if the flag was off.
329 RunLoadTest(FILE_PATH_LITERAL(
330 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
333 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
334 MAYBE_PNACL(PnaclErrorHandling)) {
335 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
338 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
339 MAYBE_PNACL(PnaclNMFOptionsO0)) {
340 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
343 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
344 MAYBE_PNACL(PnaclNMFOptionsO2)) {
345 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
348 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
349 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
350 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
353 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
354 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
355 RunNaClIntegrationTest(FILE_PATH_LITERAL(
356 "pnacl_dyncode_syscall_disabled.html"));
359 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
360 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
361 RunNaClIntegrationTest(FILE_PATH_LITERAL(
362 "pnacl_hw_eh_disabled.html"));
365 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
366 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
369 // TODO(ncbray) support glibc and PNaCl
370 // flaky: crbug.com/375894
371 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension, DISABLED_MimeHandler) {
372 RunNaClIntegrationTest(FILE_PATH_LITERAL(
373 "ppapi_extension_mime_handler.html"));
376 } // namespace