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

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

Issue 18355004: google_apis: Move data files out of chrome/test/data/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix extension tests Created 7 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/change_list_processor.h" 5 #include "chrome/browser/chromeos/drive/change_list_processor.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/drive/drive.pb.h" 10 #include "chrome/browser/chromeos/drive/drive.pb.h"
11 #include "chrome/browser/chromeos/drive/file_system_util.h" 11 #include "chrome/browser/chromeos/drive/file_system_util.h"
12 #include "chrome/browser/chromeos/drive/resource_metadata.h" 12 #include "chrome/browser/chromeos/drive/resource_metadata.h"
13 #include "chrome/browser/chromeos/drive/test_util.h" 13 #include "chrome/browser/chromeos/drive/test_util.h"
14 #include "chrome/browser/google_apis/drive_api_parser.h" 14 #include "chrome/browser/google_apis/drive_api_parser.h"
15 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 15 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
16 #include "chrome/browser/google_apis/test_util.h" 16 #include "chrome/browser/google_apis/test_util.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace drive { 20 namespace drive {
21 namespace internal { 21 namespace internal {
22 22
23 namespace { 23 namespace {
24 24
25 const int64 kBaseResourceListChangestamp = 123; 25 const int64 kBaseResourceListChangestamp = 123;
26 const char kBaseResourceListFile[] = "chromeos/gdata/root_feed.json"; 26 const char kBaseResourceListFile[] = "gdata/root_feed.json";
27 27
28 enum FileOrDirectory { 28 enum FileOrDirectory {
29 FILE, 29 FILE,
30 DIRECTORY, 30 DIRECTORY,
31 }; 31 };
32 32
33 struct EntryExpectation { 33 struct EntryExpectation {
34 std::string path; 34 std::string path;
35 std::string id; 35 std::string id;
36 std::string parent_id; 36 std::string parent_id;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 EXPECT_EQ(kExpected[i].parent_id, entry->parent_resource_id()); 158 EXPECT_EQ(kExpected[i].parent_id, entry->parent_resource_id());
159 EXPECT_EQ(kExpected[i].type, 159 EXPECT_EQ(kExpected[i].type,
160 entry->file_info().is_directory() ? DIRECTORY : FILE); 160 entry->file_info().is_directory() ? DIRECTORY : FILE);
161 } 161 }
162 162
163 EXPECT_EQ(kBaseResourceListChangestamp, metadata_->GetLargestChangestamp()); 163 EXPECT_EQ(kBaseResourceListChangestamp, metadata_->GetLargestChangestamp());
164 } 164 }
165 165
166 TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) { 166 TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) {
167 const char kTestJson[] = 167 const char kTestJson[] =
168 "chromeos/gdata/delta_file_added_in_new_directory.json"; 168 "gdata/delta_file_added_in_new_directory.json";
169 169
170 ChangeListProcessor::ResourceEntryMap entry_map; 170 ChangeListProcessor::ResourceEntryMap entry_map;
171 ChangeListProcessor::ConvertToMap( 171 ChangeListProcessor::ConvertToMap(
172 ParseChangeList(kTestJson), &entry_map, NULL); 172 ParseChangeList(kTestJson), &entry_map, NULL);
173 173
174 const std::string kRootId("fake_root"); 174 const std::string kRootId("fake_root");
175 const std::string kNewFolderId("folder:new_folder_resource_id"); 175 const std::string kNewFolderId("folder:new_folder_resource_id");
176 const std::string kNewFileId("document:file_added_in_new_dir_id"); 176 const std::string kNewFileId("document:file_added_in_new_dir_id");
177 177
178 // Check the content of parsed ResourceEntryMap. 178 // Check the content of parsed ResourceEntryMap.
(...skipping 20 matching lines...) Expand all
199 199
200 EXPECT_EQ(2U, changed_dirs.size()); 200 EXPECT_EQ(2U, changed_dirs.size());
201 EXPECT_TRUE(changed_dirs.count( 201 EXPECT_TRUE(changed_dirs.count(
202 base::FilePath::FromUTF8Unsafe("drive/root"))); 202 base::FilePath::FromUTF8Unsafe("drive/root")));
203 EXPECT_TRUE(changed_dirs.count( 203 EXPECT_TRUE(changed_dirs.count(
204 base::FilePath::FromUTF8Unsafe("drive/root/New Directory"))); 204 base::FilePath::FromUTF8Unsafe("drive/root/New Directory")));
205 } 205 }
206 206
207 TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) { 207 TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) {
208 const char kTestJson[] = 208 const char kTestJson[] =
209 "chromeos/gdata/delta_dir_moved_from_root_to_directory.json"; 209 "gdata/delta_dir_moved_from_root_to_directory.json";
210 210
211 ChangeListProcessor::ResourceEntryMap entry_map; 211 ChangeListProcessor::ResourceEntryMap entry_map;
212 ChangeListProcessor::ConvertToMap( 212 ChangeListProcessor::ConvertToMap(
213 ParseChangeList(kTestJson), &entry_map, NULL); 213 ParseChangeList(kTestJson), &entry_map, NULL);
214 214
215 const std::string kMovedId("folder:1_folder_resource_id"); 215 const std::string kMovedId("folder:1_folder_resource_id");
216 const std::string kDestId("folder:sub_dir_folder_2_self_link"); 216 const std::string kDestId("folder:sub_dir_folder_2_self_link");
217 217
218 // Check the content of parsed ResourceEntryMap. 218 // Check the content of parsed ResourceEntryMap.
219 EXPECT_EQ(2U, entry_map.size()); 219 EXPECT_EQ(2U, entry_map.size());
(...skipping 20 matching lines...) Expand all
240 EXPECT_TRUE(changed_dirs.count( 240 EXPECT_TRUE(changed_dirs.count(
241 base::FilePath::FromUTF8Unsafe( 241 base::FilePath::FromUTF8Unsafe(
242 "drive/root/Directory 2 excludeDir-test"))); 242 "drive/root/Directory 2 excludeDir-test")));
243 EXPECT_TRUE(changed_dirs.count( 243 EXPECT_TRUE(changed_dirs.count(
244 base::FilePath::FromUTF8Unsafe( 244 base::FilePath::FromUTF8Unsafe(
245 "drive/root/Directory 2 excludeDir-test/Directory 1"))); 245 "drive/root/Directory 2 excludeDir-test/Directory 1")));
246 } 246 }
247 247
248 TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { 248 TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) {
249 const char kTestJson[] = 249 const char kTestJson[] =
250 "chromeos/gdata/delta_file_moved_from_directory_to_root.json"; 250 "gdata/delta_file_moved_from_directory_to_root.json";
251 251
252 ChangeListProcessor::ResourceEntryMap entry_map; 252 ChangeListProcessor::ResourceEntryMap entry_map;
253 ChangeListProcessor::ConvertToMap( 253 ChangeListProcessor::ConvertToMap(
254 ParseChangeList(kTestJson), &entry_map, NULL); 254 ParseChangeList(kTestJson), &entry_map, NULL);
255 255
256 const std::string kRootId("fake_root"); 256 const std::string kRootId("fake_root");
257 const std::string kMovedId("file:subdirectory_file_1_id"); 257 const std::string kMovedId("file:subdirectory_file_1_id");
258 const std::string kSrcId("folder:1_folder_resource_id"); 258 const std::string kSrcId("folder:1_folder_resource_id");
259 259
260 // Check the content of parsed ResourceEntryMap. 260 // Check the content of parsed ResourceEntryMap.
(...skipping 15 matching lines...) Expand all
276 276
277 EXPECT_EQ(2U, changed_dirs.size()); 277 EXPECT_EQ(2U, changed_dirs.size());
278 EXPECT_TRUE(changed_dirs.count( 278 EXPECT_TRUE(changed_dirs.count(
279 base::FilePath::FromUTF8Unsafe("drive/root"))); 279 base::FilePath::FromUTF8Unsafe("drive/root")));
280 EXPECT_TRUE(changed_dirs.count( 280 EXPECT_TRUE(changed_dirs.count(
281 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); 281 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1")));
282 } 282 }
283 283
284 TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { 284 TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) {
285 const char kTestJson[] = 285 const char kTestJson[] =
286 "chromeos/gdata/delta_file_renamed_in_directory.json"; 286 "gdata/delta_file_renamed_in_directory.json";
287 287
288 ChangeListProcessor::ResourceEntryMap entry_map; 288 ChangeListProcessor::ResourceEntryMap entry_map;
289 ChangeListProcessor::ConvertToMap( 289 ChangeListProcessor::ConvertToMap(
290 ParseChangeList(kTestJson), &entry_map, NULL); 290 ParseChangeList(kTestJson), &entry_map, NULL);
291 291
292 const std::string kRootId("fake_root"); 292 const std::string kRootId("fake_root");
293 const std::string kRenamedId("file:subdirectory_file_1_id"); 293 const std::string kRenamedId("file:subdirectory_file_1_id");
294 const std::string kParentId("folder:1_folder_resource_id"); 294 const std::string kParentId("folder:1_folder_resource_id");
295 295
296 // Check the content of parsed ResourceEntryMap. 296 // Check the content of parsed ResourceEntryMap.
(...skipping 17 matching lines...) Expand all
314 314
315 EXPECT_EQ(2U, changed_dirs.size()); 315 EXPECT_EQ(2U, changed_dirs.size());
316 EXPECT_TRUE(changed_dirs.count( 316 EXPECT_TRUE(changed_dirs.count(
317 base::FilePath::FromUTF8Unsafe("drive/root"))); 317 base::FilePath::FromUTF8Unsafe("drive/root")));
318 EXPECT_TRUE(changed_dirs.count( 318 EXPECT_TRUE(changed_dirs.count(
319 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); 319 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1")));
320 } 320 }
321 321
322 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) { 322 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) {
323 const char kTestJsonAdd[] = 323 const char kTestJsonAdd[] =
324 "chromeos/gdata/delta_file_added_in_root.json"; 324 "gdata/delta_file_added_in_root.json";
325 const char kTestJsonDelete[] = 325 const char kTestJsonDelete[] =
326 "chromeos/gdata/delta_file_deleted_in_root.json"; 326 "gdata/delta_file_deleted_in_root.json";
327 327
328 const std::string kParentId("fake_root"); 328 const std::string kParentId("fake_root");
329 const std::string kFileId("document:added_in_root_id"); 329 const std::string kFileId("document:added_in_root_id");
330 330
331 ChangeListProcessor::ResourceEntryMap entry_map; 331 ChangeListProcessor::ResourceEntryMap entry_map;
332 332
333 // Check the content of kTestJsonAdd. 333 // Check the content of kTestJsonAdd.
334 ChangeListProcessor::ConvertToMap( 334 ChangeListProcessor::ConvertToMap(
335 ParseChangeList(kTestJsonAdd), &entry_map, NULL); 335 ParseChangeList(kTestJsonAdd), &entry_map, NULL);
336 EXPECT_EQ(1U, entry_map.size()); 336 EXPECT_EQ(1U, entry_map.size());
(...skipping 27 matching lines...) Expand all
364 EXPECT_EQ(16687, metadata_->GetLargestChangestamp()); 364 EXPECT_EQ(16687, metadata_->GetLargestChangestamp());
365 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.gdoc")); 365 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.gdoc"));
366 EXPECT_EQ(1U, changed_dirs.size()); 366 EXPECT_EQ(1U, changed_dirs.size());
367 EXPECT_TRUE(changed_dirs.count( 367 EXPECT_TRUE(changed_dirs.count(
368 base::FilePath::FromUTF8Unsafe("drive/root"))); 368 base::FilePath::FromUTF8Unsafe("drive/root")));
369 } 369 }
370 370
371 371
372 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) { 372 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) {
373 const char kTestJsonAdd[] = 373 const char kTestJsonAdd[] =
374 "chromeos/gdata/delta_file_added_in_directory.json"; 374 "gdata/delta_file_added_in_directory.json";
375 const char kTestJsonDelete[] = 375 const char kTestJsonDelete[] =
376 "chromeos/gdata/delta_file_deleted_in_directory.json"; 376 "gdata/delta_file_deleted_in_directory.json";
377 377
378 const std::string kParentId("folder:1_folder_resource_id"); 378 const std::string kParentId("folder:1_folder_resource_id");
379 const std::string kFileId("document:added_in_root_id"); 379 const std::string kFileId("document:added_in_root_id");
380 380
381 ChangeListProcessor::ResourceEntryMap entry_map; 381 ChangeListProcessor::ResourceEntryMap entry_map;
382 382
383 // Check the content of kTestJsonAdd. 383 // Check the content of kTestJsonAdd.
384 ChangeListProcessor::ConvertToMap( 384 ChangeListProcessor::ConvertToMap(
385 ParseChangeList(kTestJsonAdd), &entry_map, NULL); 385 ParseChangeList(kTestJsonAdd), &entry_map, NULL);
386 EXPECT_EQ(2U, entry_map.size()); 386 EXPECT_EQ(2U, entry_map.size());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 EXPECT_TRUE(changed_dirs.count( 422 EXPECT_TRUE(changed_dirs.count(
423 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); 423 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1")));
424 } 424 }
425 425
426 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { 426 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) {
427 // This file contains the following updates: 427 // This file contains the following updates:
428 // 1) A new PDF file is added to a new directory 428 // 1) A new PDF file is added to a new directory
429 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) 429 // 2) but the new directory is marked "deleted" (i.e. moved to Trash)
430 // Hence, the PDF file should be just ignored. 430 // Hence, the PDF file should be just ignored.
431 const char kTestJson[] = 431 const char kTestJson[] =
432 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json"; 432 "gdata/delta_file_added_in_new_but_deleted_directory.json";
433 433
434 ChangeListProcessor::ResourceEntryMap entry_map; 434 ChangeListProcessor::ResourceEntryMap entry_map;
435 ChangeListProcessor::ConvertToMap( 435 ChangeListProcessor::ConvertToMap(
436 ParseChangeList(kTestJson), &entry_map, NULL); 436 ParseChangeList(kTestJson), &entry_map, NULL);
437 437
438 const std::string kRootId("fake_root"); 438 const std::string kRootId("fake_root");
439 const std::string kDirId("folder:new_folder_resource_id"); 439 const std::string kDirId("folder:new_folder_resource_id");
440 const std::string kFileId("pdf:file_added_in_deleted_dir_id"); 440 const std::string kFileId("pdf:file_added_in_deleted_dir_id");
441 441
442 // Check the content of parsed ResourceEntryMap. 442 // Check the content of parsed ResourceEntryMap.
(...skipping 10 matching lines...) Expand all
453 453
454 // The value is written in kTestJson. 454 // The value is written in kTestJson.
455 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); 455 EXPECT_EQ(16730, metadata_->GetLargestChangestamp());
456 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf")); 456 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf"));
457 457
458 EXPECT_TRUE(changed_dirs.empty()); 458 EXPECT_TRUE(changed_dirs.empty());
459 } 459 }
460 460
461 } // namespace internal 461 } // namespace internal
462 } // namespace drive 462 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698