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

Unified Diff: chrome/browser/google_apis/fake_drive_service_unittest.cc

Issue 11824020: google_apis: Implement DownloadFile in FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add DownloadFile_NonexistingFile test Created 7 years, 11 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 | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/google_apis/fake_drive_service_unittest.cc
diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc
index 2c4a973ce6b82c4a3e58b6770c5b15124cfd9f36..3bfd83ca37f0d15664d977cd880d0d1d9e01bbd2 100644
--- a/chrome/browser/google_apis/fake_drive_service_unittest.cc
+++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/google_apis/fake_drive_service.h"
+#include "base/file_util.h"
+#include "base/files/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/google_apis/gdata_wapi_parser.h"
@@ -169,6 +171,56 @@ TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) {
EXPECT_EQ(HTTP_NOT_FOUND, error);
}
+TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ const GURL kContentUrl("https://file_content_url/");
+ const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt");
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ FilePath output_file_path;
+ fake_service_.DownloadFile(
+ FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
+ kOutputFilePath,
+ kContentUrl,
+ base::Bind(&test_util::CopyResultsFromDownloadActionCallback,
+ &error,
+ &output_file_path),
+ GetContentCallback());
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ EXPECT_EQ(output_file_path, kOutputFilePath);
+ std::string content;
+ ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
+ EXPECT_EQ(kContentUrl.spec(), content);
+}
+
+TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ const GURL kContentUrl("https://non_existing_content_url/");
+ const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt");
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ FilePath output_file_path;
+ fake_service_.DownloadFile(
+ FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
+ kOutputFilePath,
+ kContentUrl,
+ base::Bind(&test_util::CopyResultsFromDownloadActionCallback,
+ &error,
+ &output_file_path),
+ GetContentCallback());
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_NOT_FOUND, error);
+}
+
TEST_F(FakeDriveServiceTest, CopyHostedDocument_ExistingHostedDocument) {
ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698