| 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 // MediaGalleriesPreferences unit tests. | 5 // MediaGalleriesPreferences unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
| 18 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 18 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 19 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 19 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 20 #include "chrome/browser/storage_monitor/media_storage_util.h" | 20 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 21 #include "chrome/browser/storage_monitor/storage_monitor.h" | 21 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 22 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | 22 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
| 23 #include "chrome/common/extensions/background_info.h" | 23 #include "chrome/common/extensions/background_info.h" |
| 24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_unittest.h" | |
| 26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
| 28 #include "sync/api/string_ordinal.h" | 27 #include "sync/api/string_ordinal.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 32 #include "chrome/browser/chromeos/login/user_manager.h" | 31 #include "chrome/browser/chromeos/login/user_manager.h" |
| 33 #include "chrome/browser/chromeos/settings/cros_settings.h" | 32 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 34 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 33 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 35 #endif | 34 #endif |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 } | 56 } |
| 58 | 57 |
| 59 MediaGalleriesPreferences* pref_; | 58 MediaGalleriesPreferences* pref_; |
| 60 int notifications_; | 59 int notifications_; |
| 61 | 60 |
| 62 DISALLOW_COPY_AND_ASSIGN(MockGalleryChangeObserver); | 61 DISALLOW_COPY_AND_ASSIGN(MockGalleryChangeObserver); |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 } // namespace | 64 } // namespace |
| 66 | 65 |
| 67 class MediaGalleriesPreferencesTest : public extensions::ExtensionTest { | 66 class MediaGalleriesPreferencesTest : public testing::Test { |
| 68 public: | 67 public: |
| 69 typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet> | 68 typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet> |
| 70 DeviceIdPrefIdsMap; | 69 DeviceIdPrefIdsMap; |
| 71 | 70 |
| 72 MediaGalleriesPreferencesTest() | 71 MediaGalleriesPreferencesTest() |
| 73 : ui_thread_(content::BrowserThread::UI, &loop_), | 72 : ui_thread_(content::BrowserThread::UI, &loop_), |
| 74 file_thread_(content::BrowserThread::FILE, &loop_), | 73 file_thread_(content::BrowserThread::FILE, &loop_), |
| 75 profile_(new TestingProfile()), | 74 profile_(new TestingProfile()), |
| 76 default_galleries_count_(0) { | 75 default_galleries_count_(0) { |
| 77 } | 76 } |
| 78 | 77 |
| 79 virtual ~MediaGalleriesPreferencesTest() { | 78 virtual ~MediaGalleriesPreferencesTest() { |
| 80 // TestExtensionSystem uses DeleteSoon, so we need to delete the profile | 79 // TestExtensionSystem uses DeleteSoon, so we need to delete the profile |
| 81 // and then run the message queue to clean up. | 80 // and then run the message queue to clean up. |
| 82 profile_.reset(); | 81 profile_.reset(); |
| 83 MessageLoop::current()->RunUntilIdle(); | 82 MessageLoop::current()->RunUntilIdle(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 virtual void SetUp() OVERRIDE { | 85 virtual void SetUp() OVERRIDE { |
| 87 extensions::ExtensionTest::SetUp(); | |
| 88 | |
| 89 extensions::TestExtensionSystem* extension_system( | 86 extensions::TestExtensionSystem* extension_system( |
| 90 static_cast<extensions::TestExtensionSystem*>( | 87 static_cast<extensions::TestExtensionSystem*>( |
| 91 extensions::ExtensionSystem::Get(profile_.get()))); | 88 extensions::ExtensionSystem::Get(profile_.get()))); |
| 92 extension_system->CreateExtensionService( | 89 extension_system->CreateExtensionService( |
| 93 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 90 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 94 | 91 |
| 95 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); | 92 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); |
| 96 | 93 |
| 97 // Load the default galleries into the expectations. | 94 // Load the default galleries into the expectations. |
| 98 const MediaGalleriesPrefInfoMap& known_galleries = | 95 const MediaGalleriesPrefInfoMap& known_galleries = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 all_permission_extension = | 114 all_permission_extension = |
| 118 AddMediaGalleriesApp("all", all_permissions, profile_.get()); | 115 AddMediaGalleriesApp("all", all_permissions, profile_.get()); |
| 119 regular_permission_extension = | 116 regular_permission_extension = |
| 120 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); | 117 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); |
| 121 no_permissions_extension = | 118 no_permissions_extension = |
| 122 AddMediaGalleriesApp("no", read_permissions, profile_.get()); | 119 AddMediaGalleriesApp("no", read_permissions, profile_.get()); |
| 123 } | 120 } |
| 124 | 121 |
| 125 virtual void TearDown() OVERRIDE { | 122 virtual void TearDown() OVERRIDE { |
| 126 Verify(); | 123 Verify(); |
| 127 extensions::ExtensionTest::TearDown(); | |
| 128 } | 124 } |
| 129 | 125 |
| 130 void Verify() { | 126 void Verify() { |
| 131 const MediaGalleriesPrefInfoMap& known_galleries = | 127 const MediaGalleriesPrefInfoMap& known_galleries = |
| 132 gallery_prefs_->known_galleries(); | 128 gallery_prefs_->known_galleries(); |
| 133 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); | 129 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); |
| 134 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); | 130 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); |
| 135 it != known_galleries.end(); | 131 it != known_galleries.end(); |
| 136 ++it) { | 132 ++it) { |
| 137 VerifyGalleryInfo(it->second, it->first); | 133 VerifyGalleryInfo(it->second, it->first); |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // Remove a user added gallery and it should go away. | 724 // Remove a user added gallery and it should go away. |
| 729 gallery_prefs()->ForgetGalleryById(user_added_id); | 725 gallery_prefs()->ForgetGalleryById(user_added_id); |
| 730 expected_galleries_.erase(user_added_id); | 726 expected_galleries_.erase(user_added_id); |
| 731 expected_device_map[info.device_id].erase(user_added_id); | 727 expected_device_map[info.device_id].erase(user_added_id); |
| 732 | 728 |
| 733 EXPECT_EQ(2, observer1.notifications()); | 729 EXPECT_EQ(2, observer1.notifications()); |
| 734 EXPECT_EQ(3, observer2.notifications()); | 730 EXPECT_EQ(3, observer2.notifications()); |
| 735 } | 731 } |
| 736 | 732 |
| 737 } // namespace chrome | 733 } // namespace chrome |
| OLD | NEW |