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

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

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