Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: content/shell/shell_layout_tests_android.cc

Issue 17265005: content_shell: Create the FIFOs needed for running Android layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/shell/shell_layout_tests_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
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 "googleurl/src/gurl.h"
14 #include "jni/ShellLayoutTestUtils_jni.h"
15
16 namespace {
17
18 // Path to search for when translating a layout test path to an URL.
19 const char kAndroidLayoutTestPath[] =
20 "/data/local/tmp/third_party/WebKit/LayoutTests/";
21
22 // The base URL from which layout tests are being served on Android.
23 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/";
24
25 std::string GetTestFilesDirectory(JNIEnv* env) {
bulach 2013/06/20 08:48:41 nit: return a FilePath directly
Peter Beverloo 2013/06/20 10:43:46 Done.
26 ScopedJavaLocalRef<jstring> directory =
27 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory(
28 env, base::android::GetApplicationContext());
29 return ConvertJavaStringToUTF8(directory);
30 }
31
32 void EnsureCreateFIFO(const base::FilePath& path) {
33 unlink(path.value().c_str());
34 CHECK(base::android::CreateFIFO(path, 0666))
35 << "Unable to create the Android's FIFO: " << path.value().c_str();
36 }
37
38 base::MessagePump* CreateMessagePumpForUI() {
39 return new content::NestedMessagePumpAndroid();
40 }
41
42 } // namespace
43
44 namespace content {
45
46 bool GetTestUrlForAndroid(std::string& path_or_url, GURL* url) {
47 if (path_or_url.find(kAndroidLayoutTestPath) == std::string::npos)
48 return false;
49
50 std::string test_location(kAndroidLayoutTestBase);
51 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath)));
52
53 *url = GURL(test_location);
54 return true;
55 }
56
57 void EnsureInitializeForAndroidLayoutTests() {
bulach 2013/06/20 08:48:41 nit: just in case, could do with: CHECK(CommandLi
Peter Beverloo 2013/06/20 10:43:46 Done.
58 JNIEnv* env = base::android::AttachCurrentThread();
59 content::NestedMessagePumpAndroid::RegisterJni(env);
60 content::RegisterNativesImpl(env);
61
62 bool success = base::MessageLoop::InitMessagePumpForUIFactory(
63 &CreateMessagePumpForUI);
64 CHECK(success) << "Unable to initialize the message pump for Android.";
65
66 // Android will need three FIFOs to communicate with the Blink test runner,
67 // one for each of [stdout, stderr, stdin].
68 base::FilePath files_dir(GetTestFilesDirectory(env));
69
70 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo")));
71 EnsureCreateFIFO(stdout_fifo);
72
73 base::FilePath stderr_fifo(
74 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo")));
75 EnsureCreateFIFO(stderr_fifo);
76
77 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo")));
78 EnsureCreateFIFO(stdin_fifo);
79
80 // Redirecting stdout needs to happen before redirecting stdin, which needs
81 // to happen before redirecting stderr.
82 success = base::android::RedirectStream(stdout, stdout_fifo, "w") &&
83 base::android::RedirectStream(stdin, stdin_fifo, "r") &&
84 base::android::RedirectStream(stderr, stderr_fifo, "w");
85
86 CHECK(success) << "Unable to initialize the Android FIFOs.";
87 }
88
89 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_layout_tests_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698