| Index: content/shell/shell_layout_tests_android.cc
|
| diff --git a/content/shell/shell_layout_tests_android.cc b/content/shell/shell_layout_tests_android.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2b22eaff2a850fb477e588645c70d4ef4cd9a9e4
|
| --- /dev/null
|
| +++ b/content/shell/shell_layout_tests_android.cc
|
| @@ -0,0 +1,75 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/shell/shell_layout_tests_android.h"
|
| +
|
| +#include "base/android/fifo_utils.h"
|
| +#include "base/android/jni_android.h"
|
| +#include "base/android/jni_string.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/message_loop.h"
|
| +#include "content/public/test/nested_message_pump_android.h"
|
| +#include "jni/ShellLayoutTestUtils_jni.h"
|
| +
|
| +namespace {
|
| +
|
| +std::string GetTestFilesDirectory(JNIEnv* env) {
|
| + ScopedJavaLocalRef<jstring> directory =
|
| + content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory(
|
| + env, base::android::GetApplicationContext());
|
| + return ConvertJavaStringToUTF8(directory);
|
| +}
|
| +
|
| +void EnsureCreateFIFO(const base::FilePath& path) {
|
| + unlink(path.value().c_str());
|
| + CHECK(base::android::CreateFIFO(path, 0666))
|
| + << "Unable to create the Android's FIFO: " << path.value().c_str();
|
| +}
|
| +
|
| +base::MessagePump* CreateMessagePumpForUI() {
|
| + return new content::NestedMessagePumpAndroid();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// Path to search for when translating a layout test path to an URL.
|
| +const char kAndroidLayoutTestPath[] =
|
| + "/data/local/tmp/third_party/WebKit/LayoutTests/";
|
| +
|
| +// The base URL from which layout tests are being served on Android.
|
| +const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/";
|
| +
|
| +void EnsureCreateAndroidFIFOs() {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + content::RegisterNativesImpl(env);
|
| +
|
| + base::FilePath files_dir(GetTestFilesDirectory(env));
|
| +
|
| + base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo")));
|
| + EnsureCreateFIFO(stdout_fifo);
|
| +
|
| + base::FilePath stderr_fifo(
|
| + files_dir.Append(FILE_PATH_LITERAL("stderr.fifo")));
|
| + EnsureCreateFIFO(stderr_fifo);
|
| +
|
| + base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo")));
|
| + EnsureCreateFIFO(stdin_fifo);
|
| +
|
| + // Redirecting stdout needs to happen before redirecting stdin, which needs
|
| + // to happen before redirecting stderr.
|
| + bool success = base::android::RedirectStream(stdout, stdout_fifo, "w") &&
|
| + base::android::RedirectStream(stdin, stdin_fifo, "r") &&
|
| + base::android::RedirectStream(stderr, stderr_fifo, "w");
|
| +
|
| + CHECK(success) << "Unable to initialize the Android FIFOs.";
|
| +}
|
| +
|
| +void EnsureCreateAndroidNestedMessagePump() {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + content::NestedMessagePumpAndroid::RegisterJni(env);
|
| +
|
| + bool success = base::MessageLoop::InitMessagePumpForUIFactory(
|
| + &CreateMessagePumpForUI);
|
| + CHECK(success) << "Unable to initialize the message pump for Android.";
|
| +}
|
|
|