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

Unified Diff: content/shell/android/browsertests_apk/content_browser_tests_android.cc

Issue 12213035: Android: Refactor native test setup in a util class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | testing/android/native_test.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/android/browsertests_apk/content_browser_tests_android.cc
diff --git a/content/shell/android/browsertests_apk/content_browser_tests_android.cc b/content/shell/android/browsertests_apk/content_browser_tests_android.cc
index e2313ba8ae2a34895ac24a5f3df754a57bdce707..48b73e9fc2e971cdbc02f241d2d95a1b24eda8b2 100644
--- a/content/shell/android/browsertests_apk/content_browser_tests_android.cc
+++ b/content/shell/android/browsertests_apk/content_browser_tests_android.cc
@@ -22,60 +22,23 @@
#include "content/public/app/android_library_loader_hooks.h"
#include "content/shell/android/shell_jni_registrar.h"
#include "jni/ContentBrowserTestsActivity_jni.h"
+#include "testing/android/native_test_util.h"
+
+using testing::native_test_util::ArgsToArgv;
+using testing::native_test_util::CreateFIFO;
+using testing::native_test_util::ParseArgsFromCommandLineFile;
+using testing::native_test_util::RedirectStream;
+using testing::native_test_util::ScopedMainEntryLogger;
// The main function of the program to be wrapped as an apk.
extern int main(int argc, char** argv);
namespace {
-void ParseArgsFromString(const std::string& command_line,
- std::vector<std::string>* args) {
- base::StringTokenizer tokenizer(command_line, kWhitespaceASCII);
- tokenizer.set_quote_chars("\"");
- while (tokenizer.GetNext()) {
- std::string token;
- RemoveChars(tokenizer.token(), "\"", &token);
- args->push_back(token);
- }
-}
-
-void ParseArgsFromCommandLineFile(std::vector<std::string>* args) {
- // The test runner script writes the command line file in
- // "/data/local/tmp".
- static const char kCommandLineFilePath[] =
- "/data/local/tmp/content-browser-tests-command-line";
- base::FilePath command_line(kCommandLineFilePath);
- std::string command_line_string;
- if (file_util::ReadFileToString(command_line, &command_line_string)) {
- ParseArgsFromString(command_line_string, args);
- }
-}
-
-int ArgsToArgv(const std::vector<std::string>& args,
- std::vector<char*>* argv) {
- // We need to pass in a non-const char**.
- int argc = args.size();
-
- argv->resize(argc + 1);
- for (int i = 0; i < argc; ++i)
- (*argv)[i] = const_cast<char*>(args[i].c_str());
- (*argv)[argc] = NULL; // argv must be NULL terminated.
-
- return argc;
-}
-
-class ScopedMainEntryLogger {
- public:
- ScopedMainEntryLogger() {
- printf(">>ScopedMainEntryLogger\n");
- }
-
- ~ScopedMainEntryLogger() {
- printf("<<ScopedMainEntryLogger\n");
- fflush(stdout);
- fflush(stderr);
- }
-};
+// The test runner script writes the command line file in
+// "/data/local/tmp".
+static const char kCommandLineFilePath[] =
+ "/data/local/tmp/content-browser-tests-command-line";
} // namespace
@@ -95,9 +58,8 @@ static void RunTests(JNIEnv* env,
base::android::RegisterJni(env);
std::vector<std::string> args;
- ParseArgsFromCommandLineFile(&args);
+ ParseArgsFromCommandLineFile(kCommandLineFilePath, &args);
- // We need to pass in a non-const char**.
std::vector<char*> argv;
int argc = ArgsToArgv(args, &argv);
@@ -105,6 +67,13 @@ static void RunTests(JNIEnv* env,
CommandLine::ForCurrentProcess()->AppendArguments(
CommandLine(argc, &argv[0]), false);
+ // Create fifo and redirect stdout and stderr to it.
+ FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir));
+ FilePath fifo_path(files_dir.Append(FilePath("test.fifo")));
+ CreateFIFO(fifo_path.value().c_str());
+ RedirectStream(stdout, fifo_path.value().c_str(), "w");
+ dup2(STDOUT_FILENO, STDERR_FILENO);
+
ScopedMainEntryLogger scoped_main_entry_logger;
main(argc, &argv[0]);
}
« no previous file with comments | « content/content_tests.gypi ('k') | testing/android/native_test.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698