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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/google_apis/fake_drive_service.h" 5 #include "chrome/browser/google_apis/fake_drive_service.h"
6 6
7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
7 #include "base/message_loop.h" 9 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 11 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
10 #include "chrome/browser/google_apis/test_util.h" 12 #include "chrome/browser/google_apis/test_util.h"
11 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
12 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace google_apis { 17 namespace google_apis {
16 18
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 GDataErrorCode error = GDATA_OTHER_ERROR; 164 GDataErrorCode error = GDATA_OTHER_ERROR;
163 fake_service_.DeleteResource( 165 fake_service_.DeleteResource(
164 GURL("https://file1_link_self/file:nonexisting_resource_id"), 166 GURL("https://file1_link_self/file:nonexisting_resource_id"),
165 base::Bind(&test_util::CopyResultsFromEntryActionCallback, 167 base::Bind(&test_util::CopyResultsFromEntryActionCallback,
166 &error)); 168 &error));
167 message_loop_.RunUntilIdle(); 169 message_loop_.RunUntilIdle();
168 170
169 EXPECT_EQ(HTTP_NOT_FOUND, error); 171 EXPECT_EQ(HTTP_NOT_FOUND, error);
170 } 172 }
171 173
174 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
175 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
176
177 base::ScopedTempDir temp_dir;
178 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
179
180 const GURL kContentUrl("https://file_content_url/");
181 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt");
182 GDataErrorCode error = GDATA_OTHER_ERROR;
183 FilePath output_file_path;
184 fake_service_.DownloadFile(
185 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
186 kOutputFilePath,
187 kContentUrl,
188 base::Bind(&test_util::CopyResultsFromDownloadActionCallback,
189 &error,
190 &output_file_path),
191 GetContentCallback());
192 message_loop_.RunUntilIdle();
193
194 EXPECT_EQ(HTTP_SUCCESS, error);
195 EXPECT_EQ(output_file_path, kOutputFilePath);
196 std::string content;
197 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
198 EXPECT_EQ(kContentUrl.spec(), content);
199 }
200
201 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
202 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
203
204 base::ScopedTempDir temp_dir;
205 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
206
207 const GURL kContentUrl("https://non_existing_content_url/");
208 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt");
209 GDataErrorCode error = GDATA_OTHER_ERROR;
210 FilePath output_file_path;
211 fake_service_.DownloadFile(
212 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
213 kOutputFilePath,
214 kContentUrl,
215 base::Bind(&test_util::CopyResultsFromDownloadActionCallback,
216 &error,
217 &output_file_path),
218 GetContentCallback());
219 message_loop_.RunUntilIdle();
220
221 EXPECT_EQ(HTTP_NOT_FOUND, error);
222 }
223
172 TEST_F(FakeDriveServiceTest, CopyHostedDocument_ExistingHostedDocument) { 224 TEST_F(FakeDriveServiceTest, CopyHostedDocument_ExistingHostedDocument) {
173 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); 225 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
174 226
175 const std::string kResourceId = "document:5_document_resource_id"; 227 const std::string kResourceId = "document:5_document_resource_id";
176 GDataErrorCode error = GDATA_OTHER_ERROR; 228 GDataErrorCode error = GDATA_OTHER_ERROR;
177 scoped_ptr<ResourceEntry> resource_entry; 229 scoped_ptr<ResourceEntry> resource_entry;
178 fake_service_.CopyHostedDocument( 230 fake_service_.CopyHostedDocument(
179 kResourceId, 231 kResourceId,
180 FILE_PATH_LITERAL("new name"), 232 FILE_PATH_LITERAL("new name"),
181 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, 233 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, 513 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
462 &error, 514 &error,
463 &resource_entry)); 515 &resource_entry));
464 message_loop_.RunUntilIdle(); 516 message_loop_.RunUntilIdle();
465 517
466 EXPECT_EQ(HTTP_NOT_FOUND, error); 518 EXPECT_EQ(HTTP_NOT_FOUND, error);
467 EXPECT_FALSE(resource_entry); 519 EXPECT_FALSE(resource_entry);
468 } 520 }
469 521
470 } // namespace google_apis 522 } // namespace google_apis
OLDNEW
« 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