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

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

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 months 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/remove_operation.h" 10 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::AnyNumber; 18 using ::testing::AnyNumber;
19 using ::testing::DoAll; 19 using ::testing::DoAll;
20 using ::testing::Return; 20 using ::testing::Return;
21 using ::testing::StrictMock; 21 using ::testing::StrictMock;
22 using ::testing::_; 22 using ::testing::_;
23 23
24 namespace gdata { 24 namespace drive {
25 25
26 namespace { 26 namespace {
27 27
28 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier { 28 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier {
29 public: 29 public:
30 MOCK_CONST_METHOD0(GetCurrentConnectionType, 30 MOCK_CONST_METHOD0(GetCurrentConnectionType,
31 net::NetworkChangeNotifier::ConnectionType()); 31 net::NetworkChangeNotifier::ConnectionType());
32 }; 32 };
33 33
34 class MockRemoveOperation : public file_system::RemoveOperation { 34 class MockRemoveOperation : public file_system::RemoveOperation {
(...skipping 28 matching lines...) Expand all
63 &mock_remove_operation_)); 63 &mock_remove_operation_));
64 64
65 scheduler_->Initialize(); 65 scheduler_->Initialize();
66 scheduler_->SetDisableThrottling(true); 66 scheduler_->SetDisableThrottling(true);
67 } 67 }
68 68
69 virtual void TearDown() OVERRIDE { 69 virtual void TearDown() OVERRIDE {
70 // The scheduler should be deleted before NetworkLibrary, as it 70 // The scheduler should be deleted before NetworkLibrary, as it
71 // registers itself as observer of NetworkLibrary. 71 // registers itself as observer of NetworkLibrary.
72 scheduler_.reset(); 72 scheduler_.reset();
73 test_util::RunBlockingPoolTask(); 73 gdata::test_util::RunBlockingPoolTask();
74 mock_network_change_notifier_.reset(); 74 mock_network_change_notifier_.reset();
75 } 75 }
76 76
77 // Sets up MockNetworkChangeNotifier as if it's connected to a network with 77 // Sets up MockNetworkChangeNotifier as if it's connected to a network with
78 // the specified connection type. 78 // the specified connection type.
79 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) { 79 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) {
80 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType()) 80 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType())
81 .WillRepeatedly(Return(type)); 81 .WillRepeatedly(Return(type));
82 // Notify the sync client that the network is changed. This is done via 82 // Notify the sync client that the network is changed. This is done via
83 // NetworkChangeNotifier in production, but here, we simulate the behavior 83 // NetworkChangeNotifier in production, but here, we simulate the behavior
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 ConnectToWifi(); 119 ConnectToWifi();
120 120
121 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 121 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
122 EXPECT_CALL(mock_remove_operation_, Remove(file_in_root, _, _)) 122 EXPECT_CALL(mock_remove_operation_, Remove(file_in_root, _, _))
123 .WillOnce(MockRemove(DRIVE_FILE_OK)); 123 .WillOnce(MockRemove(DRIVE_FILE_OK));
124 124
125 DriveFileError error; 125 DriveFileError error;
126 scheduler_->Remove( 126 scheduler_->Remove(
127 file_in_root, false, 127 file_in_root, false,
128 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 128 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
129 test_util::RunBlockingPoolTask(); 129 gdata::test_util::RunBlockingPoolTask();
130 130
131 ASSERT_EQ(DRIVE_FILE_OK, error); 131 ASSERT_EQ(DRIVE_FILE_OK, error);
132 } 132 }
133 133
134 TEST_F(DriveSchedulerTest, RemoveFileRetry) { 134 TEST_F(DriveSchedulerTest, RemoveFileRetry) {
135 ConnectToWifi(); 135 ConnectToWifi();
136 136
137 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 137 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
138 EXPECT_CALL(mock_remove_operation_, Remove(file_in_root, _, _)) 138 EXPECT_CALL(mock_remove_operation_, Remove(file_in_root, _, _))
139 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED)) 139 .WillOnce(MockRemove(DRIVE_FILE_ERROR_THROTTLED))
140 .WillOnce(MockRemove(DRIVE_FILE_OK)); 140 .WillOnce(MockRemove(DRIVE_FILE_OK));
141 141
142 DriveFileError error; 142 DriveFileError error;
143 scheduler_->Remove( 143 scheduler_->Remove(
144 file_in_root, false, 144 file_in_root, false,
145 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 145 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
146 test_util::RunBlockingPoolTask(); 146 gdata::test_util::RunBlockingPoolTask();
147 147
148 ASSERT_EQ(DRIVE_FILE_OK, error); 148 ASSERT_EQ(DRIVE_FILE_OK, error);
149 } 149 }
150 150
151 TEST_F(DriveSchedulerTest, QueueOperation_Offline) { 151 TEST_F(DriveSchedulerTest, QueueOperation_Offline) {
152 ConnectToNone(); 152 ConnectToNone();
153 153
154 // This file will not be removed, as network is not connected. 154 // This file will not be removed, as network is not connected.
155 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0); 155 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0);
156 156
157 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 157 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
158 DriveFileError error; 158 DriveFileError error;
159 scheduler_->Remove( 159 scheduler_->Remove(
160 file_in_root, false, 160 file_in_root, false,
161 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 161 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
162 test_util::RunBlockingPoolTask(); 162 gdata::test_util::RunBlockingPoolTask();
163 } 163 }
164 164
165 TEST_F(DriveSchedulerTest, QueueOperation_CelluarDisabled) { 165 TEST_F(DriveSchedulerTest, QueueOperation_CelluarDisabled) {
166 ConnectToCellular(); 166 ConnectToCellular();
167 167
168 // This file will not be removed, as fetching over cellular network is 168 // This file will not be removed, as fetching over cellular network is
169 // disabled by default. 169 // disabled by default.
170 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0); 170 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0);
171 171
172 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 172 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
173 DriveFileError error; 173 DriveFileError error;
174 scheduler_->Remove( 174 scheduler_->Remove(
175 file_in_root, false, 175 file_in_root, false,
176 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 176 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
177 test_util::RunBlockingPoolTask(); 177 gdata::test_util::RunBlockingPoolTask();
178 } 178 }
179 179
180 TEST_F(DriveSchedulerTest, QueueOperation_CelluarEnabled) { 180 TEST_F(DriveSchedulerTest, QueueOperation_CelluarEnabled) {
181 // Enable fetching over cellular network. 181 // Enable fetching over cellular network.
182 profile_->GetPrefs()->SetBoolean(prefs::kDisableGDataOverCellular, false); 182 profile_->GetPrefs()->SetBoolean(prefs::kDisableGDataOverCellular, false);
183 183
184 ConnectToCellular(); 184 ConnectToCellular();
185 185
186 // This file will be removed, as syncing over cellular network is explicitly 186 // This file will be removed, as syncing over cellular network is explicitly
187 // enabled. 187 // enabled.
188 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(1); 188 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(1);
189 189
190 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 190 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
191 DriveFileError error; 191 DriveFileError error;
192 scheduler_->Remove( 192 scheduler_->Remove(
193 file_in_root, false, 193 file_in_root, false,
194 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 194 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
195 test_util::RunBlockingPoolTask(); 195 gdata::test_util::RunBlockingPoolTask();
196 } 196 }
197 197
198 TEST_F(DriveSchedulerTest, QueueOperation_WimaxDisabled) { 198 TEST_F(DriveSchedulerTest, QueueOperation_WimaxDisabled) {
199 // Then connect to wimax. This will kick off StartSyncLoop(). 199 // Then connect to wimax. This will kick off StartSyncLoop().
200 ConnectToWimax(); 200 ConnectToWimax();
201 201
202 // This file will not be removed, as syncing over wimax network is disabled 202 // This file will not be removed, as syncing over wimax network is disabled
203 // by default. 203 // by default.
204 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0); 204 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0);
205 205
206 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 206 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
207 DriveFileError error; 207 DriveFileError error;
208 scheduler_->Remove( 208 scheduler_->Remove(
209 file_in_root, false, 209 file_in_root, false,
210 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 210 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
211 test_util::RunBlockingPoolTask(); 211 gdata::test_util::RunBlockingPoolTask();
212 } 212 }
213 213
214 TEST_F(DriveSchedulerTest, QueueOperation_CelluarEnabledWithWimax) { 214 TEST_F(DriveSchedulerTest, QueueOperation_CelluarEnabledWithWimax) {
215 // Enable fetching over cellular network. 215 // Enable fetching over cellular network.
216 profile_->GetPrefs()->SetBoolean(prefs::kDisableGDataOverCellular, false); 216 profile_->GetPrefs()->SetBoolean(prefs::kDisableGDataOverCellular, false);
217 217
218 ConnectToWimax(); 218 ConnectToWimax();
219 219
220 // This file will be removed, as syncing over cellular network is explicitly 220 // This file will be removed, as syncing over cellular network is explicitly
221 // enabled. 221 // enabled.
222 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(1); 222 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(1);
223 223
224 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 224 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
225 DriveFileError error; 225 DriveFileError error;
226 scheduler_->Remove( 226 scheduler_->Remove(
227 file_in_root, false, 227 file_in_root, false,
228 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 228 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
229 test_util::RunBlockingPoolTask(); 229 gdata::test_util::RunBlockingPoolTask();
230 } 230 }
231 231
232 TEST_F(DriveSchedulerTest, QueueOperation_DriveDisabled) { 232 TEST_F(DriveSchedulerTest, QueueOperation_DriveDisabled) {
233 // Disable the Drive feature. 233 // Disable the Drive feature.
234 profile_->GetPrefs()->SetBoolean(prefs::kDisableGData, true); 234 profile_->GetPrefs()->SetBoolean(prefs::kDisableGData, true);
235 235
236 // This file will not be removed, as the Drive feature is disabled. 236 // This file will not be removed, as the Drive feature is disabled.
237 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0); 237 EXPECT_CALL(mock_remove_operation_, Remove(_, _, _)).Times(0);
238 238
239 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 239 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
240 DriveFileError error; 240 DriveFileError error;
241 scheduler_->Remove( 241 scheduler_->Remove(
242 file_in_root, false, 242 file_in_root, false,
243 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 243 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
244 test_util::RunBlockingPoolTask(); 244 gdata::test_util::RunBlockingPoolTask();
245 } 245 }
246 246
247 } // namespace gdata 247 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_scheduler.cc ('k') | chrome/browser/chromeos/drive/drive_service_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698