Commit 97803e1b authored by tim@chromium.org's avatar tim@chromium.org

android tests: don't override DIR_MODULE (take 2)

another attempt at https://codereview.chromium.org/408063002/ to try fixing
the iOS Simulator:URLFixerTest failures writing to DIR_TEST_DATA.

R=nyquist@chromium.org
TBR=brettw@chromium.org, nyquist@chromium.org, sky@chromium.org
BUG=

Review URL: https://codereview.chromium.org/411253010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285451 0039d316-1c4b-4281-b951-d872f2087c98
parent 6361a766
......@@ -140,9 +140,6 @@ scoped_ptr<base::MessagePump> CreateMessagePumpForUIStub() {
// Provides the test path for DIR_MODULE and DIR_ANDROID_APP_DATA.
bool GetTestProviderPath(int key, base::FilePath* result) {
switch (key) {
case base::DIR_MODULE: {
return base::android::GetExternalStorageDirectory(result);
}
case base::DIR_ANDROID_APP_DATA: {
// For tests, app data is put in external storage.
return base::android::GetExternalStorageDirectory(result);
......
......@@ -20,6 +20,7 @@
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#include "base/base_paths_android.h"
#endif
#if defined(OS_MACOSX)
......@@ -434,8 +435,15 @@ bool PathProvider(int key, base::FilePath* result) {
// will fail if executed from an installed executable (because the
// generated path won't exist).
case chrome::DIR_GEN_TEST_DATA:
#if defined(OS_ANDROID)
// On Android, our tests don't have permission to write to DIR_MODULE.
// gtest/test_runner.py pushes data to external storage.
if (!PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &cur))
return false;
#else
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("test_data"));
if (!base::PathExists(cur)) // We don't want to create this.
return false;
......
......@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
......@@ -352,11 +353,11 @@ TEST(URLFixerTest, FixupURL) {
// has to exist.
TEST(URLFixerTest, FixupFile) {
// this "original" filename is the one we tweak to get all the variations
base::FilePath dir;
base::ScopedTempDir temp_dir_;
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath original;
ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &dir));
ASSERT_TRUE(MakeTempFile(
dir,
temp_dir_.path(),
base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")),
&original));
......@@ -435,11 +436,12 @@ TEST(URLFixerTest, FixupFile) {
}
TEST(URLFixerTest, FixupRelativeFile) {
base::FilePath full_path, dir;
base::FilePath full_path;
base::FilePath file_part(
FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt"));
ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &dir));
ASSERT_TRUE(MakeTempFile(dir, file_part, &full_path));
base::ScopedTempDir temp_dir_;
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(MakeTempFile(temp_dir_.path(), file_part, &full_path));
full_path = base::MakeAbsoluteFilePath(full_path);
ASSERT_FALSE(full_path.empty());
......@@ -448,22 +450,23 @@ TEST(URLFixerTest, FixupRelativeFile) {
FixupCase value = fixup_cases[i];
base::FilePath input = base::FilePath::FromUTF8Unsafe(value.input);
EXPECT_EQ(value.output,
url_fixer::FixupRelativeFile(dir, input).possibly_invalid_spec());
url_fixer::FixupRelativeFile(temp_dir_.path(),
input).possibly_invalid_spec());
}
// make sure the existing file got fixed-up to a file URL, and that there
// are no backslashes
EXPECT_TRUE(IsMatchingFileURL(
url_fixer::FixupRelativeFile(dir, file_part).possibly_invalid_spec(),
full_path));
url_fixer::FixupRelativeFile(temp_dir_.path(),
file_part).possibly_invalid_spec(), full_path));
EXPECT_TRUE(base::DeleteFile(full_path, false));
// create a filename we know doesn't exist and make sure it doesn't get
// fixed up to a file URL
base::FilePath nonexistent_file(
FILE_PATH_LITERAL("url_fixer_upper_nonexistent_file.txt"));
std::string fixedup(url_fixer::FixupRelativeFile(dir, nonexistent_file)
.possibly_invalid_spec());
std::string fixedup(url_fixer::FixupRelativeFile(
temp_dir_.path(), nonexistent_file).possibly_invalid_spec());
EXPECT_NE(std::string("file:///"), fixedup.substr(0, 8));
EXPECT_FALSE(IsMatchingFileURL(fixedup, nonexistent_file));
......@@ -473,7 +476,7 @@ TEST(URLFixerTest, FixupRelativeFile) {
base::FilePath sub_dir(FILE_PATH_LITERAL("url fixer-upper dir"));
base::FilePath sub_file(
FILE_PATH_LITERAL("url fixer-upper existing file.txt"));
base::FilePath new_dir = dir.Append(sub_dir);
base::FilePath new_dir = temp_dir_.path().Append(sub_dir);
base::CreateDirectory(new_dir);
ASSERT_TRUE(MakeTempFile(new_dir, sub_file, &full_path));
full_path = base::MakeAbsoluteFilePath(full_path);
......@@ -482,8 +485,8 @@ TEST(URLFixerTest, FixupRelativeFile) {
// test file in the subdir
base::FilePath relative_file = sub_dir.Append(sub_file);
EXPECT_TRUE(IsMatchingFileURL(
url_fixer::FixupRelativeFile(dir, relative_file).possibly_invalid_spec(),
full_path));
url_fixer::FixupRelativeFile(temp_dir_.path(),
relative_file).possibly_invalid_spec(), full_path));
// test file in the subdir with different slashes and escaping.
base::FilePath::StringType relative_file_str = sub_dir.value() +
......@@ -491,18 +494,18 @@ TEST(URLFixerTest, FixupRelativeFile) {
ReplaceSubstringsAfterOffset(&relative_file_str, 0,
FILE_PATH_LITERAL(" "), FILE_PATH_LITERAL("%20"));
EXPECT_TRUE(IsMatchingFileURL(
url_fixer::FixupRelativeFile(dir, base::FilePath(relative_file_str))
.possibly_invalid_spec(),
full_path));
url_fixer::FixupRelativeFile(temp_dir_.path(),
base::FilePath(relative_file_str)).possibly_invalid_spec(),
full_path));
// test relative directories and duplicate slashes
// (should resolve to the same file as above)
relative_file_str = sub_dir.value() + FILE_PATH_LITERAL("/../") +
sub_dir.value() + FILE_PATH_LITERAL("///./") + sub_file.value();
EXPECT_TRUE(IsMatchingFileURL(
url_fixer::FixupRelativeFile(dir, base::FilePath(relative_file_str))
.possibly_invalid_spec(),
full_path));
url_fixer::FixupRelativeFile(temp_dir_.path(),
base::FilePath(relative_file_str)).possibly_invalid_spec(),
full_path));
// done with the subdir
EXPECT_TRUE(base::DeleteFile(full_path, false));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment