Use chromeos accelerometer reader in athena and support only lid accelerometer.
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest.cc
blob58014e24100862bf6adf02f5ceb94f1a9feabf9b
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 #else
111 # define MAYBE_Crash Crash
112 #endif
113 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_Crash, {
114 RunNaClIntegrationTest(FILE_PATH_LITERAL("ppapi_crash.html"));
117 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtManifestFile) {
118 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
120 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
121 MAYBE_PNACL_NONSFI(IrtManifestFile)) {
122 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_manifest_file_test.html"));
125 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlib, IrtException) {
126 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
128 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
129 MAYBE_PNACL_NONSFI(IrtException)) {
130 RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
133 // Some versions of Visual Studio does not like preprocessor
134 // conditionals inside the argument of a macro, so we put the
135 // conditionals on a helper function. We are already in an anonymous
136 // namespace, so the name of the helper is not visible in external
137 // scope.
138 #if defined(OS_POSIX)
139 base::FilePath::StringType NumberOfCoresAsFilePathString() {
140 char string_rep[23];
141 long nprocessors = sysconf(_SC_NPROCESSORS_ONLN);
142 #if TELEMETRY
143 fprintf(stderr, "browser says nprocessors = %ld\n", nprocessors);
144 fflush(NULL);
145 #endif
146 snprintf(string_rep, sizeof string_rep, "%ld", nprocessors);
147 return string_rep;
149 #elif defined(OS_WIN)
150 base::FilePath::StringType NumberOfCoresAsFilePathString() {
151 wchar_t string_rep[23];
152 SYSTEM_INFO system_info;
153 GetSystemInfo(&system_info);
154 #if TELEMETRY
155 fprintf(stderr, "browser says nprocessors = %lu\n",
156 system_info.dwNumberOfProcessors);
157 fflush(NULL);
158 #endif
159 _snwprintf_s(string_rep, sizeof string_rep / sizeof string_rep[0], _TRUNCATE,
160 L"%u", system_info.dwNumberOfProcessors);
161 return string_rep;
163 #endif
165 #if TELEMETRY
166 static void PathTelemetry(base::FilePath::StringType const &path) {
167 # if defined(OS_WIN)
168 fwprintf(stderr, L"path = %s\n", path.c_str());
169 # else
170 fprintf(stderr, "path = %s\n", path.c_str());
171 # endif
172 fflush(NULL);
174 #else
175 static void PathTelemetry(base::FilePath::StringType const &path) {
176 (void) path;
178 #endif
180 NACL_BROWSER_TEST_F(NaClBrowserTest, MAYBE_SysconfNprocessorsOnln, {
181 base::FilePath::StringType path =
182 FILE_PATH_LITERAL("sysconf_nprocessors_onln_test.html?cpu_count=");
183 path = path + NumberOfCoresAsFilePathString();
184 PathTelemetry(path);
185 RunNaClIntegrationTest(path);
188 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginCORS) {
189 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors.html"));
192 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CrossOriginFail) {
193 RunLoadTest(FILE_PATH_LITERAL("cross_origin/fail.html"));
196 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, SameOriginCookie) {
197 RunLoadTest(FILE_PATH_LITERAL("cross_origin/same_origin_cookie.html"));
200 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, CORSNoCookie) {
201 RunLoadTest(FILE_PATH_LITERAL("cross_origin/cors_no_cookie.html"));
204 IN_PROC_BROWSER_TEST_F(NaClBrowserTestStatic, RelativeManifest) {
205 RunLoadTest(FILE_PATH_LITERAL("manifest/relative_manifest.html"));
208 // Test with the NaCl debug flag turned on.
209 class NaClBrowserTestPnaclDebug : public NaClBrowserTestPnacl {
210 public:
211 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
212 NaClBrowserTestPnacl::SetUpCommandLine(command_line);
213 // Turn on debugging to influence the PNaCl URL loaded
214 command_line->AppendSwitch(switches::kEnableNaClDebug);
215 // On windows, the debug stub requires --no-sandbox:
216 // crbug.com/265624
217 #if defined(OS_WIN)
218 command_line->AppendSwitch(switches::kNoSandbox);
219 #endif
222 // On some platforms this test does not work.
223 bool TestIsBroken() {
224 // TODO(jvoung): Make this test work on Windows 32-bit. When --no-sandbox
225 // is used, the required 1GB sandbox address space is not reserved.
226 // (see note in chrome/browser/nacl_host/test/nacl_gdb_browsertest.cc)
227 #if defined(OS_WIN)
228 if (base::win::OSInfo::GetInstance()->wow64_status() ==
229 base::win::OSInfo::WOW64_DISABLED &&
230 base::win::OSInfo::GetInstance()->architecture() ==
231 base::win::OSInfo::X86_ARCHITECTURE) {
232 return true;
234 #endif
235 return false;
238 void StartTestScript(base::ProcessHandle* test_process,
239 int debug_stub_port) {
240 // We call a python script that speaks to the debug stub, and
241 // lets the app continue, so that the load progress event completes.
242 CommandLine cmd(base::FilePath(FILE_PATH_LITERAL("python")));
243 base::FilePath script;
244 PathService::Get(chrome::DIR_TEST_DATA, &script);
245 script = script.AppendASCII("nacl/debug_stub_browser_tests.py");
246 cmd.AppendArgPath(script);
247 cmd.AppendArg(base::IntToString(debug_stub_port));
248 cmd.AppendArg("continue");
249 LOG(INFO) << cmd.GetCommandLineString();
250 base::LaunchProcess(cmd, base::LaunchOptions(), test_process);
253 void RunWithTestDebugger(const base::FilePath::StringType& test_url) {
254 base::ProcessHandle test_script;
255 scoped_ptr<base::Environment> env(base::Environment::Create());
256 nacl::NaClBrowser::GetInstance()->SetGdbDebugStubPortListener(
257 base::Bind(&NaClBrowserTestPnaclDebug::StartTestScript,
258 base::Unretained(this), &test_script));
259 // Turn on debug stub logging.
260 env->SetVar("NACLVERBOSITY", "1");
261 RunLoadTest(test_url);
262 env->UnSetVar("NACLVERBOSITY");
263 nacl::NaClBrowser::GetInstance()->ClearGdbDebugStubPortListener();
264 int exit_code;
265 LOG(INFO) << "Waiting for script to exit (which waits for embed to die).";
266 base::WaitForExitCode(test_script, &exit_code);
267 EXPECT_EQ(0, exit_code);
271 // Test with the NaCl debug flag turned on, but mask off every URL
272 // so that nothing is actually debugged.
273 class NaClBrowserTestPnaclDebugMasked : public NaClBrowserTestPnaclDebug {
274 public:
275 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
276 NaClBrowserTestPnaclDebug::SetUpCommandLine(command_line);
277 command_line->AppendSwitchASCII(switches::kNaClDebugMask,
278 "!<all_urls>");
282 // The tests which actually start a debug session must use the debug stub
283 // to continue the app startup. However, NaCl on windows can't open the
284 // debug stub socket in the browser process as needed by the test.
285 // See http://crbug.com/157312.
286 #if defined(OS_WIN)
287 #define MAYBE_PnaclDebugURLFlagAndURL DISABLED_PnaclDebugURLFlagAndURL
288 #define MAYBE_PnaclDebugURLFlagNoURL DISABLED_PnaclDebugURLFlagNoURL
289 #else
290 #define MAYBE_PnaclDebugURLFlagAndURL PnaclDebugURLFlagAndURL
291 #define MAYBE_PnaclDebugURLFlagNoURL PnaclDebugURLFlagNoURL
292 #endif
293 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
294 MAYBE_PnaclDebugURLFlagAndURL) {
295 RunWithTestDebugger(FILE_PATH_LITERAL(
296 "pnacl_debug_url.html?nmf_file=pnacl_has_debug.nmf"));
299 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebug,
300 MAYBE_PnaclDebugURLFlagNoURL) {
301 RunWithTestDebugger(FILE_PATH_LITERAL(
302 "pnacl_debug_url.html?nmf_file=pnacl_no_debug.nmf"));
305 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
306 MAYBE_PNACL(PnaclDebugURLFlagOff)) {
307 RunLoadTest(FILE_PATH_LITERAL(
308 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
311 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclDebugMasked,
312 MAYBE_PNACL(PnaclDebugURLFlagMaskedOff)) {
313 if (TestIsBroken()) {
314 return;
316 // If the mask excludes debugging, it's as if the flag was off.
317 RunLoadTest(FILE_PATH_LITERAL(
318 "pnacl_debug_url.html?nmf_file=pnacl_has_debug_flag_off.nmf"));
321 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
322 MAYBE_PNACL(PnaclErrorHandling)) {
323 RunNaClIntegrationTest(FILE_PATH_LITERAL("pnacl_error_handling.html"));
326 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
327 MAYBE_PNACL(PnaclNMFOptionsO0)) {
328 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
331 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
332 MAYBE_PNACL(PnaclNMFOptionsO2)) {
333 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_2"));
336 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
337 MAYBE_PNACL(PnaclNMFOptionsOlarge)) {
338 RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_large"));
341 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
342 MAYBE_PNACL(PnaclDyncodeSyscallDisabled)) {
343 RunNaClIntegrationTest(FILE_PATH_LITERAL(
344 "pnacl_dyncode_syscall_disabled.html"));
347 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
348 MAYBE_PNACL(PnaclExceptionHandlingDisabled)) {
349 RunNaClIntegrationTest(FILE_PATH_LITERAL(
350 "pnacl_hw_eh_disabled.html"));
353 IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, PnaclMimeType) {
354 RunLoadTest(FILE_PATH_LITERAL("pnacl_mime_type.html"));
357 // TODO(ncbray) support glibc and PNaCl
358 // flaky: crbug.com/375894
359 IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibExtension, DISABLED_MimeHandler) {
360 RunNaClIntegrationTest(FILE_PATH_LITERAL(
361 "ppapi_extension_mime_handler.html"));
364 } // namespace