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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10081032: Proper fix for MockGDataSyncClient cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/mock_directory_change_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <errno.h> 5 #include <errno.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/time.h" 21 #include "base/time.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 24 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
25 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 25 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
26 #include "chrome/browser/chromeos/gdata/gdata_parser.h" 26 #include "chrome/browser/chromeos/gdata/gdata_parser.h"
27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
27 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h" 28 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h"
28 #include "chrome/browser/chromeos/gdata/mock_gdata_sync_client.h" 29 #include "chrome/browser/chromeos/gdata/mock_gdata_sync_client.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
30 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
31 #include "content/test/test_browser_thread.h" 32 #include "content/test/test_browser_thread.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 36
36 using ::testing::AnyNumber; 37 using ::testing::AnyNumber;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 }; 126 };
126 127
127 class GDataFileSystemTest : public testing::Test { 128 class GDataFileSystemTest : public testing::Test {
128 protected: 129 protected:
129 GDataFileSystemTest() 130 GDataFileSystemTest()
130 : ui_thread_(content::BrowserThread::UI, &message_loop_), 131 : ui_thread_(content::BrowserThread::UI, &message_loop_),
131 file_thread_(content::BrowserThread::FILE), 132 file_thread_(content::BrowserThread::FILE),
132 io_thread_(content::BrowserThread::IO), 133 io_thread_(content::BrowserThread::IO),
133 file_system_(NULL), 134 file_system_(NULL),
134 mock_doc_service_(NULL), 135 mock_doc_service_(NULL),
135 mock_sync_client_(NULL),
136 num_callback_invocations_(0), 136 num_callback_invocations_(0),
137 expected_error_(base::PLATFORM_FILE_OK), 137 expected_error_(base::PLATFORM_FILE_OK),
138 expected_cache_state_(0), 138 expected_cache_state_(0),
139 expected_sub_dir_type_(GDataRootDirectory::CACHE_TYPE_META), 139 expected_sub_dir_type_(GDataRootDirectory::CACHE_TYPE_META),
140 expect_outgoing_symlink_(false), 140 expect_outgoing_symlink_(false),
141 root_feed_changestamp_(0) { 141 root_feed_changestamp_(0) {
142 } 142 }
143 143
144 virtual void SetUp() OVERRIDE { 144 virtual void SetUp() OVERRIDE {
145 file_thread_.StartIOThread(); 145 file_thread_.StartIOThread();
(...skipping 13 matching lines...) Expand all
159 mock_free_disk_space_checker_ = new MockFreeDiskSpaceGetter; 159 mock_free_disk_space_checker_ = new MockFreeDiskSpaceGetter;
160 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); 160 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_);
161 161
162 ASSERT_FALSE(file_system_); 162 ASSERT_FALSE(file_system_);
163 file_system_ = new GDataFileSystem(profile_.get(), 163 file_system_ = new GDataFileSystem(profile_.get(),
164 mock_doc_service_); 164 mock_doc_service_);
165 file_system_->Initialize(); 165 file_system_->Initialize();
166 166
167 mock_sync_client_.reset(new MockGDataSyncClient); 167 mock_sync_client_.reset(new MockGDataSyncClient);
168 file_system_->AddObserver(mock_sync_client_.get()); 168 file_system_->AddObserver(mock_sync_client_.get());
169
170 mock_directory_observer_.reset(new MockDirectoryChangeObserver);
171 file_system_->AddObserver(mock_directory_observer_.get());
169 } 172 }
170 173
171 virtual void TearDown() OVERRIDE { 174 virtual void TearDown() OVERRIDE {
172 ASSERT_TRUE(file_system_); 175 ASSERT_TRUE(file_system_);
173 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1); 176 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1);
174 delete file_system_; 177 delete file_system_;
175 file_system_ = NULL; 178 file_system_ = NULL;
176 SetFreeDiskSpaceGetterForTesting(NULL); 179 SetFreeDiskSpaceGetterForTesting(NULL);
177 180
178 // Run the remaining tasks on the main thread, so that reply tasks (2nd 181 // Run the remaining tasks on the main thread, so that reply tasks (2nd
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // See also content/browser/browser_thread_imple.cc. 970 // See also content/browser/browser_thread_imple.cc.
968 content::TestBrowserThread ui_thread_; 971 content::TestBrowserThread ui_thread_;
969 content::TestBrowserThread file_thread_; 972 content::TestBrowserThread file_thread_;
970 content::TestBrowserThread io_thread_; 973 content::TestBrowserThread io_thread_;
971 scoped_ptr<TestingProfile> profile_; 974 scoped_ptr<TestingProfile> profile_;
972 scoped_refptr<CallbackHelper> callback_helper_; 975 scoped_refptr<CallbackHelper> callback_helper_;
973 GDataFileSystem* file_system_; 976 GDataFileSystem* file_system_;
974 MockDocumentsService* mock_doc_service_; 977 MockDocumentsService* mock_doc_service_;
975 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_; 978 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_;
976 scoped_ptr<MockGDataSyncClient> mock_sync_client_; 979 scoped_ptr<MockGDataSyncClient> mock_sync_client_;
980 scoped_ptr<MockDirectoryChangeObserver> mock_directory_observer_;
977 981
978 int num_callback_invocations_; 982 int num_callback_invocations_;
979 base::PlatformFileError expected_error_; 983 base::PlatformFileError expected_error_;
980 int expected_cache_state_; 984 int expected_cache_state_;
981 GDataRootDirectory::CacheSubDirectoryType expected_sub_dir_type_; 985 GDataRootDirectory::CacheSubDirectoryType expected_sub_dir_type_;
982 bool expect_outgoing_symlink_; 986 bool expect_outgoing_symlink_;
983 std::string expected_file_extension_; 987 std::string expected_file_extension_;
984 int root_feed_changestamp_; 988 int root_feed_changestamp_;
985 }; 989 };
986 990
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt"))); 1197 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt")));
1194 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))); 1198 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")));
1195 FindAndTestFilePath( 1199 FindAndTestFilePath(
1196 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt"))); 1200 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")));
1197 } 1201 }
1198 1202
1199 TEST_F(GDataFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { 1203 TEST_F(GDataFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) {
1200 int latest_changelog = 0; 1204 int latest_changelog = 0;
1201 LoadRootFeedDocument("root_feed.json"); 1205 LoadRootFeedDocument("root_feed.json");
1202 1206
1203 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1207 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1204 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(2); 1208 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(2);
1205 1209
1206 LoadChangeFeed("delta_file_added_in_root.json", ++latest_changelog); 1210 LoadChangeFeed("delta_file_added_in_root.json", ++latest_changelog);
1207 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL("gdata/Added file.gdoc")))); 1211 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL("gdata/Added file.gdoc"))));
1208 1212
1209 LoadChangeFeed("delta_file_deleted_in_root.json", ++latest_changelog); 1213 LoadChangeFeed("delta_file_deleted_in_root.json", ++latest_changelog);
1210 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL("gdata/Added file.gdoc")))); 1214 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL("gdata/Added file.gdoc"))));
1211 } 1215 }
1212 1216
1213 1217
1214 TEST_F(GDataFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { 1218 TEST_F(GDataFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) {
1215 int latest_changelog = 0; 1219 int latest_changelog = 0;
1216 LoadRootFeedDocument("root_feed.json"); 1220 LoadRootFeedDocument("root_feed.json");
1217 1221
1218 EXPECT_TRUE(FindFile(FilePath( 1222 EXPECT_TRUE(FindFile(FilePath(
1219 FILE_PATH_LITERAL("gdata/Directory 1")))); 1223 FILE_PATH_LITERAL("gdata/Directory 1"))));
1220 1224
1221 // Add file to an existing directory. 1225 // Add file to an existing directory.
1222 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1226 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1223 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1227 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1224 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1228 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1225 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1229 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1226 LoadChangeFeed("delta_file_added_in_directory.json", ++latest_changelog); 1230 LoadChangeFeed("delta_file_added_in_directory.json", ++latest_changelog);
1227 EXPECT_TRUE(FindFile(FilePath( 1231 EXPECT_TRUE(FindFile(FilePath(
1228 FILE_PATH_LITERAL("gdata/Directory 1/Added file.gdoc")))); 1232 FILE_PATH_LITERAL("gdata/Directory 1/Added file.gdoc"))));
1229 1233
1230 // Remove that file from the directory. 1234 // Remove that file from the directory.
1231 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1235 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1232 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1236 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1233 LoadChangeFeed("delta_file_deleted_in_directory.json", ++latest_changelog); 1237 LoadChangeFeed("delta_file_deleted_in_directory.json", ++latest_changelog);
1234 EXPECT_TRUE(FindFile(FilePath( 1238 EXPECT_TRUE(FindFile(FilePath(
1235 FILE_PATH_LITERAL("gdata/Directory 1")))); 1239 FILE_PATH_LITERAL("gdata/Directory 1"))));
1236 EXPECT_FALSE(FindFile(FilePath( 1240 EXPECT_FALSE(FindFile(FilePath(
1237 FILE_PATH_LITERAL("gdata/Directory 1/Added file.gdoc")))); 1241 FILE_PATH_LITERAL("gdata/Directory 1/Added file.gdoc"))));
1238 } 1242 }
1239 1243
1240 TEST_F(GDataFileSystemTest, ChangeFeed_AddFileToNewDirectory) { 1244 TEST_F(GDataFileSystemTest, ChangeFeed_AddFileToNewDirectory) {
1241 int latest_changelog = 0; 1245 int latest_changelog = 0;
1242 LoadRootFeedDocument("root_feed.json"); 1246 LoadRootFeedDocument("root_feed.json");
1243 // Add file to a new directory. 1247 // Add file to a new directory.
1244 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1248 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1245 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1249 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1246 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1250 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1247 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Directory"))))).Times(1); 1251 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Directory"))))).Times(1);
1248 1252
1249 LoadChangeFeed("delta_file_added_in_new_directory.json", ++latest_changelog); 1253 LoadChangeFeed("delta_file_added_in_new_directory.json", ++latest_changelog);
1250 1254
1251 EXPECT_TRUE(FindFile(FilePath( 1255 EXPECT_TRUE(FindFile(FilePath(
1252 FILE_PATH_LITERAL("gdata/New Directory")))); 1256 FILE_PATH_LITERAL("gdata/New Directory"))));
1253 EXPECT_TRUE(FindFile(FilePath( 1257 EXPECT_TRUE(FindFile(FilePath(
1254 FILE_PATH_LITERAL("gdata/New Directory/File in new dir.gdoc")))); 1258 FILE_PATH_LITERAL("gdata/New Directory/File in new dir.gdoc"))));
1255 } 1259 }
1256 1260
1257 TEST_F(GDataFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { 1261 TEST_F(GDataFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) {
1258 int latest_changelog = 0; 1262 int latest_changelog = 0;
1259 LoadRootFeedDocument("root_feed.json"); 1263 LoadRootFeedDocument("root_feed.json");
1260 1264
1261 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1265 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1262 "gdata/Directory 2")))); 1266 "gdata/Directory 2"))));
1263 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1267 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1264 "gdata/Directory 1")))); 1268 "gdata/Directory 1"))));
1265 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1269 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1266 "gdata/Directory 1/SubDirectory File 1.txt")))); 1270 "gdata/Directory 1/SubDirectory File 1.txt"))));
1267 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1271 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1268 "gdata/Directory 1/Sub Directory Folder")))); 1272 "gdata/Directory 1/Sub Directory Folder"))));
1269 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1273 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1270 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 1274 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder"))));
1271 1275
1272 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1276 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1273 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1277 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1274 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1278 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1275 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 2"))))).Times(1); 1279 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 2"))))).Times(1);
1276 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1280 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1277 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 2/Directory 1"))))) 1281 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 2/Directory 1")))))
1278 .Times(1); 1282 .Times(1);
1279 LoadChangeFeed("delta_dir_moved_from_root_to_directory.json", 1283 LoadChangeFeed("delta_dir_moved_from_root_to_directory.json",
1280 ++latest_changelog); 1284 ++latest_changelog);
1281 1285
1282 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1286 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1283 "gdata/Directory 2")))); 1287 "gdata/Directory 2"))));
1284 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL( 1288 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL(
1285 "gdata/Directory 1")))); 1289 "gdata/Directory 1"))));
1286 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1290 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
(...skipping 13 matching lines...) Expand all
1300 1304
1301 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1305 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1302 "gdata/Directory 1")))); 1306 "gdata/Directory 1"))));
1303 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1307 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1304 "gdata/Directory 1/Sub Directory Folder")))); 1308 "gdata/Directory 1/Sub Directory Folder"))));
1305 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1309 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1306 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 1310 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder"))));
1307 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1311 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1308 "gdata/Directory 1/SubDirectory File 1.txt")))); 1312 "gdata/Directory 1/SubDirectory File 1.txt"))));
1309 1313
1310 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1314 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1311 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1315 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1312 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1316 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1313 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1317 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1314 LoadChangeFeed("delta_file_moved_from_directory_to_root.json", 1318 LoadChangeFeed("delta_file_moved_from_directory_to_root.json",
1315 ++latest_changelog); 1319 ++latest_changelog);
1316 1320
1317 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1321 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1318 "gdata/Directory 1")))); 1322 "gdata/Directory 1"))));
1319 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1323 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1320 "gdata/Directory 1/Sub Directory Folder")))); 1324 "gdata/Directory 1/Sub Directory Folder"))));
1321 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1325 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1322 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 1326 "gdata/Directory 1/Sub Directory Folder/Sub Sub Directory Folder"))));
1323 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL( 1327 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL(
1324 "gdata/Directory 1/SubDirectory File 1.txt")))); 1328 "gdata/Directory 1/SubDirectory File 1.txt"))));
1325 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1329 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1326 "gdata/SubDirectory File 1.txt")))); 1330 "gdata/SubDirectory File 1.txt"))));
1327 } 1331 }
1328 1332
1329 TEST_F(GDataFileSystemTest, ChangeFeed_FileRenamedInDirectory) { 1333 TEST_F(GDataFileSystemTest, ChangeFeed_FileRenamedInDirectory) {
1330 int latest_changelog = 0; 1334 int latest_changelog = 0;
1331 LoadRootFeedDocument("root_feed.json"); 1335 LoadRootFeedDocument("root_feed.json");
1332 1336
1333 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1337 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1334 "gdata/Directory 1")))); 1338 "gdata/Directory 1"))));
1335 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1339 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1336 "gdata/Directory 1/SubDirectory File 1.txt")))); 1340 "gdata/Directory 1/SubDirectory File 1.txt"))));
1337 1341
1338 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1342 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1339 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1343 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1340 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1344 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1341 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1345 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1342 LoadChangeFeed("delta_file_renamed_in_directory.json", 1346 LoadChangeFeed("delta_file_renamed_in_directory.json",
1343 ++latest_changelog); 1347 ++latest_changelog);
1344 1348
1345 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1349 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1346 "gdata/Directory 1")))); 1350 "gdata/Directory 1"))));
1347 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL( 1351 EXPECT_FALSE(FindFile(FilePath(FILE_PATH_LITERAL(
1348 "gdata/Directory 1/SubDirectory File 1.txt")))); 1352 "gdata/Directory 1/SubDirectory File 1.txt"))));
1349 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL( 1353 EXPECT_TRUE(FindFile(FilePath(FILE_PATH_LITERAL(
1350 "gdata/Directory 1/New SubDirectory File 1.txt")))); 1354 "gdata/Directory 1/New SubDirectory File 1.txt"))));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 EXPECT_EQ(src_file, FindFileByResourceId(src_file_resource)); 1469 EXPECT_EQ(src_file, FindFileByResourceId(src_file_resource));
1466 1470
1467 EXPECT_CALL(*mock_doc_service_, 1471 EXPECT_CALL(*mock_doc_service_,
1468 RenameResource(src_file->edit_url(), 1472 RenameResource(src_file->edit_url(),
1469 FILE_PATH_LITERAL("Test.log"), _)); 1473 FILE_PATH_LITERAL("Test.log"), _));
1470 1474
1471 FileOperationCallback callback = 1475 FileOperationCallback callback =
1472 base::Bind(&CallbackHelper::FileOperationCallback, 1476 base::Bind(&CallbackHelper::FileOperationCallback,
1473 callback_helper_.get()); 1477 callback_helper_.get());
1474 1478
1475 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1479 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1476 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1480 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1477 1481
1478 file_system_->Move(src_file_path, dest_file_path, callback); 1482 file_system_->Move(src_file_path, dest_file_path, callback);
1479 message_loop_.RunAllPending(); 1483 message_loop_.RunAllPending();
1480 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); 1484 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
1481 1485
1482 EXPECT_TRUE(FindFile(src_file_path) == NULL); 1486 EXPECT_TRUE(FindFile(src_file_path) == NULL);
1483 1487
1484 GDataFileBase* dest_file = NULL; 1488 GDataFileBase* dest_file = NULL;
1485 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL); 1489 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL);
(...skipping 25 matching lines...) Expand all
1511 FILE_PATH_LITERAL("Test.log"), _)); 1515 FILE_PATH_LITERAL("Test.log"), _));
1512 EXPECT_CALL(*mock_doc_service_, 1516 EXPECT_CALL(*mock_doc_service_,
1513 AddResourceToDirectory(dest_parent->content_url(), 1517 AddResourceToDirectory(dest_parent->content_url(),
1514 src_file->edit_url(), _)); 1518 src_file->edit_url(), _));
1515 1519
1516 FileOperationCallback callback = 1520 FileOperationCallback callback =
1517 base::Bind(&CallbackHelper::FileOperationCallback, 1521 base::Bind(&CallbackHelper::FileOperationCallback,
1518 callback_helper_.get()); 1522 callback_helper_.get());
1519 1523
1520 // Expect notification for both source and destination directories. 1524 // Expect notification for both source and destination directories.
1521 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1525 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1522 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1526 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1523 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1527 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1524 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1528 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1525 1529
1526 file_system_->Move(src_file_path, dest_file_path, callback); 1530 file_system_->Move(src_file_path, dest_file_path, callback);
1527 message_loop_.RunAllPending(); 1531 message_loop_.RunAllPending();
1528 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); 1532 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
1529 1533
1530 EXPECT_TRUE(FindFile(src_file_path) == NULL); 1534 EXPECT_TRUE(FindFile(src_file_path) == NULL);
1531 1535
1532 GDataFileBase* dest_file = NULL; 1536 GDataFileBase* dest_file = NULL;
1533 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL); 1537 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL);
(...skipping 27 matching lines...) Expand all
1561 EXPECT_CALL(*mock_doc_service_, 1565 EXPECT_CALL(*mock_doc_service_,
1562 RemoveResourceFromDirectory(src_parent->content_url(), 1566 RemoveResourceFromDirectory(src_parent->content_url(),
1563 src_file->edit_url(), 1567 src_file->edit_url(),
1564 src_file_path_resource, _)); 1568 src_file_path_resource, _));
1565 1569
1566 FileOperationCallback callback = 1570 FileOperationCallback callback =
1567 base::Bind(&CallbackHelper::FileOperationCallback, 1571 base::Bind(&CallbackHelper::FileOperationCallback,
1568 callback_helper_.get()); 1572 callback_helper_.get());
1569 1573
1570 // Expect notification for both source and destination directories. 1574 // Expect notification for both source and destination directories.
1571 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1575 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1572 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1576 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1573 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1577 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1574 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1578 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1575 1579
1576 file_system_->Move(src_file_path, dest_file_path, callback); 1580 file_system_->Move(src_file_path, dest_file_path, callback);
1577 message_loop_.RunAllPending(); 1581 message_loop_.RunAllPending();
1578 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); 1582 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
1579 1583
1580 EXPECT_TRUE(FindFile(src_file_path) == NULL); 1584 EXPECT_TRUE(FindFile(src_file_path) == NULL);
1581 1585
1582 GDataFileBase* dest_file = NULL; 1586 GDataFileBase* dest_file = NULL;
1583 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL); 1587 EXPECT_TRUE((dest_file = FindFile(dest_file_path)) != NULL);
1584 EXPECT_EQ(dest_file, FindFileByResourceId(src_file_path_resource)); 1588 EXPECT_EQ(dest_file, FindFileByResourceId(src_file_path_resource));
1585 EXPECT_EQ(src_file, dest_file); 1589 EXPECT_EQ(src_file, dest_file);
1586 } 1590 }
1587 1591
1588 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) { 1592 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) {
1589 FilePath src_parent_path(FILE_PATH_LITERAL("gdata/Directory 1")); 1593 FilePath src_parent_path(FILE_PATH_LITERAL("gdata/Directory 1"));
1590 FilePath src_file_path( 1594 FilePath src_file_path(
1591 FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")); 1595 FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt"));
1592 FilePath dest_parent_path(FILE_PATH_LITERAL("gdata/New Folder 1")); 1596 FilePath dest_parent_path(FILE_PATH_LITERAL("gdata/New Folder 1"));
1593 FilePath dest_file_path(FILE_PATH_LITERAL("gdata/New Folder 1/Test.log")); 1597 FilePath dest_file_path(FILE_PATH_LITERAL("gdata/New Folder 1/Test.log"));
1594 FilePath interim_file_path(FILE_PATH_LITERAL("gdata/Test.log")); 1598 FilePath interim_file_path(FILE_PATH_LITERAL("gdata/Test.log"));
1595 1599
1596 LoadRootFeedDocument("root_feed.json"); 1600 LoadRootFeedDocument("root_feed.json");
1597 1601
1598 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1602 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1599 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1603 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1600 1604
1601 AddDirectoryFromFile(dest_parent_path, "directory_entry_atom.json"); 1605 AddDirectoryFromFile(dest_parent_path, "directory_entry_atom.json");
1602 1606
1603 GDataFileBase* src_file = NULL; 1607 GDataFileBase* src_file = NULL;
1604 EXPECT_TRUE((src_file = FindFile(src_file_path)) != NULL); 1608 EXPECT_TRUE((src_file = FindFile(src_file_path)) != NULL);
1605 EXPECT_TRUE(src_file->AsGDataFile() != NULL); 1609 EXPECT_TRUE(src_file->AsGDataFile() != NULL);
1606 std::string src_file_path_resource = src_file->AsGDataFile()->resource_id(); 1610 std::string src_file_path_resource = src_file->AsGDataFile()->resource_id();
1607 EXPECT_EQ(src_file, FindFileByResourceId(src_file_path_resource)); 1611 EXPECT_EQ(src_file, FindFileByResourceId(src_file_path_resource));
1608 EXPECT_FALSE(src_file->edit_url().is_empty()); 1612 EXPECT_FALSE(src_file->edit_url().is_empty());
(...skipping 20 matching lines...) Expand all
1629 EXPECT_CALL(*mock_doc_service_, 1633 EXPECT_CALL(*mock_doc_service_,
1630 AddResourceToDirectory(dest_parent->content_url(), 1634 AddResourceToDirectory(dest_parent->content_url(),
1631 src_file->edit_url(), _)); 1635 src_file->edit_url(), _));
1632 1636
1633 FileOperationCallback callback = 1637 FileOperationCallback callback =
1634 base::Bind(&CallbackHelper::FileOperationCallback, 1638 base::Bind(&CallbackHelper::FileOperationCallback,
1635 callback_helper_.get()); 1639 callback_helper_.get());
1636 1640
1637 // Expect notification for both source and destination directories plus 1641 // Expect notification for both source and destination directories plus
1638 // interim file path. 1642 // interim file path.
1639 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1643 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1640 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); 1644 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1);
1641 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1645 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1642 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1646 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1643 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1647 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1644 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1"))))).Times(1); 1648 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1"))))).Times(1);
1645 1649
1646 file_system_->Move(src_file_path, dest_file_path, callback); 1650 file_system_->Move(src_file_path, dest_file_path, callback);
1647 message_loop_.RunAllPending(); 1651 message_loop_.RunAllPending();
1648 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); 1652 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
1649 1653
1650 EXPECT_TRUE(FindFile(src_file_path) == NULL); 1654 EXPECT_TRUE(FindFile(src_file_path) == NULL);
1651 EXPECT_TRUE(FindFile(interim_file_path) == NULL); 1655 EXPECT_TRUE(FindFile(interim_file_path) == NULL);
1652 1656
1653 GDataFileBase* dest_file = NULL; 1657 GDataFileBase* dest_file = NULL;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 EXPECT_EQ(file, FindFileByResourceId(file_in_root_resource)); 1767 EXPECT_EQ(file, FindFileByResourceId(file_in_root_resource));
1764 1768
1765 EXPECT_TRUE(FindFile(dir_in_root) != NULL); 1769 EXPECT_TRUE(FindFile(dir_in_root) != NULL);
1766 1770
1767 EXPECT_TRUE((file = FindFile(file_in_subdir)) != NULL); 1771 EXPECT_TRUE((file = FindFile(file_in_subdir)) != NULL);
1768 EXPECT_TRUE(file->AsGDataFile() != NULL); 1772 EXPECT_TRUE(file->AsGDataFile() != NULL);
1769 std::string file_in_subdir_resource = file->AsGDataFile()->resource_id(); 1773 std::string file_in_subdir_resource = file->AsGDataFile()->resource_id();
1770 EXPECT_EQ(file, FindFileByResourceId(file_in_subdir_resource)); 1774 EXPECT_EQ(file, FindFileByResourceId(file_in_subdir_resource));
1771 1775
1772 // Once for file in root and once for file... 1776 // Once for file in root and once for file...
1773 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1777 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1774 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(2); 1778 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(2);
1775 1779
1776 // Remove first file in root. 1780 // Remove first file in root.
1777 EXPECT_TRUE(RemoveFile(file_in_root)); 1781 EXPECT_TRUE(RemoveFile(file_in_root));
1778 EXPECT_TRUE(FindFile(file_in_root) == NULL); 1782 EXPECT_TRUE(FindFile(file_in_root) == NULL);
1779 EXPECT_EQ(NULL, FindFileByResourceId(file_in_root_resource)); 1783 EXPECT_EQ(NULL, FindFileByResourceId(file_in_root_resource));
1780 EXPECT_TRUE(FindFile(dir_in_root) != NULL); 1784 EXPECT_TRUE(FindFile(dir_in_root) != NULL);
1781 EXPECT_TRUE((file = FindFile(file_in_subdir)) != NULL); 1785 EXPECT_TRUE((file = FindFile(file_in_subdir)) != NULL);
1782 EXPECT_EQ(file, FindFileByResourceId(file_in_subdir_resource)); 1786 EXPECT_EQ(file, FindFileByResourceId(file_in_subdir_resource));
1783 1787
(...skipping 14 matching lines...) Expand all
1798 // Try removing root file element. 1802 // Try removing root file element.
1799 EXPECT_FALSE(RemoveFile(FilePath(FILE_PATH_LITERAL("gdata")))); 1803 EXPECT_FALSE(RemoveFile(FilePath(FILE_PATH_LITERAL("gdata"))));
1800 1804
1801 // Need this to ensure OnDirectoryChanged() is run. 1805 // Need this to ensure OnDirectoryChanged() is run.
1802 RunAllPendingForIO(); 1806 RunAllPendingForIO();
1803 } 1807 }
1804 1808
1805 TEST_F(GDataFileSystemTest, CreateDirectory) { 1809 TEST_F(GDataFileSystemTest, CreateDirectory) {
1806 LoadRootFeedDocument("root_feed.json"); 1810 LoadRootFeedDocument("root_feed.json");
1807 1811
1808 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1812 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1809 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); 1813 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1);
1810 1814
1811 // Create directory in root. 1815 // Create directory in root.
1812 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1")); 1816 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1"));
1813 EXPECT_TRUE(FindFile(dir_path) == NULL); 1817 EXPECT_TRUE(FindFile(dir_path) == NULL);
1814 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); 1818 AddDirectoryFromFile(dir_path, "directory_entry_atom.json");
1815 EXPECT_TRUE(FindFile(dir_path) != NULL); 1819 EXPECT_TRUE(FindFile(dir_path) != NULL);
1816 1820
1817 EXPECT_CALL(*mock_sync_client_, OnDirectoryChanged( 1821 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1818 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1"))))).Times(1); 1822 Eq(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1"))))).Times(1);
1819 1823
1820 // Create directory in a sub dirrectory. 1824 // Create directory in a sub dirrectory.
1821 FilePath subdir_path(FILE_PATH_LITERAL("gdata/New Folder 1/New Folder 2")); 1825 FilePath subdir_path(FILE_PATH_LITERAL("gdata/New Folder 1/New Folder 2"));
1822 EXPECT_TRUE(FindFile(subdir_path) == NULL); 1826 EXPECT_TRUE(FindFile(subdir_path) == NULL);
1823 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); 1827 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json");
1824 EXPECT_TRUE(FindFile(subdir_path) != NULL); 1828 EXPECT_TRUE(FindFile(subdir_path) != NULL);
1825 } 1829 }
1826 1830
1827 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { 1831 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) {
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 3016
3013 // Verify account meta feed is saved to cache. 3017 // Verify account meta feed is saved to cache.
3014 RunAllPendingForIO(); 3018 RunAllPendingForIO();
3015 FilePath path = file_system_->cache_paths_[ 3019 FilePath path = file_system_->cache_paths_[
3016 GDataRootDirectory::CACHE_TYPE_META].Append( 3020 GDataRootDirectory::CACHE_TYPE_META].Append(
3017 FILE_PATH_LITERAL("account_metadata.json")); 3021 FILE_PATH_LITERAL("account_metadata.json"));
3018 EXPECT_TRUE(file_util::PathExists(path)); 3022 EXPECT_TRUE(file_util::PathExists(path));
3019 } 3023 }
3020 3024
3021 } // namespace gdata 3025 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/mock_directory_change_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698