| 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 "base/android/fifo_utils.h" | 7 #include "base/android/fifo_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "content/public/test/nested_message_pump_android.h" | 13 #include "content/public/test/nested_message_pump_android.h" |
| 14 #include "content/shell/common/shell_switches.h" | 14 #include "content/shell/common/shell_switches.h" |
| 15 #include "jni/ShellLayoutTestUtils_jni.h" | 15 #include "jni/ShellLayoutTestUtils_jni.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Path to search for when translating a layout test path to an URL. | |
| 21 const char kAndroidLayoutTestPath[] = | |
| 22 "/data/local/tmp/third_party/WebKit/LayoutTests/"; | |
| 23 | |
| 24 // The base URL from which layout tests are being served on Android. | |
| 25 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; | |
| 26 | |
| 27 base::FilePath GetTestFilesDirectory(JNIEnv* env) { | 20 base::FilePath GetTestFilesDirectory(JNIEnv* env) { |
| 28 ScopedJavaLocalRef<jstring> directory = | 21 ScopedJavaLocalRef<jstring> directory = |
| 29 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory( | 22 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory( |
| 30 env, base::android::GetApplicationContext()); | 23 env, base::android::GetApplicationContext()); |
| 31 return base::FilePath(ConvertJavaStringToUTF8(directory)); | 24 return base::FilePath(ConvertJavaStringToUTF8(directory)); |
| 32 } | 25 } |
| 33 | 26 |
| 34 void EnsureCreateFIFO(const base::FilePath& path) { | 27 void EnsureCreateFIFO(const base::FilePath& path) { |
| 35 unlink(path.value().c_str()); | 28 unlink(path.value().c_str()); |
| 36 CHECK(base::android::CreateFIFO(path, 0666)) | 29 CHECK(base::android::CreateFIFO(path, 0666)) |
| 37 << "Unable to create the Android's FIFO: " << path.value().c_str(); | 30 << "Unable to create the Android's FIFO: " << path.value().c_str(); |
| 38 } | 31 } |
| 39 | 32 |
| 40 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() { | 33 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() { |
| 41 return scoped_ptr<base::MessagePump>(new content::NestedMessagePumpAndroid()); | 34 return scoped_ptr<base::MessagePump>(new content::NestedMessagePumpAndroid()); |
| 42 } | 35 } |
| 43 | 36 |
| 44 } // namespace | 37 } // namespace |
| 45 | 38 |
| 46 namespace content { | 39 namespace content { |
| 47 | 40 |
| 48 bool GetTestUrlForAndroid(std::string& path_or_url, GURL* url) { | |
| 49 if (path_or_url.find(kAndroidLayoutTestPath) == std::string::npos) | |
| 50 return false; | |
| 51 | |
| 52 std::string test_location(kAndroidLayoutTestBase); | |
| 53 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); | |
| 54 | |
| 55 *url = GURL(test_location); | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 void EnsureInitializeForAndroidLayoutTests() { | 41 void EnsureInitializeForAndroidLayoutTests() { |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); | 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 61 content::NestedMessagePumpAndroid::RegisterJni(env); | 43 content::NestedMessagePumpAndroid::RegisterJni(env); |
| 62 content::RegisterNativesImpl(env); | 44 content::RegisterNativesImpl(env); |
| 63 | 45 |
| 64 bool success = base::MessageLoop::InitMessagePumpForUIFactory( | 46 bool success = base::MessageLoop::InitMessagePumpForUIFactory( |
| 65 &CreateMessagePumpForUI); | 47 &CreateMessagePumpForUI); |
| 66 CHECK(success) << "Unable to initialize the message pump for Android."; | 48 CHECK(success) << "Unable to initialize the message pump for Android."; |
| 67 | 49 |
| 68 // Android will need three FIFOs to communicate with the Blink test runner, | 50 // Android will need three FIFOs to communicate with the Blink test runner, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 // Redirecting stdout needs to happen before redirecting stdin, which needs | 64 // Redirecting stdout needs to happen before redirecting stdin, which needs |
| 83 // to happen before redirecting stderr. | 65 // to happen before redirecting stderr. |
| 84 success = base::android::RedirectStream(stdout, stdout_fifo, "w") && | 66 success = base::android::RedirectStream(stdout, stdout_fifo, "w") && |
| 85 base::android::RedirectStream(stdin, stdin_fifo, "r") && | 67 base::android::RedirectStream(stdin, stdin_fifo, "r") && |
| 86 base::android::RedirectStream(stderr, stderr_fifo, "w"); | 68 base::android::RedirectStream(stderr, stderr_fifo, "w"); |
| 87 | 69 |
| 88 CHECK(success) << "Unable to initialize the Android FIFOs."; | 70 CHECK(success) << "Unable to initialize the Android FIFOs."; |
| 89 } | 71 } |
| 90 | 72 |
| 91 } // namespace content | 73 } // namespace content |
| OLD | NEW |