| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/browser/layout_test/layout_test_android.h" | 5 #include "content/shell/browser/layout_test/layout_test_android.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/fifo_utils.h" | 10 #include "base/android/fifo_utils.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 base::FilePath GetTestFilesDirectory(JNIEnv* env) { | 25 base::FilePath GetTestFilesDirectory(JNIEnv* env) { |
| 26 ScopedJavaLocalRef<jstring> directory = | 26 ScopedJavaLocalRef<jstring> directory = |
| 27 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory( | 27 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory( |
| 28 env, base::android::GetApplicationContext()); | 28 env, base::android::GetApplicationContext()); |
| 29 return base::FilePath(ConvertJavaStringToUTF8(directory)); | 29 return base::FilePath(ConvertJavaStringToUTF8(directory)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void EnsureCreateFIFO(const base::FilePath& path) { | 32 void EnsureCreateFIFO(const base::FilePath& path) { |
| 33 unlink(path.value().c_str()); | 33 unlink(path.value().c_str()); |
| 34 CHECK(base::android::CreateFIFO(path, 0666)) | 34 // Unable to create the Android's FIFO. |
| 35 << "Unable to create the Android's FIFO: " << path.value().c_str(); | 35 CHECK(base::android::CreateFIFO(path, 0666)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() { | 38 std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() { |
| 39 return std::unique_ptr<base::MessagePump>( | 39 return std::unique_ptr<base::MessagePump>( |
| 40 new content::NestedMessagePumpAndroid()); | 40 new content::NestedMessagePumpAndroid()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 namespace content { | 45 namespace content { |
| 46 | 46 |
| 47 void EnsureInitializeForAndroidLayoutTests() { | 47 void EnsureInitializeForAndroidLayoutTests() { |
| 48 JNIEnv* env = base::android::AttachCurrentThread(); | 48 JNIEnv* env = base::android::AttachCurrentThread(); |
| 49 | 49 |
| 50 bool success = base::MessageLoop::InitMessagePumpForUIFactory( | 50 bool success = base::MessageLoop::InitMessagePumpForUIFactory( |
| 51 &CreateMessagePumpForUI); | 51 &CreateMessagePumpForUI); |
| 52 CHECK(success) << "Unable to initialize the message pump for Android."; | 52 // Unable to initialize the message pump for Android. |
| 53 CHECK(success); |
| 53 | 54 |
| 54 // Android will need three FIFOs to communicate with the Blink test runner, | 55 // Android will need three FIFOs to communicate with the Blink test runner, |
| 55 // one for each of [stdout, stderr, stdin]. | 56 // one for each of [stdout, stderr, stdin]. |
| 56 base::FilePath files_dir(GetTestFilesDirectory(env)); | 57 base::FilePath files_dir(GetTestFilesDirectory(env)); |
| 57 | 58 |
| 58 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo"))); | 59 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo"))); |
| 59 EnsureCreateFIFO(stdout_fifo); | 60 EnsureCreateFIFO(stdout_fifo); |
| 60 | 61 |
| 61 base::FilePath stderr_fifo( | 62 base::FilePath stderr_fifo( |
| 62 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo"))); | 63 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo"))); |
| 63 EnsureCreateFIFO(stderr_fifo); | 64 EnsureCreateFIFO(stderr_fifo); |
| 64 | 65 |
| 65 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo"))); | 66 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo"))); |
| 66 EnsureCreateFIFO(stdin_fifo); | 67 EnsureCreateFIFO(stdin_fifo); |
| 67 | 68 |
| 68 // Redirecting stdout needs to happen before redirecting stdin, which needs | 69 // Redirecting stdout needs to happen before redirecting stdin, which needs |
| 69 // to happen before redirecting stderr. | 70 // to happen before redirecting stderr. |
| 70 success = base::android::RedirectStream(stdout, stdout_fifo, "w") && | 71 success = base::android::RedirectStream(stdout, stdout_fifo, "w") && |
| 71 base::android::RedirectStream(stdin, stdin_fifo, "r") && | 72 base::android::RedirectStream(stdin, stdin_fifo, "r") && |
| 72 base::android::RedirectStream(stderr, stderr_fifo, "w"); | 73 base::android::RedirectStream(stderr, stderr_fifo, "w"); |
| 73 | 74 |
| 74 CHECK(success) << "Unable to initialize the Android FIFOs."; | 75 // Unable to initialize the Android FIFOs. |
| 76 CHECK(success); |
| 75 } | 77 } |
| 76 | 78 |
| 77 } // namespace content | 79 } // namespace content |
| OLD | NEW |