Restore old behavior for Android in fileutils.cc

From r7014 the Android APK tests are designed to be
build from a standalone WebRTC checkout instead of a
Chromium checkout. Because of that, the special handling
for both cases can be removed.

I also don't think we need to use the
base::android::GetExternalStorageDirectory() method since
all devices has a symlink at /sdcard that points
to /storage/emulated/legacy on the Android device.

This essentially reverts the changes in
https://webrtc-codereview.appspot.com/1754005/
plus some minor changes.

BUG=webrtc:3741
TEST=Locally running test_support_unittests APK test on an
Android device using:
CHECKOUT_SOURCE_ROOT=`pwd` build/android/test_runner.py gtest -s test_support_unittests --verbose --isolate-file-path=webrtc/test/test_support_unittests.isolate
R=henrike@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/15329004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7632 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kjellander@webrtc.org 2014-11-05 06:28:50 +00:00
parent f6e1600a7d
commit 72fd339352
6 changed files with 21 additions and 106 deletions

View File

@ -67,10 +67,7 @@ source_set("test_support") {
]
if (is_android) {
sources += [ "testsupport/android/root_path_android_chromium.cc" ]
deps += [ "//base:base" ]
} else {
sources += [ "testsupport/android/root_path_android.cc" ]
}
configs += [ "..:common_config" ]

View File

@ -98,8 +98,6 @@
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
],
'sources': [
'testsupport/android/root_path_android.cc',
'testsupport/android/root_path_android_chromium.cc',
'testsupport/fileutils.cc',
'testsupport/fileutils.h',
'testsupport/frame_reader.cc',
@ -117,20 +115,6 @@
'testsupport/trace_to_stderr.cc',
'testsupport/trace_to_stderr.h',
],
'conditions': [
['OS=="android"', {
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
],
'sources!': [
'testsupport/android/root_path_android.cc',
],
}, {
'sources!': [
'testsupport/android/root_path_android_chromium.cc',
],
}],
],
},
{
# Depend on this target when you want to have test_support but also the

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <string>
namespace webrtc {
namespace test {
static const char* kRootDirName = "/sdcard/";
std::string ProjectRootPathAndroid() {
return kRootDirName;
}
std::string OutputPathAndroid() {
return kRootDirName;
}
} // namespace test
} // namespace webrtc

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "base/android/path_utils.h"
#include "base/files/file_path.h"
namespace webrtc {
namespace test {
std::string OutputPathImpl();
// This file is only compiled when running WebRTC tests in a Chromium workspace.
// The Android testing framework will push files relative to the root path of
// the Chromium workspace. The root path for webrtc is one directory up from
// trunk/webrtc (in standalone) or src/third_party/webrtc (in Chromium).
std::string ProjectRootPathAndroid() {
base::FilePath root_path;
base::android::GetExternalStorageDirectory(&root_path);
return root_path.value() + "/";
}
std::string OutputPathAndroid() {
return OutputPathImpl();
}
} // namespace test
} // namespace webrtc

View File

@ -50,15 +50,15 @@ const char* kPathDelimiter = "/";
#endif
#ifdef WEBRTC_ANDROID
const char* kResourcesDirName = "resources";
const char* kRootDirName = "/sdcard/";
#else
// The file we're looking for to identify the project root dir.
const char* kProjectRootFileName = "DEPS";
const char* kResourcesDirName = "resources";
#endif
const char* kFallbackPath = "./";
const char* kOutputDirName = "out";
const char* kFallbackPath = "./";
#endif
const char* kResourcesDirName = "resources";
char relative_dir_path[FILENAME_MAX];
bool relative_dir_path_set = false;
@ -66,9 +66,6 @@ bool relative_dir_path_set = false;
const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
std::string OutputPathAndroid();
std::string ProjectRootPathAndroid();
void SetExecutablePath(const std::string& path) {
std::string working_dir = WorkingDir();
std::string temp_path = path;
@ -95,30 +92,18 @@ bool FileExists(std::string& file_name) {
return stat(file_name.c_str(), &file_info) == 0;
}
std::string OutputPathImpl() {
std::string path = ProjectRootPath();
if (path == kCannotFindProjectRootDir) {
return kFallbackPath;
}
path += kOutputDirName;
if (!CreateDir(path)) {
return kFallbackPath;
}
return path + kPathDelimiter;
}
#ifdef WEBRTC_ANDROID
std::string ProjectRootPath() {
return ProjectRootPathAndroid();
return kRootDirName;
}
std::string OutputPath() {
return OutputPathAndroid();
return kRootDirName;
}
std::string WorkingDir() {
return ProjectRootPath();
return kRootDirName;
}
#else // WEBRTC_ANDROID
@ -148,7 +133,15 @@ std::string ProjectRootPath() {
}
std::string OutputPath() {
return OutputPathImpl();
std::string path = ProjectRootPath();
if (path == kCannotFindProjectRootDir) {
return kFallbackPath;
}
path += kOutputDirName;
if (!CreateDir(path)) {
return kFallbackPath;
}
return path + kPathDelimiter;
}
std::string WorkingDir() {

View File

@ -66,7 +66,7 @@ TEST_F(FileUtilsTest, ProjectRootPath) {
}
// Similar to the above test, but for the output dir
TEST_F(FileUtilsTest, OutputPathFromUnchangedWorkingDir) {
TEST_F(FileUtilsTest, DISABLED_ON_ANDROID(OutputPathFromUnchangedWorkingDir)) {
std::string path = webrtc::test::OutputPath();
std::string expected_end = "out";
expected_end = kPathDelimiter + expected_end + kPathDelimiter;
@ -80,10 +80,11 @@ TEST_F(FileUtilsTest, DISABLED_ON_ANDROID(OutputPathFromRootWorkingDir)) {
ASSERT_EQ("./", webrtc::test::OutputPath());
}
TEST_F(FileUtilsTest, DISABLED_ON_ANDROID(TempFilename)) {
TEST_F(FileUtilsTest, TempFilename) {
std::string temp_filename = webrtc::test::TempFilename(
webrtc::test::OutputPath(), "TempFilenameTest");
ASSERT_TRUE(webrtc::test::FileExists(temp_filename));
ASSERT_TRUE(webrtc::test::FileExists(temp_filename))
<< "Couldn't find file: " << temp_filename;
remove(temp_filename.c_str());
}