| OLD | NEW |
| 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/drive/drive_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_test_util.h" | 9 #include "chrome/browser/chromeos/drive/drive_test_util.h" |
| 10 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" | 10 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" | 12 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
| 20 using ::testing::DoAll; | 21 using ::testing::DoAll; |
| 21 using ::testing::Return; | 22 using ::testing::Return; |
| 22 using ::testing::StrictMock; | 23 using ::testing::StrictMock; |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 | 25 |
| 25 namespace drive { | 26 namespace drive { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier { | 30 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier { |
| 30 public: | 31 public: |
| 31 MOCK_CONST_METHOD0(GetCurrentConnectionType, | 32 MOCK_CONST_METHOD0(GetCurrentConnectionType, |
| 32 net::NetworkChangeNotifier::ConnectionType()); | 33 net::NetworkChangeNotifier::ConnectionType()); |
| 33 }; | 34 }; |
| 34 | 35 |
| 36 class MockMoveOperation : public file_system::MoveOperation { |
| 37 public: |
| 38 MockMoveOperation() |
| 39 : file_system::MoveOperation(NULL, NULL, NULL) { |
| 40 } |
| 41 |
| 42 MOCK_METHOD3(Move, void(const FilePath& src_file_path, |
| 43 const FilePath& dest_file_path, |
| 44 const FileOperationCallback& callback)); |
| 45 }; |
| 46 |
| 35 class MockRemoveOperation : public file_system::RemoveOperation { | 47 class MockRemoveOperation : public file_system::RemoveOperation { |
| 36 public: | 48 public: |
| 37 MockRemoveOperation() | 49 MockRemoveOperation() |
| 38 : file_system::RemoveOperation(NULL, NULL, NULL, NULL) { | 50 : file_system::RemoveOperation(NULL, NULL, NULL, NULL) { |
| 39 } | 51 } |
| 40 | 52 |
| 41 MOCK_METHOD3(Remove, void(const FilePath& file_path, | 53 MOCK_METHOD3(Remove, void(const FilePath& file_path, |
| 42 bool is_recursive, | 54 bool is_recursive, |
| 43 const FileOperationCallback& callback)); | 55 const FileOperationCallback& callback)); |
| 44 }; | 56 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 class DriveSchedulerTest : public testing::Test { | 67 class DriveSchedulerTest : public testing::Test { |
| 56 public: | 68 public: |
| 57 DriveSchedulerTest() | 69 DriveSchedulerTest() |
| 58 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 70 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 59 profile_(new TestingProfile) { | 71 profile_(new TestingProfile) { |
| 60 } | 72 } |
| 61 | 73 |
| 62 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
| 63 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); | 75 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); |
| 64 | 76 |
| 77 mock_move_operation_ = new StrictMock<MockMoveOperation>(); |
| 65 mock_remove_operation_ = new StrictMock<MockRemoveOperation>(); | 78 mock_remove_operation_ = new StrictMock<MockRemoveOperation>(); |
| 66 drive_operations_.InitForTesting(NULL, mock_remove_operation_); | 79 drive_operations_.InitForTesting(mock_move_operation_, |
| 80 mock_remove_operation_); |
| 67 scheduler_.reset(new DriveScheduler(profile_.get(), | 81 scheduler_.reset(new DriveScheduler(profile_.get(), |
| 68 &drive_operations_)); | 82 &drive_operations_)); |
| 69 | 83 |
| 70 scheduler_->Initialize(); | 84 scheduler_->Initialize(); |
| 71 scheduler_->SetDisableThrottling(true); | 85 scheduler_->SetDisableThrottling(true); |
| 72 } | 86 } |
| 73 | 87 |
| 74 virtual void TearDown() OVERRIDE { | 88 virtual void TearDown() OVERRIDE { |
| 75 // The scheduler should be deleted before NetworkLibrary, as it | 89 // The scheduler should be deleted before NetworkLibrary, as it |
| 76 // registers itself as observer of NetworkLibrary. | 90 // registers itself as observer of NetworkLibrary. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 125 } |
| 112 | 126 |
| 113 protected: | 127 protected: |
| 114 MessageLoopForUI message_loop_; | 128 MessageLoopForUI message_loop_; |
| 115 content::TestBrowserThread ui_thread_; | 129 content::TestBrowserThread ui_thread_; |
| 116 scoped_ptr<TestingProfile> profile_; | 130 scoped_ptr<TestingProfile> profile_; |
| 117 scoped_ptr<DriveScheduler> scheduler_; | 131 scoped_ptr<DriveScheduler> scheduler_; |
| 118 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; | 132 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; |
| 119 | 133 |
| 120 file_system::DriveOperations drive_operations_; | 134 file_system::DriveOperations drive_operations_; |
| 135 StrictMock<MockMoveOperation>* mock_move_operation_; |
| 121 StrictMock<MockRemoveOperation>* mock_remove_operation_; | 136 StrictMock<MockRemoveOperation>* mock_remove_operation_; |
| 122 }; | 137 }; |
| 123 | 138 |
| 139 TEST_F(DriveSchedulerTest, MoveFile) { |
| 140 ConnectToWifi(); |
| 141 |
| 142 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 143 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 144 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _)) |
| 145 .WillOnce(MockRemove(DRIVE_FILE_OK)); |
| 146 |
| 147 DriveFileError error; |
| 148 scheduler_->Move( |
| 149 file_in_root, dest_file, |
| 150 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
| 151 gdata::test_util::RunBlockingPoolTask(); |
| 152 |
| 153 ASSERT_EQ(DRIVE_FILE_OK, error); |
| 154 } |
| 155 |
| 156 TEST_F(DriveSchedulerTest, MoveFileRetry) { |
| 157 ConnectToWifi(); |
| 158 |
| 159 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 160 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 161 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _)) |
| 162 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED)) |
| 163 .WillOnce(MockRemove(DRIVE_FILE_OK)); |
| 164 |
| 165 DriveFileError error; |
| 166 scheduler_->Move( |
| 167 file_in_root, dest_file, |
| 168 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
| 169 gdata::test_util::RunBlockingPoolTask(); |
| 170 |
| 171 ASSERT_EQ(DRIVE_FILE_OK, error); |
| 172 } |
| 173 |
| 124 TEST_F(DriveSchedulerTest, RemoveFile) { | 174 TEST_F(DriveSchedulerTest, RemoveFile) { |
| 125 ConnectToWifi(); | 175 ConnectToWifi(); |
| 126 | 176 |
| 127 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 177 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 128 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _)) | 178 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _)) |
| 129 .WillOnce(MockRemove(DRIVE_FILE_OK)); | 179 .WillOnce(MockRemove(DRIVE_FILE_OK)); |
| 130 | 180 |
| 131 DriveFileError error; | 181 DriveFileError error; |
| 132 scheduler_->Remove( | 182 scheduler_->Remove( |
| 133 file_in_root, false, | 183 file_in_root, false, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 294 |
| 245 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); | 295 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 246 DriveFileError error; | 296 DriveFileError error; |
| 247 scheduler_->Remove( | 297 scheduler_->Remove( |
| 248 file_in_root, false, | 298 file_in_root, false, |
| 249 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); | 299 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
| 250 gdata::test_util::RunBlockingPoolTask(); | 300 gdata::test_util::RunBlockingPoolTask(); |
| 251 } | 301 } |
| 252 | 302 |
| 253 } // namespace drive | 303 } // namespace drive |
| OLD | NEW |