| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/sync_file_system/drive/fake_api_util.h" | 8 #include "chrome/browser/sync_file_system/drive/fake_api_util.h" |
| 9 #include "chrome/browser/sync_file_system/drive_metadata_store.h" | 9 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
| 10 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" | 10 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | 14 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
| 15 | 15 |
| 16 namespace sync_file_system { | 16 namespace sync_file_system { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char* kServiceName = DriveFileSyncService::kServiceName; | |
| 21 const char kSyncRootResourceId[] = "folder:sync_root_resource_id"; | 20 const char kSyncRootResourceId[] = "folder:sync_root_resource_id"; |
| 22 | 21 |
| 23 void DidInitialize(bool* done, SyncStatusCode status, bool created) { | 22 void DidInitialize(bool* done, SyncStatusCode status, bool created) { |
| 24 EXPECT_EQ(SYNC_STATUS_OK, status); | 23 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 25 *done = true; | 24 *done = true; |
| 26 } | 25 } |
| 27 | 26 |
| 28 void ExpectEqStatus(bool* done, | 27 void ExpectEqStatus(bool* done, |
| 29 SyncStatusCode expected, | 28 SyncStatusCode expected, |
| 30 SyncStatusCode actual) { | 29 SyncStatusCode actual) { |
| 31 EXPECT_FALSE(*done); | 30 EXPECT_FALSE(*done); |
| 32 *done = true; | 31 *done = true; |
| 33 EXPECT_EQ(expected, actual); | 32 EXPECT_EQ(expected, actual); |
| 34 } | 33 } |
| 35 | 34 |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 class DriveFileSyncServiceTest : public testing::Test { | 37 class DriveFileSyncServiceTest : public testing::Test { |
| 39 public: | 38 public: |
| 40 DriveFileSyncServiceTest() | 39 DriveFileSyncServiceTest() |
| 41 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 40 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 42 file_thread_(content::BrowserThread::FILE, &message_loop_), | 41 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 43 fake_api_util_(NULL), | 42 fake_api_util_(NULL), |
| 44 metadata_store_(NULL), | 43 metadata_store_(NULL), |
| 45 sync_service_(NULL) {} | 44 sync_service_(NULL) {} |
| 46 | 45 |
| 47 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
| 48 ASSERT_TRUE(RegisterSyncableFileSystem(kServiceName)); | 47 RegisterSyncableFileSystem(); |
| 49 fake_api_util_ = new drive::FakeAPIUtil; | 48 fake_api_util_ = new drive::FakeAPIUtil; |
| 50 | 49 |
| 51 ASSERT_TRUE(scoped_base_dir_.CreateUniqueTempDir()); | 50 ASSERT_TRUE(scoped_base_dir_.CreateUniqueTempDir()); |
| 52 base_dir_ = scoped_base_dir_.path(); | 51 base_dir_ = scoped_base_dir_.path(); |
| 53 metadata_store_ = new DriveMetadataStore( | 52 metadata_store_ = new DriveMetadataStore( |
| 54 base_dir_, | 53 base_dir_, |
| 55 base::MessageLoopProxy::current()); | 54 base::MessageLoopProxy::current()); |
| 56 bool done = false; | 55 bool done = false; |
| 57 metadata_store_->Initialize(base::Bind(&DidInitialize, &done)); | 56 metadata_store_->Initialize(base::Bind(&DidInitialize, &done)); |
| 58 message_loop_.RunUntilIdle(); | 57 message_loop_.RunUntilIdle(); |
| 59 metadata_store_->SetSyncRootDirectory(kSyncRootResourceId); | 58 metadata_store_->SetSyncRootDirectory(kSyncRootResourceId); |
| 60 EXPECT_TRUE(done); | 59 EXPECT_TRUE(done); |
| 61 | 60 |
| 62 sync_service_ = DriveFileSyncService::CreateForTesting( | 61 sync_service_ = DriveFileSyncService::CreateForTesting( |
| 63 &profile_, | 62 &profile_, |
| 64 base_dir_, | 63 base_dir_, |
| 65 scoped_ptr<drive::APIUtilInterface>(fake_api_util_), | 64 scoped_ptr<drive::APIUtilInterface>(fake_api_util_), |
| 66 scoped_ptr<DriveMetadataStore>(metadata_store_)).Pass(); | 65 scoped_ptr<DriveMetadataStore>(metadata_store_)).Pass(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 virtual void TearDown() OVERRIDE { | 68 virtual void TearDown() OVERRIDE { |
| 70 metadata_store_ = NULL; | 69 metadata_store_ = NULL; |
| 71 fake_api_util_ = NULL; | 70 fake_api_util_ = NULL; |
| 72 sync_service_.reset(); | 71 sync_service_.reset(); |
| 73 message_loop_.RunUntilIdle(); | 72 message_loop_.RunUntilIdle(); |
| 74 | 73 |
| 75 base_dir_ = base::FilePath(); | 74 base_dir_ = base::FilePath(); |
| 76 ASSERT_TRUE(RevokeSyncableFileSystem(kServiceName)); | 75 RevokeSyncableFileSystem(); |
| 77 } | 76 } |
| 78 | 77 |
| 79 virtual ~DriveFileSyncServiceTest() { | 78 virtual ~DriveFileSyncServiceTest() { |
| 80 } | 79 } |
| 81 | 80 |
| 82 protected: | 81 protected: |
| 83 base::MessageLoop* message_loop() { return &message_loop_; } | 82 base::MessageLoop* message_loop() { return &message_loop_; } |
| 84 drive::FakeAPIUtil* fake_api_util() { return fake_api_util_; } | 83 drive::FakeAPIUtil* fake_api_util() { return fake_api_util_; } |
| 85 DriveMetadataStore* metadata_store() { return metadata_store_; } | 84 DriveMetadataStore* metadata_store() { return metadata_store_; } |
| 86 DriveFileSyncService* sync_service() { return sync_service_.get(); } | 85 DriveFileSyncService* sync_service() { return sync_service_.get(); } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 124 base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
| 126 message_loop()->RunUntilIdle(); | 125 message_loop()->RunUntilIdle(); |
| 127 EXPECT_TRUE(done); | 126 EXPECT_TRUE(done); |
| 128 | 127 |
| 129 // Assert the App's origin folder was marked as deleted. | 128 // Assert the App's origin folder was marked as deleted. |
| 130 EXPECT_TRUE(fake_api_util()->remote_resources().find(origin_dir_resource_id) | 129 EXPECT_TRUE(fake_api_util()->remote_resources().find(origin_dir_resource_id) |
| 131 ->second.deleted); | 130 ->second.deleted); |
| 132 } | 131 } |
| 133 | 132 |
| 134 } // namespace sync_file_system | 133 } // namespace sync_file_system |
| OLD | NEW |