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

Unified Diff: net/url_request/url_request_file_job_unittest.cc

Issue 739033003: Support content scheme uri for Chrome on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 6 years, 1 month 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
Index: net/url_request/url_request_file_job_unittest.cc
diff --git a/net/url_request/url_request_file_job_unittest.cc b/net/url_request/url_request_file_job_unittest.cc
index 23ded74576470dd28d704281b29aaced0cc801e5..376faa6c420a03ee61a7b4bef1f59c0af8151789 100644
--- a/net/url_request/url_request_file_job_unittest.cc
+++ b/net/url_request/url_request_file_job_unittest.cc
@@ -16,6 +16,10 @@
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_ANDROID)
+#include "base/test/test_file_util.h"
+#endif
+
namespace net {
namespace {
@@ -96,6 +100,9 @@ class CallbacksJobFactory : public URLRequestJobFactory {
}
bool IsHandledProtocol(const std::string& scheme) const override {
+#if defined(OS_ANDROID)
+ return scheme == "file" || scheme == "content";
+#endif
return scheme == "file";
}
@@ -172,6 +179,14 @@ class URLRequestFileJobEventsTest : public testing::Test {
// observed.
void RunRequest(const std::string& content, const Range* range);
+
+ // Helper methods called by RunRequest to run the url request and verify
+ // the returned results.
+ void RunRequestInternal(const base::FilePath& path,
+ const Range* range);
+ void VerifyResult(const std::string& content,
+ const Range* range);
+
JobObserverImpl observer_;
TestURLRequestContext context_;
TestDelegate delegate_;
@@ -185,6 +200,15 @@ void URLRequestFileJobEventsTest::RunRequest(const std::string& content,
ASSERT_TRUE(directory.CreateUniqueTempDir());
base::FilePath path;
ASSERT_TRUE(CreateTempFileWithContent(content, directory, &path));
+ if (range)
+ ASSERT_LT(static_cast<unsigned int>(range->end), content.length());
asanka 2014/11/21 02:22:02 Why not test the behavior when a range request ext
+ RunRequestInternal(path, range);
+ VerifyResult(content, range);
+}
+
+void URLRequestFileJobEventsTest::RunRequestInternal(
+ const base::FilePath& path,
+ const Range* range) {
CallbacksJobFactory factory(path, &observer_);
context_.set_job_factory(&factory);
@@ -194,7 +218,6 @@ void URLRequestFileJobEventsTest::RunRequest(const std::string& content,
ASSERT_GE(range->start, 0);
ASSERT_GE(range->end, 0);
ASSERT_LE(range->start, range->end);
- ASSERT_LT(static_cast<unsigned int>(range->end), content.length());
std::string range_value =
base::StringPrintf("bytes=%d-%d", range->start, range->end);
request->SetExtraRequestHeaderByName(
@@ -204,6 +227,10 @@ void URLRequestFileJobEventsTest::RunRequest(const std::string& content,
base::RunLoop loop;
loop.Run();
+}
+
+void URLRequestFileJobEventsTest::VerifyResult(const std::string& content,
+ const Range* range) {
asanka 2014/11/21 02:22:02 extra whitespace.
EXPECT_FALSE(delegate_.request_failed());
int expected_length =
@@ -264,6 +291,31 @@ TEST_F(URLRequestFileJobEventsTest, Range) {
RunRequest(MakeContentOfSize(size), &range);
}
+#if defined(OS_ANDROID)
+TEST_F(URLRequestFileJobEventsTest, ContentUriFile) {
+ base::FilePath test_dir;
+ PathService::Get(base::DIR_SOURCE_ROOT, &test_dir);
+ test_dir = test_dir.AppendASCII("net");
+ test_dir = test_dir.AppendASCII("data");
+ test_dir = test_dir.AppendASCII("url_request_unittest");
+ ASSERT_TRUE(base::PathExists(test_dir));
+ base::FilePath image_file = test_dir.Append(FILE_PATH_LITERAL("red.png"));
+
+ // Insert the image into MediaStore. MediaStore will do some conversions, and
+ // return the content URI.
+ base::FilePath path = base::InsertImageIntoMediaStore(image_file);
+ EXPECT_TRUE(path.IsContentUri());
+ EXPECT_TRUE(base::PathExists(path));
+ int64 file_size;
+ EXPECT_TRUE(base::GetFileSize(path, &file_size));
+ EXPECT_LT(0, file_size);
+
+ RunRequestInternal(path, NULL);
asanka 2014/11/21 02:22:02 This doesn't run the test with a content:// URI, d
+ EXPECT_FALSE(delegate_.request_failed());
+ EXPECT_EQ(delegate_.bytes_received(), file_size);
asanka 2014/11/21 02:22:02 Assuming the test will still look like this, the r
+}
+#endif
+
} // namespace
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698