operation_test_base.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 7 8#include <set> 9 10#include "base/files/scoped_temp_dir.h" 11#include "chrome/browser/chromeos/drive/drive.pb.h" 12#include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 13#include "chrome/browser/chromeos/drive/test_util.h" 14#include "content/public/test/test_browser_thread_bundle.h" 15#include "testing/gtest/include/gtest/gtest.h" 16 17class TestingProfile; 18 19namespace base { 20class SequencedTaskRunner; 21} // namespace base 22 23namespace google_apis { 24class FakeDriveService; 25} // namespace google_apis 26 27namespace drive { 28 29class FakeFreeDiskSpaceGetter; 30class JobScheduler; 31 32namespace internal { 33class FileCache; 34class ResourceMetadata; 35} // namespace internal 36 37namespace file_system { 38 39// Base fixture class for testing Drive file system operations. It sets up the 40// basic set of Drive internal classes (ResourceMetadata, Cache, etc) on top of 41// FakeDriveService for testing. 42class OperationTestBase : public testing::Test { 43 protected: 44 // OperationObserver that records all the events. 45 class LoggingObserver : public OperationObserver { 46 public: 47 LoggingObserver(); 48 ~LoggingObserver(); 49 50 // OperationObserver overrides. 51 virtual void OnDirectoryChangedByOperation( 52 const base::FilePath& path) OVERRIDE; 53 virtual void OnCacheFileUploadNeededByOperation( 54 const std::string& resource_id) OVERRIDE; 55 56 // Gets the set of changed paths. 57 const std::set<base::FilePath>& get_changed_paths() { 58 return changed_paths_; 59 } 60 61 // Gets the set of upload needed resource IDs. 62 const std::set<std::string>& upload_needed_resource_ids() const { 63 return upload_needed_resource_ids_; 64 } 65 66 private: 67 std::set<base::FilePath> changed_paths_; 68 std::set<std::string> upload_needed_resource_ids_; 69 }; 70 71 OperationTestBase(); 72 virtual ~OperationTestBase(); 73 74 // testing::Test overrides. 75 virtual void SetUp() OVERRIDE; 76 virtual void TearDown() OVERRIDE; 77 78 // Returns the path of the temporary directory for putting test files. 79 base::FilePath temp_dir() const { return temp_dir_.path(); } 80 81 // Synchronously gets the resource entry corresponding to the path from local 82 // ResourceMetadta. 83 FileError GetLocalResourceEntry(const base::FilePath& path, 84 ResourceEntry* entry); 85 86 // Accessors for the components. 87 google_apis::FakeDriveService* fake_service() { 88 return fake_drive_service_.get(); 89 } 90 LoggingObserver* observer() { return &observer_; } 91 JobScheduler* scheduler() { return scheduler_.get(); } 92 base::SequencedTaskRunner* blocking_task_runner() { 93 return blocking_task_runner_.get(); 94 } 95 internal::ResourceMetadata* metadata() { return metadata_.get(); } 96 FakeFreeDiskSpaceGetter* fake_free_disk_space_getter() { 97 return fake_free_disk_space_getter_.get(); 98 } 99 internal::FileCache* cache() { return cache_.get(); } 100 101 private: 102 content::TestBrowserThreadBundle thread_bundle_; 103 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 104 scoped_ptr<TestingProfile> profile_; 105 base::ScopedTempDir temp_dir_; 106 107 LoggingObserver observer_; 108 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 109 scoped_ptr<JobScheduler> scheduler_; 110 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 111 metadata_; 112 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 113 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; 114}; 115 116} // namespace file_system 117} // namespace drive 118 119#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_OPERATION_TEST_BASE_H_ 120