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

Side by Side Diff: content/shell/browser/layout_test/layout_test_android.cc

Issue 2540603004: [Android] Redirect std{in,out,err} to sockets for layout tests. (Closed)
Patch Set: rebase Created 3 years, 11 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
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/browser/layout_test/layout_test_android.h"
6
7 #include <memory>
8
9 #include "base/android/context_utils.h"
10 #include "base/android/fifo_utils.h"
11 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h"
13 #include "base/command_line.h"
14 #include "base/files/file_path.h"
15 #include "base/message_loop/message_loop.h"
16 #include "content/public/test/nested_message_pump_android.h"
17 #include "content/shell/common/shell_switches.h"
18 #include "jni/ShellLayoutTestUtils_jni.h"
19 #include "url/gurl.h"
20
21 using base::android::ScopedJavaLocalRef;
22
23 namespace {
24
25 base::FilePath GetTestFilesDirectory(JNIEnv* env) {
26 ScopedJavaLocalRef<jstring> directory =
27 content::Java_ShellLayoutTestUtils_getApplicationFilesDirectory(
28 env, base::android::GetApplicationContext());
29 return base::FilePath(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 std::unique_ptr<base::MessagePump> CreateMessagePumpForUI() {
39 return std::unique_ptr<base::MessagePump>(
40 new content::NestedMessagePumpAndroid());
41 }
42
43 } // namespace
44
45 namespace content {
46
47 void EnsureInitializeForAndroidLayoutTests() {
48 JNIEnv* env = base::android::AttachCurrentThread();
49
50 bool success = base::MessageLoop::InitMessagePumpForUIFactory(
51 &CreateMessagePumpForUI);
52 CHECK(success) << "Unable to initialize the message pump for Android.";
53
54 // Android will need three FIFOs to communicate with the Blink test runner,
55 // one for each of [stdout, stderr, stdin].
56 base::FilePath files_dir(GetTestFilesDirectory(env));
57
58 base::FilePath stdout_fifo(files_dir.Append(FILE_PATH_LITERAL("test.fifo")));
59 EnsureCreateFIFO(stdout_fifo);
60
61 base::FilePath stderr_fifo(
62 files_dir.Append(FILE_PATH_LITERAL("stderr.fifo")));
63 EnsureCreateFIFO(stderr_fifo);
64
65 base::FilePath stdin_fifo(files_dir.Append(FILE_PATH_LITERAL("stdin.fifo")));
66 EnsureCreateFIFO(stdin_fifo);
67
68 // Redirecting stdout needs to happen before redirecting stdin, which needs
69 // to happen before redirecting stderr.
70 success = base::android::RedirectStream(stdout, stdout_fifo, "w") &&
71 base::android::RedirectStream(stdin, stdin_fifo, "r") &&
72 base::android::RedirectStream(stderr, stderr_fifo, "w");
73
74 CHECK(success) << "Unable to initialize the Android FIFOs.";
75 }
76
77 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/layout_test_android.h ('k') | content/shell/browser/layout_test/layout_test_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698