| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "content/shell/shell_layout_tests_android.h" |
| 6 |
| 7 #include "base/android/fifo_utils.h" |
| 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "content/public/test/nested_message_pump_android.h" |
| 13 #include "jni/ShellLayoutTestUtils_jni.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 std::string GetTestFilesDirectory(JNIEnv* env) { |
| 18 ScopedJavaLocalRef<jstring> directory = |
| 19 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory( |
| 20 env, base::android::GetApplicationContext()); |
| 21 return ConvertJavaStringToUTF8(directory); |
| 22 } |
| 23 |
| 24 void EnsureCreateFIFO(const base::FilePath& path) { |
| 25 unlink(path.value().c_str()); |
| 26 CHECK(base::android::CreateFIFO(path, 0666)) |
| 27 << "Unable to create the Android's FIFO: " << path.value().c_str(); |
| 28 } |
| 29 |
| 30 base::MessagePump* CreateMessagePumpForUI() { |
| 31 return new content::NestedMessagePumpAndroid(); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 // Path to search for when translating a layout test path to an URL. |
| 37 const char kAndroidLayoutTestPath[] = |
| 38 "/data/local/tmp/third_party/WebKit/LayoutTests/"; |
| 39 |
| 40 // The base URL from which layout tests are being served on Android. |
| 41 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; |
| 42 |
| 43 void EnsureCreateAndroidFIFOs() { |
| 44 JNIEnv* env = base::android::AttachCurrentThread(); |
| 45 content::RegisterNativesImpl(env); |
| 46 |
| 47 base::FilePath files_dir(GetTestFilesDirectory(env)); |
| 48 |
| 49 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo"))); |
| 50 EnsureCreateFIFO(stdout_fifo); |
| 51 |
| 52 base::FilePath stderr_fifo( |
| 53 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo"))); |
| 54 EnsureCreateFIFO(stderr_fifo); |
| 55 |
| 56 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo"))); |
| 57 EnsureCreateFIFO(stdin_fifo); |
| 58 |
| 59 // Redirecting stdout needs to happen before redirecting stdin, which needs |
| 60 // to happen before redirecting stderr. |
| 61 bool success = base::android::RedirectStream(stdout, stdout_fifo, "w") && |
| 62 base::android::RedirectStream(stdin, stdin_fifo, "r") && |
| 63 base::android::RedirectStream(stderr, stderr_fifo, "w"); |
| 64 |
| 65 CHECK(success) << "Unable to initialize the Android FIFOs."; |
| 66 } |
| 67 |
| 68 void EnsureCreateAndroidNestedMessagePump() { |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); |
| 70 content::NestedMessagePumpAndroid::RegisterJni(env); |
| 71 |
| 72 bool success = base::MessageLoop::InitMessagePumpForUIFactory( |
| 73 &CreateMessagePumpForUI); |
| 74 CHECK(success) << "Unable to initialize the message pump for Android."; |
| 75 } |
| OLD | NEW |