Skip to content

Commit

Permalink
Disable URLRequestFileDirTest tests that fail on Android.
Browse files Browse the repository at this point in the history
Various RootDirectory test cases exist to make sure browsing file:///
works. However, this action is not allowed on Android, so it is a slight
mystery how the tests manage to pass on earlier version of Android. The
tests fail under newer version of Android.

Given this situation, just disable the tests on Android altogether, as
it is pointless to test a disallowed action. Also combine the test cases
which are very similar into a single test case with a for-loop.

BUG=787149

Change-Id: Icec5ed676b245519ae98e8914b397122d5c7bbd5
Reviewed-on: https://chromium-review.googlesource.com/780921
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518421}
  • Loading branch information
leizleiz authored and Commit Bot committed Nov 21, 2017
1 parent bbcd68d commit 284aae9
Showing 1 changed file with 28 additions and 73 deletions.
101 changes: 28 additions & 73 deletions net/url_request/url_request_file_dir_job_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,83 +302,38 @@ TEST_F(URLRequestFileDirTest, EmptyDirectory) {
EXPECT_FALSE(HasParentDirEntry(delegate.data_received()));
}

// Android security policies prevent access to the root directory, so skip this
// test there.
#if !defined(OS_ANDROID)
TEST_F(URLRequestFileDirTest, RootDirectory) {
for (int slashes_to_test = 1; slashes_to_test < 4; ++slashes_to_test) {
base::FilePath::StringType root_dir_string;
#if defined(OS_WIN)
base::FilePath root_dir(L"C:\\");
#else
base::FilePath root_dir("/");
root_dir_string = L"C:";
#endif
TestJobFactory factory(root_dir);
context_.set_job_factory(&factory);

TestDelegate delegate;
std::unique_ptr<URLRequest> request(
context_.CreateRequest(FilePathToFileURL(root_dir), DEFAULT_PRIORITY,
&delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
EXPECT_TRUE(request->is_pending());

base::RunLoop().Run();

ASSERT_GT(delegate.bytes_received(), 0);
ASSERT_LE(delegate.bytes_received(), kBufferSize);
EXPECT_TRUE(HasHeader(delegate.data_received(), root_dir));
EXPECT_FALSE(HasParentDirLink(delegate.data_received()));
EXPECT_GT(GetEntryCount(delegate.data_received()), 0);
EXPECT_FALSE(HasParentDirEntry(delegate.data_received()));
}

TEST_F(URLRequestFileDirTest, RootDirectoryWithTrailer) {
#if defined(OS_WIN)
base::FilePath root_dir(L"C:\\\\");
#else
base::FilePath root_dir("//");
#endif
TestJobFactory factory(root_dir);
context_.set_job_factory(&factory);

TestDelegate delegate;
std::unique_ptr<URLRequest> request(
context_.CreateRequest(FilePathToFileURL(root_dir), DEFAULT_PRIORITY,
&delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
EXPECT_TRUE(request->is_pending());

base::RunLoop().Run();

ASSERT_GT(delegate.bytes_received(), 0);
ASSERT_LE(delegate.bytes_received(), kBufferSize);
EXPECT_TRUE(HasHeader(delegate.data_received(), root_dir));
EXPECT_FALSE(HasParentDirLink(delegate.data_received()));
EXPECT_GT(GetEntryCount(delegate.data_received()), 0);
EXPECT_FALSE(HasParentDirEntry(delegate.data_received()));
}

TEST_F(URLRequestFileDirTest, RootDirectoryWithLongerTrailer) {
#if defined(OS_WIN)
base::FilePath root_dir(L"C:\\\\\\");
#else
base::FilePath root_dir("///");
#endif
TestJobFactory factory(root_dir);
context_.set_job_factory(&factory);

TestDelegate delegate;
std::unique_ptr<URLRequest> request(
context_.CreateRequest(FilePathToFileURL(root_dir), DEFAULT_PRIORITY,
&delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
EXPECT_TRUE(request->is_pending());

base::RunLoop().Run();

ASSERT_GT(delegate.bytes_received(), 0);
ASSERT_LE(delegate.bytes_received(), kBufferSize);
EXPECT_TRUE(HasHeader(delegate.data_received(), root_dir));
EXPECT_FALSE(HasParentDirLink(delegate.data_received()));
EXPECT_GT(GetEntryCount(delegate.data_received()), 0);
EXPECT_FALSE(HasParentDirEntry(delegate.data_received()));
root_dir_string.append(slashes_to_test, base::FilePath::kSeparators[0]);
base::FilePath root_dir(root_dir_string);
TestJobFactory factory(root_dir);
context_.set_job_factory(&factory);

TestDelegate delegate;
std::unique_ptr<URLRequest> request(
context_.CreateRequest(FilePathToFileURL(root_dir), DEFAULT_PRIORITY,
&delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
EXPECT_TRUE(request->is_pending());

base::RunLoop().Run();

ASSERT_GT(delegate.bytes_received(), 0);
ASSERT_LE(delegate.bytes_received(), kBufferSize);
EXPECT_TRUE(HasHeader(delegate.data_received(), root_dir));
EXPECT_FALSE(HasParentDirLink(delegate.data_received()));
EXPECT_GT(GetEntryCount(delegate.data_received()), 0);
EXPECT_FALSE(HasParentDirEntry(delegate.data_received()));
}
}
#endif // !defined(OS_ANDROID)

} // namespace

Expand Down

0 comments on commit 284aae9

Please sign in to comment.