Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // MediaFileSystemRegistry unit tests. | 5 // MediaFileSystemRegistry unit tests. |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/json/json_reader.h" | |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 15 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 17 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 18 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 21 #include "base/values.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 23 #include "chrome/browser/extensions/extension_system.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 DCHECK(!path.ReferencesParent()); | 146 DCHECK(!path.ReferencesParent()); |
| 145 | 147 |
| 146 std::string fsid = base::StringPrintf("FSID:%d", ++fsid_); | 148 std::string fsid = base::StringPrintf("FSID:%d", ++fsid_); |
| 147 FSInfo info(device_id, path, fsid); | 149 FSInfo info(device_id, path, fsid); |
| 148 file_systems_by_id_[fsid] = info; | 150 file_systems_by_id_[fsid] = info; |
| 149 return fsid; | 151 return fsid; |
| 150 } | 152 } |
| 151 | 153 |
| 152 namespace { | 154 namespace { |
| 153 | 155 |
| 156 void GetGalleryNamesCB(std::set<std::string>* results, | |
| 157 const std::vector<MediaFileSystemInfo>& file_systems) { | |
| 158 for (size_t i = 0; i < file_systems.size(); ++i) { | |
| 159 std::set<std::string>::const_iterator it = | |
| 160 results->find(file_systems[i].name); | |
| 161 ASSERT_EQ(it, results->end()); | |
| 162 results->insert(file_systems[i].name); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 | |
|
kmadhusu
2012/12/14 03:29:39
nit: remove a blank line.
Lei Zhang
2012/12/14 03:45:31
Done.
| |
| 167 void CheckGalleryJSONName(const std::string& name, | |
| 168 bool removable, | |
| 169 bool user_added) { | |
| 170 scoped_ptr<DictionaryValue> dict(static_cast<DictionaryValue*>( | |
| 171 base::JSONReader::Read(name))); | |
| 172 ASSERT_TRUE(dict); | |
| 173 | |
| 174 // Check deviceId. | |
| 175 EXPECT_EQ(removable, | |
| 176 dict->HasKey(MediaFileSystemRegistry::kDeviceIdKey)) << name; | |
| 177 if (removable) { | |
| 178 std::string device_id; | |
| 179 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kDeviceIdKey, | |
| 180 &device_id)) << name; | |
|
kmadhusu
2012/12/14 03:29:39
style nit: Add one more space before &device_id
Lei Zhang
2012/12/14 03:45:31
Done.
| |
| 181 EXPECT_FALSE(device_id.empty()) << name; | |
| 182 } | |
| 183 | |
| 184 // Check galleryId. | |
| 185 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kGalleryIdKey)) << name; | |
|
kmadhusu
2012/12/14 03:29:39
Can we also make sure !gallery_id.empty()?
Lei Zhang
2012/12/14 03:45:31
galleryId is a number.
| |
| 186 | |
| 187 // Check name. | |
| 188 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kNameKey)) << name; | |
| 189 std::string gallery_name; | |
| 190 EXPECT_TRUE(dict->GetString(MediaFileSystemRegistry::kNameKey, | |
| 191 &gallery_name)) << name; | |
|
kmadhusu
2012/12/14 03:29:39
style nit: Add one more space before &gallery_name
Lei Zhang
2012/12/14 03:45:31
Done.
| |
| 192 EXPECT_FALSE(gallery_name.empty()) << name; | |
| 193 | |
| 194 // Check userAdded. | |
| 195 EXPECT_TRUE(dict->HasKey(MediaFileSystemRegistry::kUserAddedKey)) << name; | |
| 196 bool actual_user_added = !user_added; | |
| 197 EXPECT_TRUE(dict->GetBoolean(MediaFileSystemRegistry::kUserAddedKey, | |
| 198 &actual_user_added)) << name; | |
|
kmadhusu
2012/12/14 03:29:39
style nit: Add one more space before &gallery_name
Lei Zhang
2012/12/14 03:45:31
Done.
| |
| 199 EXPECT_EQ(user_added, actual_user_added) << name; | |
| 200 } | |
| 201 | |
| 154 class TestMediaStorageUtil : public MediaStorageUtil { | 202 class TestMediaStorageUtil : public MediaStorageUtil { |
| 155 public: | 203 public: |
| 156 static void SetTestingMode(); | 204 static void SetTestingMode(); |
| 157 | 205 |
| 158 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, | 206 static bool GetDeviceInfoFromPathTestFunction(const FilePath& path, |
| 159 std::string* device_id, | 207 std::string* device_id, |
| 160 string16* device_name, | 208 string16* device_name, |
| 161 FilePath* relative_path); | 209 FilePath* relative_path); |
| 162 }; | 210 }; |
| 163 | 211 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 189 MockProfileSharedRenderProcessHostFactory* rph_factory); | 237 MockProfileSharedRenderProcessHostFactory* rph_factory); |
| 190 ~ProfileState(); | 238 ~ProfileState(); |
| 191 | 239 |
| 192 MediaGalleriesPreferences* GetMediaGalleriesPrefs(); | 240 MediaGalleriesPreferences* GetMediaGalleriesPrefs(); |
| 193 | 241 |
| 194 void CheckGalleries( | 242 void CheckGalleries( |
| 195 const std::string& test, | 243 const std::string& test, |
| 196 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, | 244 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, |
| 197 const std::vector<MediaFileSystemInfo>& all_extension_galleries); | 245 const std::vector<MediaFileSystemInfo>& all_extension_galleries); |
| 198 | 246 |
| 247 std::set<std::string> GetGalleryNames(extensions::Extension* extension); | |
| 248 | |
| 199 extensions::Extension* all_permission_extension(); | 249 extensions::Extension* all_permission_extension(); |
| 200 extensions::Extension* regular_permission_extension(); | 250 extensions::Extension* regular_permission_extension(); |
| 201 | 251 |
| 202 private: | 252 private: |
| 203 void CompareResults(const std::string& test, | 253 void CompareResults(const std::string& test, |
| 204 const std::vector<MediaFileSystemInfo>& expected, | 254 const std::vector<MediaFileSystemInfo>& expected, |
| 205 const std::vector<MediaFileSystemInfo>& actual); | 255 const std::vector<MediaFileSystemInfo>& actual); |
| 206 | 256 |
| 207 int GetAndClearComparisonCount(); | 257 int GetAndClearComparisonCount(); |
| 208 | 258 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 306 |
| 257 void DetachDevice(const std::string& device_id); | 307 void DetachDevice(const std::string& device_id); |
| 258 | 308 |
| 259 void SetGalleryPermission(ProfileState* profile_state, | 309 void SetGalleryPermission(ProfileState* profile_state, |
| 260 extensions::Extension* extension, | 310 extensions::Extension* extension, |
| 261 const std::string& device_id, | 311 const std::string& device_id, |
| 262 bool has_access); | 312 bool has_access); |
| 263 | 313 |
| 264 void AssertAllAutoAddedGalleries(); | 314 void AssertAllAutoAddedGalleries(); |
| 265 | 315 |
| 316 void InitForGalleryNamesTest(std::set<std::string>* gallery_names); | |
| 317 | |
| 318 void CheckNewGallery(ProfileState* profile_state, | |
| 319 const std::set<std::string>& gallery_names, | |
|
kmadhusu
2012/12/14 03:29:39
nit: std::set<std::string> is used at several plac
Lei Zhang
2012/12/14 03:45:31
I don't see what's so hard to understand about a s
| |
| 320 bool removable, | |
| 321 bool user_added); | |
| 322 | |
| 266 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( | 323 std::vector<MediaFileSystemInfo> GetAutoAddedGalleries( |
| 267 ProfileState* profile_state); | 324 ProfileState* profile_state); |
| 268 | 325 |
| 269 protected: | 326 protected: |
| 270 void SetUp(); | 327 void SetUp(); |
| 271 void TearDown(); | 328 void TearDown(); |
| 272 | 329 |
| 273 private: | 330 private: |
| 274 // This makes sure that at least one default gallery exists on the file | 331 // This makes sure that at least one default gallery exists on the file |
| 275 // system. | 332 // system. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // All galleries permission. | 503 // All galleries permission. |
| 447 registry->GetMediaFileSystemsForExtension( | 504 registry->GetMediaFileSystemsForExtension( |
| 448 rvh, all_permission_extension_.get(), | 505 rvh, all_permission_extension_.get(), |
| 449 base::Bind(&ProfileState::CompareResults, base::Unretained(this), | 506 base::Bind(&ProfileState::CompareResults, base::Unretained(this), |
| 450 StringPrintf("%s (all permission)", test.c_str()), | 507 StringPrintf("%s (all permission)", test.c_str()), |
| 451 base::ConstRef(all_extension_galleries))); | 508 base::ConstRef(all_extension_galleries))); |
| 452 MessageLoop::current()->RunUntilIdle(); | 509 MessageLoop::current()->RunUntilIdle(); |
| 453 EXPECT_EQ(1, GetAndClearComparisonCount()); | 510 EXPECT_EQ(1, GetAndClearComparisonCount()); |
| 454 } | 511 } |
| 455 | 512 |
| 513 std::set<std::string> ProfileState::GetGalleryNames( | |
| 514 extensions::Extension* extension) { | |
| 515 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); | |
| 516 std::set<std::string> results; | |
| 517 MediaFileSystemRegistry* registry = | |
| 518 g_browser_process->media_file_system_registry(); | |
| 519 registry->GetMediaFileSystemsForExtension( | |
| 520 rvh, extension, | |
| 521 base::Bind(&GetGalleryNamesCB, base::Unretained(&results))); | |
|
kmadhusu
2012/12/14 03:29:39
Just curious about the "GetGalleryNamesCB", Are we
Lei Zhang
2012/12/14 03:45:31
Renamed.
| |
| 522 MessageLoop::current()->RunUntilIdle(); | |
| 523 return results; | |
| 524 } | |
| 525 | |
| 456 extensions::Extension* ProfileState::all_permission_extension() { | 526 extensions::Extension* ProfileState::all_permission_extension() { |
| 457 return all_permission_extension_.get(); | 527 return all_permission_extension_.get(); |
| 458 } | 528 } |
| 459 | 529 |
| 460 extensions::Extension* ProfileState::regular_permission_extension() { | 530 extensions::Extension* ProfileState::regular_permission_extension() { |
| 461 return regular_permission_extension_.get(); | 531 return regular_permission_extension_.get(); |
| 462 } | 532 } |
| 463 | 533 |
| 464 void ProfileState::CompareResults( | 534 void ProfileState::CompareResults( |
| 465 const std::string& test, | 535 const std::string& test, |
| 466 const std::vector<MediaFileSystemInfo>& expected, | 536 const std::vector<MediaFileSystemInfo>& expected, |
| 467 const std::vector<MediaFileSystemInfo>& actual) { | 537 const std::vector<MediaFileSystemInfo>& actual) { |
| 468 // Order isn't important, so sort the results. Assume that expected | 538 // Order isn't important, so sort the results. Assume that expected |
| 469 // is already sorted. | 539 // is already sorted. |
| 470 std::vector<MediaFileSystemInfo> sorted(actual); | 540 std::vector<MediaFileSystemInfo> sorted(actual); |
| 471 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); | 541 std::sort(sorted.begin(), sorted.end(), MediaFileSystemInfoComparator); |
| 472 | 542 |
| 473 num_comparisons_++; | 543 num_comparisons_++; |
| 474 ASSERT_EQ(expected.size(), actual.size()) << test; | 544 ASSERT_EQ(expected.size(), actual.size()) << test; |
| 475 for (size_t i = 0; i < expected.size() && i < actual.size(); i++) { | 545 for (size_t i = 0; i < expected.size() && i < actual.size(); ++i) { |
| 476 EXPECT_EQ(expected[i].path.value(), actual[i].path.value()) << test; | 546 EXPECT_EQ(expected[i].path.value(), actual[i].path.value()) << test; |
| 477 EXPECT_FALSE(actual[i].fsid.empty()) << test; | 547 EXPECT_FALSE(actual[i].fsid.empty()) << test; |
| 478 if (!expected[i].fsid.empty()) | 548 if (!expected[i].fsid.empty()) |
| 479 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; | 549 EXPECT_EQ(expected[i].fsid, actual[i].fsid) << test; |
| 480 } | 550 } |
| 481 } | 551 } |
| 482 | 552 |
| 483 int ProfileState::GetAndClearComparisonCount() { | 553 int ProfileState::GetAndClearComparisonCount() { |
| 484 int result = num_comparisons_; | 554 int result = num_comparisons_; |
| 485 num_comparisons_ = 0; | 555 num_comparisons_ = 0; |
| 486 return result; | 556 return result; |
| 487 } | 557 } |
| 488 | 558 |
| 489 ///////////////////////////////// | 559 ///////////////////////////////// |
| 490 // MediaFileSystemRegistryTest // | 560 // MediaFileSystemRegistryTest // |
| 491 ///////////////////////////////// | 561 ///////////////////////////////// |
| 492 | 562 |
| 493 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() | 563 MediaFileSystemRegistryTest::MediaFileSystemRegistryTest() |
| 494 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), | 564 : ui_thread_(content::BrowserThread::UI, MessageLoop::current()), |
| 495 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { | 565 file_thread_(content::BrowserThread::FILE, MessageLoop::current()) { |
| 496 } | 566 } |
| 497 | 567 |
| 498 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { | 568 void MediaFileSystemRegistryTest::CreateProfileState(size_t profile_count) { |
| 499 for (size_t i = 0; i < profile_count; i++) { | 569 for (size_t i = 0; i < profile_count; ++i) { |
| 500 ProfileState* state = new ProfileState(&rph_factory_); | 570 ProfileState* state = new ProfileState(&rph_factory_); |
| 501 profile_states_.push_back(state); | 571 profile_states_.push_back(state); |
| 502 } | 572 } |
| 503 } | 573 } |
| 504 | 574 |
| 505 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { | 575 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { |
| 506 return profile_states_[i]; | 576 return profile_states_[i]; |
| 507 } | 577 } |
| 508 | 578 |
| 509 std::string MediaFileSystemRegistryTest::AddUserGallery( | 579 std::string MediaFileSystemRegistryTest::AddUserGallery( |
| 510 MediaStorageUtil::Type type, | 580 MediaStorageUtil::Type type, |
| 511 const std::string& unique_id, | 581 const std::string& unique_id, |
| 512 const FilePath& path) { | 582 const FilePath& path) { |
| 513 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 583 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 514 string16 name = path.LossyDisplayName(); | 584 string16 name = path.LossyDisplayName(); |
| 515 DCHECK(!MediaStorageUtil::IsMediaDevice(device_id)); | 585 DCHECK(!MediaStorageUtil::IsMediaDevice(device_id)); |
| 516 | 586 |
| 517 for (size_t i = 0; i < profile_states_.size(); i++) { | 587 for (size_t i = 0; i < profile_states_.size(); ++i) { |
| 518 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( | 588 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( |
| 519 device_id, name, FilePath(), true /*user_added*/); | 589 device_id, name, FilePath(), true /*user_added*/); |
| 520 } | 590 } |
| 521 return device_id; | 591 return device_id; |
| 522 } | 592 } |
| 523 | 593 |
| 524 std::string MediaFileSystemRegistryTest::AttachDevice( | 594 std::string MediaFileSystemRegistryTest::AttachDevice( |
| 525 MediaStorageUtil::Type type, | 595 MediaStorageUtil::Type type, |
| 526 const std::string& unique_id, | 596 const std::string& unique_id, |
| 527 const FilePath& location) { | 597 const FilePath& location) { |
| 528 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); | 598 std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id); |
| 529 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 599 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 530 string16 name = location.LossyDisplayName(); | 600 string16 name = location.LossyDisplayName(); |
| 531 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 601 base::SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, |
| 532 location.value()); | 602 location.value()); |
| 603 bool user_added = (type == MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM); | |
| 604 for (size_t i = 0; i < profile_states_.size(); ++i) { | |
| 605 profile_states_[i]->GetMediaGalleriesPrefs()->AddGallery( | |
| 606 device_id, name, FilePath(), user_added); | |
| 607 } | |
| 533 MessageLoop::current()->RunUntilIdle(); | 608 MessageLoop::current()->RunUntilIdle(); |
| 534 return device_id; | 609 return device_id; |
| 535 } | 610 } |
| 536 | 611 |
| 537 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { | 612 void MediaFileSystemRegistryTest::DetachDevice(const std::string& device_id) { |
| 538 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); | 613 DCHECK(MediaStorageUtil::IsRemovableDevice(device_id)); |
| 539 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); | 614 base::SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); |
| 540 MessageLoop::current()->RunUntilIdle(); | 615 MessageLoop::current()->RunUntilIdle(); |
| 541 } | 616 } |
| 542 | 617 |
| 543 void MediaFileSystemRegistryTest::SetGalleryPermission( | 618 void MediaFileSystemRegistryTest::SetGalleryPermission( |
| 544 ProfileState* profile_state, extensions::Extension* extension, | 619 ProfileState* profile_state, extensions::Extension* extension, |
| 545 const std::string& device_id, bool has_access) { | 620 const std::string& device_id, bool has_access) { |
| 546 MediaGalleriesPreferences* preferences = | 621 MediaGalleriesPreferences* preferences = |
| 547 profile_state->GetMediaGalleriesPrefs(); | 622 profile_state->GetMediaGalleriesPrefs(); |
| 548 MediaGalleryPrefIdSet pref_id = | 623 MediaGalleryPrefIdSet pref_id = |
| 549 preferences->LookUpGalleriesByDeviceId(device_id); | 624 preferences->LookUpGalleriesByDeviceId(device_id); |
| 550 DCHECK_EQ(1U, pref_id.size()); | 625 ASSERT_EQ(1U, pref_id.size()); |
| 551 preferences->SetGalleryPermissionForExtension(*extension, *pref_id.begin(), | 626 preferences->SetGalleryPermissionForExtension(*extension, *pref_id.begin(), |
| 552 has_access); | 627 has_access); |
| 553 } | 628 } |
| 554 | 629 |
| 555 void MediaFileSystemRegistryTest::AssertAllAutoAddedGalleries() { | 630 void MediaFileSystemRegistryTest::AssertAllAutoAddedGalleries() { |
| 556 for (size_t i = 0; i < profile_states_.size(); i++) { | 631 for (size_t i = 0; i < profile_states_.size(); ++i) { |
| 557 MediaGalleriesPreferences* prefs = | 632 MediaGalleriesPreferences* prefs = |
| 558 profile_states_[0]->GetMediaGalleriesPrefs(); | 633 profile_states_[0]->GetMediaGalleriesPrefs(); |
| 559 | 634 |
| 560 // Make sure that we have at least one gallery and that they are all | 635 // Make sure that we have at least one gallery and that they are all |
| 561 // auto added galleries. | 636 // auto added galleries. |
| 562 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); | 637 const MediaGalleriesPrefInfoMap& galleries = prefs->known_galleries(); |
| 563 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 638 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 564 ASSERT_GT(galleries.size(), 0U); | 639 ASSERT_GT(galleries.size(), 0U); |
| 565 #endif | 640 #endif |
| 566 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 641 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
| 567 it != galleries.end(); | 642 it != galleries.end(); |
| 568 ++it) { | 643 ++it) { |
| 569 ASSERT_EQ(MediaGalleryPrefInfo::kAutoDetected, it->second.type); | 644 ASSERT_EQ(MediaGalleryPrefInfo::kAutoDetected, it->second.type); |
| 570 } | 645 } |
| 571 } | 646 } |
| 572 } | 647 } |
| 573 | 648 |
| 649 void MediaFileSystemRegistryTest::InitForGalleryNamesTest( | |
| 650 std::set<std::string>* gallery_names) { | |
| 651 CreateProfileState(1); | |
| 652 AssertAllAutoAddedGalleries(); | |
| 653 | |
| 654 // Get all existing gallery names. | |
| 655 ProfileState* profile_state = GetProfileState(0U); | |
| 656 *gallery_names = | |
| 657 profile_state->GetGalleryNames(profile_state->all_permission_extension()); | |
| 658 ASSERT_EQ(3U, gallery_names->size()); | |
| 659 } | |
| 660 | |
| 661 void MediaFileSystemRegistryTest::CheckNewGallery( | |
| 662 ProfileState* profile_state, | |
| 663 const std::set<std::string>& gallery_names, | |
| 664 bool removable, | |
| 665 bool user_added) { | |
| 666 // Get new galleries. | |
| 667 std::set<std::string> new_gallery_names = | |
| 668 profile_state->GetGalleryNames(profile_state->all_permission_extension()); | |
| 669 ASSERT_EQ(4U, new_gallery_names.size()); | |
| 670 | |
| 671 // Find the new one and check it. | |
| 672 std::vector<std::string> difference; | |
| 673 std::set_symmetric_difference( | |
| 674 gallery_names.begin(), gallery_names.end(), | |
| 675 new_gallery_names.begin(), new_gallery_names.end(), | |
| 676 std::back_inserter(difference)); | |
| 677 ASSERT_EQ(1U, difference.size()); | |
| 678 CheckGalleryJSONName(difference[0], removable, user_added); | |
| 679 } | |
| 680 | |
| 574 std::vector<MediaFileSystemInfo> | 681 std::vector<MediaFileSystemInfo> |
| 575 MediaFileSystemRegistryTest::GetAutoAddedGalleries( | 682 MediaFileSystemRegistryTest::GetAutoAddedGalleries( |
| 576 ProfileState* profile_state) { | 683 ProfileState* profile_state) { |
| 577 const MediaGalleriesPrefInfoMap& galleries = | 684 const MediaGalleriesPrefInfoMap& galleries = |
| 578 profile_state->GetMediaGalleriesPrefs()->known_galleries(); | 685 profile_state->GetMediaGalleriesPrefs()->known_galleries(); |
| 579 std::vector<MediaFileSystemInfo> result; | 686 std::vector<MediaFileSystemInfo> result; |
| 580 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 687 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
| 581 it != galleries.end(); | 688 it != galleries.end(); |
| 582 ++it) { | 689 ++it) { |
| 583 if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { | 690 if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 // Add it to the all galleries extension. | 770 // Add it to the all galleries extension. |
| 664 SetGalleryPermission(profile_state, | 771 SetGalleryPermission(profile_state, |
| 665 profile_state->all_permission_extension(), | 772 profile_state->all_permission_extension(), |
| 666 device_id, | 773 device_id, |
| 667 true /*has access*/); | 774 true /*has access*/); |
| 668 auto_galleries.push_back(added_info); | 775 auto_galleries.push_back(added_info); |
| 669 profile_state->CheckGalleries("user added all", added_galleries, | 776 profile_state->CheckGalleries("user added all", added_galleries, |
| 670 auto_galleries); | 777 auto_galleries); |
| 671 } | 778 } |
| 672 | 779 |
| 780 TEST_F(MediaFileSystemRegistryTest, GalleryNameDefault) { | |
| 781 std::set<std::string> gallery_names; | |
| 782 InitForGalleryNamesTest(&gallery_names); | |
| 783 | |
| 784 for (std::set<std::string>::const_iterator it = gallery_names.begin(); | |
| 785 it != gallery_names.end(); | |
| 786 ++it) { | |
| 787 CheckGalleryJSONName(*it, | |
| 788 false /*not removable*/, | |
| 789 false /*not user added*/); | |
| 790 } | |
| 791 } | |
| 792 | |
| 793 TEST_F(MediaFileSystemRegistryTest, GalleryNameMTP) { | |
| 794 std::set<std::string> gallery_names; | |
| 795 InitForGalleryNamesTest(&gallery_names); | |
| 796 | |
| 797 FilePath location(FILE_PATH_LITERAL("/mtp_bogus")); | |
| 798 AttachDevice(MediaStorageUtil::MTP_OR_PTP, "mtp_fake_id", location); | |
| 799 CheckNewGallery(GetProfileState(0U), gallery_names, | |
| 800 true /*removable*/, false /*not user added*/); | |
| 801 } | |
| 802 | |
| 803 TEST_F(MediaFileSystemRegistryTest, GalleryNameDCIM) { | |
| 804 std::set<std::string> gallery_names; | |
| 805 InitForGalleryNamesTest(&gallery_names); | |
| 806 | |
| 807 FilePath location(FILE_PATH_LITERAL("/removable_dcim_bogus")); | |
| 808 AttachDevice(MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, | |
| 809 "removable_dcim_fake_id", | |
| 810 location); | |
| 811 CheckNewGallery(GetProfileState(0U), gallery_names, | |
| 812 true /*removable*/, false /*not user added*/); | |
| 813 } | |
| 814 | |
| 815 TEST_F(MediaFileSystemRegistryTest, GalleryNameNoDCIM) { | |
| 816 std::set<std::string> gallery_names; | |
| 817 InitForGalleryNamesTest(&gallery_names); | |
| 818 | |
| 819 std::string device_id = | |
| 820 AttachDevice(MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | |
| 821 empty_dir().AsUTF8Unsafe(), | |
| 822 empty_dir()); | |
| 823 std::string device_id2 = | |
| 824 AddUserGallery(MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, | |
| 825 empty_dir().AsUTF8Unsafe(), | |
| 826 empty_dir()); | |
| 827 ASSERT_EQ(device_id, device_id2); | |
| 828 // Add permission for new non-default gallery. | |
| 829 ProfileState* profile_state = GetProfileState(0U); | |
| 830 SetGalleryPermission(profile_state, | |
| 831 profile_state->all_permission_extension(), | |
| 832 device_id, | |
| 833 true /*has access*/); | |
| 834 CheckNewGallery(profile_state, gallery_names, | |
| 835 true /*removable*/, true /*user added*/); | |
| 836 } | |
| 837 | |
| 838 | |
| 839 TEST_F(MediaFileSystemRegistryTest, GalleryNameUserAddedPath) { | |
| 840 std::set<std::string> gallery_names; | |
| 841 InitForGalleryNamesTest(&gallery_names); | |
| 842 | |
| 843 std::string device_id = AddUserGallery(MediaStorageUtil::FIXED_MASS_STORAGE, | |
| 844 empty_dir().AsUTF8Unsafe(), | |
| 845 empty_dir()); | |
| 846 // Add permission for new non-default gallery. | |
| 847 ProfileState* profile_state = GetProfileState(0U); | |
| 848 SetGalleryPermission(profile_state, | |
| 849 profile_state->all_permission_extension(), | |
| 850 device_id, | |
| 851 true /*has access*/); | |
| 852 CheckNewGallery(profile_state, gallery_names, | |
| 853 false /*not removable*/, true /*user added*/); | |
| 854 } | |
| 855 | |
| 673 } // namespace | 856 } // namespace |
| 674 | 857 |
| 675 } // namespace chrome | 858 } // namespace chrome |
| OLD | NEW |