Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_android.cc
blobf19d721c993e423a12eaf0194c05c9e83a824f0e
1 // Copyright 2013 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 "content/shell/browser/layout_test/layout_test_android.h"
7 #include "base/android/fifo_utils.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h"
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h"
13 #include "content/public/test/nested_message_pump_android.h"
14 #include "content/shell/common/shell_switches.h"
15 #include "jni/ShellLayoutTestUtils_jni.h"
16 #include "url/gurl.h"
18 namespace {
20 base::FilePath GetTestFilesDirectory(JNIEnv* env) {
21 ScopedJavaLocalRef<jstring> directory =
22 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory(
23 env, base::android::GetApplicationContext());
24 return base::FilePath(ConvertJavaStringToUTF8(directory));
27 void EnsureCreateFIFO(const base::FilePath& path) {
28 unlink(path.value().c_str());
29 CHECK(base::android::CreateFIFO(path, 0666))
30 << "Unable to create the Android's FIFO: " << path.value().c_str();
33 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
34 return scoped_ptr<base::MessagePump>(new content::NestedMessagePumpAndroid());
37 } // namespace
39 namespace content {
41 void EnsureInitializeForAndroidLayoutTests() {
42 JNIEnv* env = base::android::AttachCurrentThread();
43 content::NestedMessagePumpAndroid::RegisterJni(env);
44 content::RegisterNativesImpl(env);
46 bool success = base::MessageLoop::InitMessagePumpForUIFactory(
47 &CreateMessagePumpForUI);
48 CHECK(success) << "Unable to initialize the message pump for Android.";
50 // Android will need three FIFOs to communicate with the Blink test runner,
51 // one for each of [stdout, stderr, stdin].
52 base::FilePath files_dir(GetTestFilesDirectory(env));
54 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo")));
55 EnsureCreateFIFO(stdout_fifo);
57 base::FilePath stderr_fifo(
58 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo")));
59 EnsureCreateFIFO(stderr_fifo);
61 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo")));
62 EnsureCreateFIFO(stdin_fifo);
64 // Redirecting stdout needs to happen before redirecting stdin, which needs
65 // to happen before redirecting stderr.
66 success = base::android::RedirectStream(stdout, stdout_fifo, "w") &&
67 base::android::RedirectStream(stdin, stdin_fifo, "r") &&
68 base::android::RedirectStream(stderr, stderr_fifo, "w");
70 CHECK(success) << "Unable to initialize the Android FIFOs.";
73 } // namespace content