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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_directory_service_unittest.cc

Issue 10836354: Rename GData* to Drive* in gdata.proto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments. Created 8 years, 4 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/chromeos/gdata/gdata_directory_service.h" 5 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 16 #include "chrome/browser/chromeos/gdata/drive.pb.h"
17 #include "chrome/browser/chromeos/gdata/gdata_cache.h" 17 #include "chrome/browser/chromeos/gdata/gdata_cache.h"
18 #include "chrome/browser/chromeos/gdata/gdata_files.h" 18 #include "chrome/browser/chromeos/gdata/gdata_files.h"
19 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 19 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace gdata { 24 namespace gdata {
25 namespace { 25 namespace {
26 26
27 // See gdata.proto for the difference between the two URLs. 27 // See drive.proto for the difference between the two URLs.
28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/";
30 30
31 // Add a directory to |parent| and return that directory. The name and 31 // Add a directory to |parent| and return that directory. The name and
32 // resource_id are determined by the incrementing counter |sequence_id|. 32 // resource_id are determined by the incrementing counter |sequence_id|.
33 GDataDirectory* AddDirectory(GDataDirectory* parent, 33 GDataDirectory* AddDirectory(GDataDirectory* parent,
34 GDataDirectoryService* directory_service, 34 GDataDirectoryService* directory_service,
35 int sequence_id) { 35 int sequence_id) {
36 GDataDirectory* dir = directory_service->CreateGDataDirectory(); 36 GDataDirectory* dir = directory_service->CreateGDataDirectory();
37 const std::string dir_name = "dir" + base::IntToString(sequence_id); 37 const std::string dir_name = "dir" + base::IntToString(sequence_id);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 186
187 // Callback for GDataDirectoryService::InitFromDB. 187 // Callback for GDataDirectoryService::InitFromDB.
188 void InitFromDBCallback(GDataFileError expected_error, 188 void InitFromDBCallback(GDataFileError expected_error,
189 GDataFileError actual_error) { 189 GDataFileError actual_error) {
190 EXPECT_EQ(expected_error, actual_error); 190 EXPECT_EQ(expected_error, actual_error);
191 } 191 }
192 192
193 // Callback for GDataDirectoryService::ReadDirectoryByPath. 193 // Callback for GDataDirectoryService::ReadDirectoryByPath.
194 void ReadDirectoryByPathCallback( 194 void ReadDirectoryByPathCallback(
195 scoped_ptr<GDataEntryProtoVector>* result, 195 scoped_ptr<DriveEntryProtoVector>* result,
196 GDataFileError error, 196 GDataFileError error,
197 scoped_ptr<GDataEntryProtoVector> entries) { 197 scoped_ptr<DriveEntryProtoVector> entries) {
198 EXPECT_EQ(GDATA_FILE_OK, error); 198 EXPECT_EQ(GDATA_FILE_OK, error);
199 *result = entries.Pass(); 199 *result = entries.Pass();
200 } 200 }
201 201
202 } // namespace 202 } // namespace
203 203
204 TEST(GDataDirectoryServiceTest, VersionCheck) { 204 TEST(GDataDirectoryServiceTest, VersionCheck) {
205 // Set up the root directory. 205 // Set up the root directory.
206 GDataRootDirectoryProto proto; 206 DriveRootDirectoryProto proto;
207 GDataEntryProto* mutable_entry = 207 DriveEntryProto* mutable_entry =
208 proto.mutable_gdata_directory()->mutable_gdata_entry(); 208 proto.mutable_gdata_directory()->mutable_gdata_entry();
209 mutable_entry->mutable_file_info()->set_is_directory(true); 209 mutable_entry->mutable_file_info()->set_is_directory(true);
210 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); 210 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId);
211 mutable_entry->set_upload_url(kResumableCreateMediaUrl); 211 mutable_entry->set_upload_url(kResumableCreateMediaUrl);
212 mutable_entry->set_title("drive"); 212 mutable_entry->set_title("drive");
213 213
214 GDataDirectoryService directory_service; 214 GDataDirectoryService directory_service;
215 215
216 std::string serialized_proto; 216 std::string serialized_proto;
217 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); 217 ASSERT_TRUE(proto.SerializeToString(&serialized_proto));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 TEST(GDataDirectoryServiceTest, GetEntryInfoByResourceId) { 318 TEST(GDataDirectoryServiceTest, GetEntryInfoByResourceId) {
319 MessageLoopForUI message_loop; 319 MessageLoopForUI message_loop;
320 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 320 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
321 &message_loop); 321 &message_loop);
322 GDataDirectoryService directory_service; 322 GDataDirectoryService directory_service;
323 InitDirectoryService(&directory_service); 323 InitDirectoryService(&directory_service);
324 324
325 // Confirm that an existing file is found. 325 // Confirm that an existing file is found.
326 GDataFileError error = GDATA_FILE_ERROR_FAILED; 326 GDataFileError error = GDATA_FILE_ERROR_FAILED;
327 FilePath drive_file_path; 327 FilePath drive_file_path;
328 scoped_ptr<GDataEntryProto> entry_proto; 328 scoped_ptr<DriveEntryProto> entry_proto;
329 directory_service.GetEntryInfoByResourceId( 329 directory_service.GetEntryInfoByResourceId(
330 "file_resource_id:file4", 330 "file_resource_id:file4",
331 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, 331 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback,
332 &error, &drive_file_path, &entry_proto)); 332 &error, &drive_file_path, &entry_proto));
333 test_util::RunBlockingPoolTask(); 333 test_util::RunBlockingPoolTask();
334 EXPECT_EQ(GDATA_FILE_OK, error); 334 EXPECT_EQ(GDATA_FILE_OK, error);
335 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path); 335 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), drive_file_path);
336 ASSERT_TRUE(entry_proto.get()); 336 ASSERT_TRUE(entry_proto.get());
337 EXPECT_EQ("file4", entry_proto->base_name()); 337 EXPECT_EQ("file4", entry_proto->base_name());
338 338
(...skipping 11 matching lines...) Expand all
350 350
351 TEST(GDataDirectoryServiceTest, GetEntryInfoByPath) { 351 TEST(GDataDirectoryServiceTest, GetEntryInfoByPath) {
352 MessageLoopForUI message_loop; 352 MessageLoopForUI message_loop;
353 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 353 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
354 &message_loop); 354 &message_loop);
355 GDataDirectoryService directory_service; 355 GDataDirectoryService directory_service;
356 InitDirectoryService(&directory_service); 356 InitDirectoryService(&directory_service);
357 357
358 // Confirm that an existing file is found. 358 // Confirm that an existing file is found.
359 GDataFileError error = GDATA_FILE_ERROR_FAILED; 359 GDataFileError error = GDATA_FILE_ERROR_FAILED;
360 scoped_ptr<GDataEntryProto> entry_proto; 360 scoped_ptr<DriveEntryProto> entry_proto;
361 directory_service.GetEntryInfoByPath( 361 directory_service.GetEntryInfoByPath(
362 FilePath::FromUTF8Unsafe("drive/dir1/file4"), 362 FilePath::FromUTF8Unsafe("drive/dir1/file4"),
363 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback, 363 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
364 &error, &entry_proto)); 364 &error, &entry_proto));
365 test_util::RunBlockingPoolTask(); 365 test_util::RunBlockingPoolTask();
366 EXPECT_EQ(GDATA_FILE_OK, error); 366 EXPECT_EQ(GDATA_FILE_OK, error);
367 ASSERT_TRUE(entry_proto.get()); 367 ASSERT_TRUE(entry_proto.get());
368 EXPECT_EQ("file4", entry_proto->base_name()); 368 EXPECT_EQ("file4", entry_proto->base_name());
369 369
370 // Confirm that a non existing file is not found. 370 // Confirm that a non existing file is not found.
(...skipping 10 matching lines...) Expand all
381 381
382 TEST(GDataDirectoryServiceTest, ReadDirectoryByPath) { 382 TEST(GDataDirectoryServiceTest, ReadDirectoryByPath) {
383 MessageLoopForUI message_loop; 383 MessageLoopForUI message_loop;
384 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 384 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
385 &message_loop); 385 &message_loop);
386 GDataDirectoryService directory_service; 386 GDataDirectoryService directory_service;
387 InitDirectoryService(&directory_service); 387 InitDirectoryService(&directory_service);
388 388
389 // Confirm that an existing directory is found. 389 // Confirm that an existing directory is found.
390 GDataFileError error = GDATA_FILE_ERROR_FAILED; 390 GDataFileError error = GDATA_FILE_ERROR_FAILED;
391 scoped_ptr<GDataEntryProtoVector> entries; 391 scoped_ptr<DriveEntryProtoVector> entries;
392 directory_service.ReadDirectoryByPath( 392 directory_service.ReadDirectoryByPath(
393 FilePath::FromUTF8Unsafe("drive/dir1"), 393 FilePath::FromUTF8Unsafe("drive/dir1"),
394 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, 394 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback,
395 &error, &entries)); 395 &error, &entries));
396 test_util::RunBlockingPoolTask(); 396 test_util::RunBlockingPoolTask();
397 EXPECT_EQ(GDATA_FILE_OK, error); 397 EXPECT_EQ(GDATA_FILE_OK, error);
398 ASSERT_TRUE(entries.get()); 398 ASSERT_TRUE(entries.get());
399 ASSERT_EQ(3U, entries->size()); 399 ASSERT_EQ(3U, entries->size());
400 400
401 // The order is not guaranteed so we should sort the base names. 401 // The order is not guaranteed so we should sort the base names.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 GDataDirectoryService directory_service2; 526 GDataDirectoryService directory_service2;
527 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. 527 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists.
528 directory_service2.InitFromDB(db_path, blocking_task_runner, 528 directory_service2.InitFromDB(db_path, blocking_task_runner,
529 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); 529 base::Bind(&InitFromDBCallback, GDATA_FILE_OK));
530 test_util::RunBlockingPoolTask(); 530 test_util::RunBlockingPoolTask();
531 531
532 VerifyDirectoryService(&directory_service2); 532 VerifyDirectoryService(&directory_service2);
533 } 533 }
534 534
535 } // namespace gdata 535 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_directory_service.cc ('k') | chrome/browser/chromeos/gdata/gdata_download_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698