| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_file_system/drive_backend/sync_worker.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 class MockSyncTask : public ExclusiveTask { | 43 class MockSyncTask : public ExclusiveTask { |
| 44 public: | 44 public: |
| 45 explicit MockSyncTask(bool used_network) { | 45 explicit MockSyncTask(bool used_network) { |
| 46 set_used_network(used_network); | 46 set_used_network(used_network); |
| 47 } | 47 } |
| 48 virtual ~MockSyncTask() {} | 48 virtual ~MockSyncTask() {} |
| 49 | 49 |
| 50 virtual void RunExclusive(const SyncStatusCallback& callback) OVERRIDE { | 50 virtual void RunExclusive(const SyncStatusCallback& callback) override { |
| 51 callback.Run(SYNC_STATUS_OK); | 51 callback.Run(SYNC_STATUS_OK); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(MockSyncTask); | 55 DISALLOW_COPY_AND_ASSIGN(MockSyncTask); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 class MockExtensionService : public TestExtensionService { | 58 class MockExtensionService : public TestExtensionService { |
| 59 public: | 59 public: |
| 60 MockExtensionService() {} | 60 MockExtensionService() {} |
| 61 virtual ~MockExtensionService() {} | 61 virtual ~MockExtensionService() {} |
| 62 | 62 |
| 63 virtual const extensions::ExtensionSet* extensions() const OVERRIDE { | 63 virtual const extensions::ExtensionSet* extensions() const override { |
| 64 return &extensions_; | 64 return &extensions_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void AddExtension(const extensions::Extension* extension) OVERRIDE { | 67 virtual void AddExtension(const extensions::Extension* extension) override { |
| 68 extensions_.Insert(make_scoped_refptr(extension)); | 68 extensions_.Insert(make_scoped_refptr(extension)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual const extensions::Extension* GetInstalledExtension( | 71 virtual const extensions::Extension* GetInstalledExtension( |
| 72 const std::string& extension_id) const OVERRIDE { | 72 const std::string& extension_id) const override { |
| 73 return extensions_.GetByID(extension_id); | 73 return extensions_.GetByID(extension_id); |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual bool IsExtensionEnabled( | 76 virtual bool IsExtensionEnabled( |
| 77 const std::string& extension_id) const OVERRIDE { | 77 const std::string& extension_id) const override { |
| 78 return extensions_.Contains(extension_id) && | 78 return extensions_.Contains(extension_id) && |
| 79 !disabled_extensions_.Contains(extension_id); | 79 !disabled_extensions_.Contains(extension_id); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void UninstallExtension(const std::string& extension_id) { | 82 void UninstallExtension(const std::string& extension_id) { |
| 83 extensions_.Remove(extension_id); | 83 extensions_.Remove(extension_id); |
| 84 disabled_extensions_.Remove(extension_id); | 84 disabled_extensions_.Remove(extension_id); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DisableExtension(const std::string& extension_id) { | 87 void DisableExtension(const std::string& extension_id) { |
| 88 if (!IsExtensionEnabled(extension_id)) | 88 if (!IsExtensionEnabled(extension_id)) |
| 89 return; | 89 return; |
| 90 const extensions::Extension* extension = extensions_.GetByID(extension_id); | 90 const extensions::Extension* extension = extensions_.GetByID(extension_id); |
| 91 disabled_extensions_.Insert(make_scoped_refptr(extension)); | 91 disabled_extensions_.Insert(make_scoped_refptr(extension)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 extensions::ExtensionSet extensions_; | 95 extensions::ExtensionSet extensions_; |
| 96 extensions::ExtensionSet disabled_extensions_; | 96 extensions::ExtensionSet disabled_extensions_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(MockExtensionService); | 98 DISALLOW_COPY_AND_ASSIGN(MockExtensionService); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 class SyncWorkerTest : public testing::Test, | 101 class SyncWorkerTest : public testing::Test, |
| 102 public base::SupportsWeakPtr<SyncWorkerTest> { | 102 public base::SupportsWeakPtr<SyncWorkerTest> { |
| 103 public: | 103 public: |
| 104 SyncWorkerTest() {} | 104 SyncWorkerTest() {} |
| 105 virtual ~SyncWorkerTest() {} | 105 virtual ~SyncWorkerTest() {} |
| 106 | 106 |
| 107 virtual void SetUp() OVERRIDE { | 107 virtual void SetUp() override { |
| 108 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); | 108 ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
| 109 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); | 109 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); |
| 110 | 110 |
| 111 extension_service_.reset(new MockExtensionService); | 111 extension_service_.reset(new MockExtensionService); |
| 112 scoped_ptr<drive::DriveServiceInterface> | 112 scoped_ptr<drive::DriveServiceInterface> |
| 113 fake_drive_service(new drive::FakeDriveService); | 113 fake_drive_service(new drive::FakeDriveService); |
| 114 | 114 |
| 115 scoped_ptr<SyncEngineContext> | 115 scoped_ptr<SyncEngineContext> |
| 116 sync_engine_context(new SyncEngineContext( | 116 sync_engine_context(new SyncEngineContext( |
| 117 fake_drive_service.Pass(), | 117 fake_drive_service.Pass(), |
| 118 nullptr /* drive_uploader */, | 118 nullptr /* drive_uploader */, |
| 119 nullptr /* task_logger */, | 119 nullptr /* task_logger */, |
| 120 base::ThreadTaskRunnerHandle::Get() /* ui_task_runner */, | 120 base::ThreadTaskRunnerHandle::Get() /* ui_task_runner */, |
| 121 base::ThreadTaskRunnerHandle::Get() /* worker_task_runner */)); | 121 base::ThreadTaskRunnerHandle::Get() /* worker_task_runner */)); |
| 122 | 122 |
| 123 sync_worker_.reset(new SyncWorker( | 123 sync_worker_.reset(new SyncWorker( |
| 124 profile_dir_.path(), | 124 profile_dir_.path(), |
| 125 extension_service_->AsWeakPtr(), | 125 extension_service_->AsWeakPtr(), |
| 126 in_memory_env_.get())); | 126 in_memory_env_.get())); |
| 127 sync_worker_->Initialize(sync_engine_context.Pass()); | 127 sync_worker_->Initialize(sync_engine_context.Pass()); |
| 128 | 128 |
| 129 sync_worker_->SetSyncEnabled(true); | 129 sync_worker_->SetSyncEnabled(true); |
| 130 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual void TearDown() OVERRIDE { | 133 virtual void TearDown() override { |
| 134 sync_worker_.reset(); | 134 sync_worker_.reset(); |
| 135 extension_service_.reset(); | 135 extension_service_.reset(); |
| 136 base::RunLoop().RunUntilIdle(); | 136 base::RunLoop().RunUntilIdle(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 MockExtensionService* extension_service() { return extension_service_.get(); } | 139 MockExtensionService* extension_service() { return extension_service_.get(); } |
| 140 SyncWorker* sync_worker() { return sync_worker_.get(); } | 140 SyncWorker* sync_worker() { return sync_worker_.get(); } |
| 141 | 141 |
| 142 void UpdateRegisteredApps() { | 142 void UpdateRegisteredApps() { |
| 143 sync_worker_->UpdateRegisteredApps(); | 143 sync_worker_->UpdateRegisteredApps(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 base::Bind(&SyncWorkerTest::CheckServiceState, | 381 base::Bind(&SyncWorkerTest::CheckServiceState, |
| 382 AsWeakPtr(), | 382 AsWeakPtr(), |
| 383 SYNC_STATUS_OK, | 383 SYNC_STATUS_OK, |
| 384 REMOTE_SERVICE_OK)); | 384 REMOTE_SERVICE_OK)); |
| 385 | 385 |
| 386 base::RunLoop().RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
| 387 } | 387 } |
| 388 | 388 |
| 389 } // namespace drive_backend | 389 } // namespace drive_backend |
| 390 } // namespace sync_file_system | 390 } // namespace sync_file_system |
| OLD | NEW |