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

Side by Side Diff: chrome/browser/chromeos/drive/drive_scheduler_unittest.cc

Issue 11142036: Add Move operation to the the scheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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/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
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, NULL, mock_remove_operation_); 79 drive_operations_.InitForTesting(NULL,
80 mock_move_operation_,
81 mock_remove_operation_);
67 scheduler_.reset(new DriveScheduler(profile_.get(), 82 scheduler_.reset(new DriveScheduler(profile_.get(),
68 &drive_operations_)); 83 &drive_operations_));
69 84
70 scheduler_->Initialize(); 85 scheduler_->Initialize();
71 scheduler_->SetDisableThrottling(true); 86 scheduler_->SetDisableThrottling(true);
72 } 87 }
73 88
74 virtual void TearDown() OVERRIDE { 89 virtual void TearDown() OVERRIDE {
75 // The scheduler should be deleted before NetworkLibrary, as it 90 // The scheduler should be deleted before NetworkLibrary, as it
76 // registers itself as observer of NetworkLibrary. 91 // registers itself as observer of NetworkLibrary.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 126 }
112 127
113 protected: 128 protected:
114 MessageLoopForUI message_loop_; 129 MessageLoopForUI message_loop_;
115 content::TestBrowserThread ui_thread_; 130 content::TestBrowserThread ui_thread_;
116 scoped_ptr<TestingProfile> profile_; 131 scoped_ptr<TestingProfile> profile_;
117 scoped_ptr<DriveScheduler> scheduler_; 132 scoped_ptr<DriveScheduler> scheduler_;
118 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; 133 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
119 134
120 file_system::DriveOperations drive_operations_; 135 file_system::DriveOperations drive_operations_;
136 StrictMock<MockMoveOperation>* mock_move_operation_;
121 StrictMock<MockRemoveOperation>* mock_remove_operation_; 137 StrictMock<MockRemoveOperation>* mock_remove_operation_;
122 }; 138 };
123 139
140 TEST_F(DriveSchedulerTest, MoveFile) {
141 ConnectToWifi();
142
143 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
144 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt"));
145 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _))
146 .WillOnce(MockRemove(DRIVE_FILE_OK));
147
148 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
149 scheduler_->Move(
150 file_in_root, dest_file,
151 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
152 google_apis::test_util::RunBlockingPoolTask();
153
154 ASSERT_EQ(DRIVE_FILE_OK, error);
155 }
156
157 TEST_F(DriveSchedulerTest, MoveFileRetry) {
158 ConnectToWifi();
159
160 // This will fail once with a throttled message. It tests that the scheduler
161 // will retry in this case.
162 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
163 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt"));
164 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _))
165 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED))
166 .WillOnce(MockRemove(DRIVE_FILE_OK));
167
168 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
169 scheduler_->Move(
170 file_in_root, dest_file,
171 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
172 google_apis::test_util::RunBlockingPoolTask();
173
174 ASSERT_EQ(DRIVE_FILE_OK, error);
175 }
176
124 TEST_F(DriveSchedulerTest, RemoveFile) { 177 TEST_F(DriveSchedulerTest, RemoveFile) {
125 ConnectToWifi(); 178 ConnectToWifi();
126 179
127 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 180 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
128 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _)) 181 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _))
129 .WillOnce(MockRemove(DRIVE_FILE_OK)); 182 .WillOnce(MockRemove(DRIVE_FILE_OK));
130 183
131 DriveFileError error; 184 DriveFileError error;
132 scheduler_->Remove( 185 scheduler_->Remove(
133 file_in_root, false, 186 file_in_root, false,
134 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 187 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
135 google_apis::test_util::RunBlockingPoolTask(); 188 google_apis::test_util::RunBlockingPoolTask();
136 189
137 ASSERT_EQ(DRIVE_FILE_OK, error); 190 ASSERT_EQ(DRIVE_FILE_OK, error);
138 } 191 }
139 192
140 TEST_F(DriveSchedulerTest, RemoveFileRetry) { 193 TEST_F(DriveSchedulerTest, RemoveFileRetry) {
141 ConnectToWifi(); 194 ConnectToWifi();
142 195
196 // This will fail once with a throttled message. It tests that the scheduler
197 // will retry in this case.
143 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 198 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
144 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _)) 199 EXPECT_CALL(*mock_remove_operation_, Remove(file_in_root, _, _))
145 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED)) 200 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED))
146 .WillOnce(MockRemove(DRIVE_FILE_OK)); 201 .WillOnce(MockRemove(DRIVE_FILE_OK));
147 202
148 DriveFileError error; 203 DriveFileError error;
149 scheduler_->Remove( 204 scheduler_->Remove(
150 file_in_root, false, 205 file_in_root, false,
151 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 206 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
152 google_apis::test_util::RunBlockingPoolTask(); 207 google_apis::test_util::RunBlockingPoolTask();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 299
245 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 300 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
246 DriveFileError error; 301 DriveFileError error;
247 scheduler_->Remove( 302 scheduler_->Remove(
248 file_in_root, false, 303 file_in_root, false,
249 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 304 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
250 google_apis::test_util::RunBlockingPoolTask(); 305 google_apis::test_util::RunBlockingPoolTask();
251 } 306 }
252 307
253 } // namespace drive 308 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_scheduler.cc ('k') | chrome/browser/chromeos/drive/file_system/move_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698