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/common/extensions/background_info.h" |
21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/manifest_handler.h" |
22 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
23 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
24 #include "sync/api/string_ordinal.h" | 26 #include "sync/api/string_ordinal.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 namespace chrome { | 29 namespace chrome { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 class MediaStorageUtilTest : public MediaStorageUtil { | 33 class MediaStorageUtilTest : public MediaStorageUtil { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 profile_.reset(); | 96 profile_.reset(); |
95 MessageLoop::current()->RunUntilIdle(); | 97 MessageLoop::current()->RunUntilIdle(); |
96 } | 98 } |
97 | 99 |
98 virtual void SetUp() OVERRIDE { | 100 virtual void SetUp() OVERRIDE { |
99 extensions::TestExtensionSystem* extension_system( | 101 extensions::TestExtensionSystem* extension_system( |
100 static_cast<extensions::TestExtensionSystem*>( | 102 static_cast<extensions::TestExtensionSystem*>( |
101 extensions::ExtensionSystem::Get(profile_.get()))); | 103 extensions::ExtensionSystem::Get(profile_.get()))); |
102 extension_system->CreateExtensionService( | 104 extension_system->CreateExtensionService( |
103 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 105 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 106 (new extensions::BackgroundManifestHandler)->Register(); |
104 | 107 |
105 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); | 108 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); |
106 | 109 |
107 // Load the default galleries into the expectations. | 110 // Load the default galleries into the expectations. |
108 const MediaGalleriesPrefInfoMap& known_galleries = | 111 const MediaGalleriesPrefInfoMap& known_galleries = |
109 gallery_prefs_->known_galleries(); | 112 gallery_prefs_->known_galleries(); |
110 if (known_galleries.size()) { | 113 if (known_galleries.size()) { |
111 ASSERT_EQ(3U, known_galleries.size()); | 114 ASSERT_EQ(3U, known_galleries.size()); |
112 default_galleries_count_ = 3; | 115 default_galleries_count_ = 3; |
113 MediaGalleriesPrefInfoMap::const_iterator it; | 116 MediaGalleriesPrefInfoMap::const_iterator it; |
(...skipping 13 matching lines...) Expand all Loading... |
127 all_permission_extension = | 130 all_permission_extension = |
128 AddMediaGalleriesApp("all", all_permissions, profile_.get()); | 131 AddMediaGalleriesApp("all", all_permissions, profile_.get()); |
129 regular_permission_extension = | 132 regular_permission_extension = |
130 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); | 133 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); |
131 no_permissions_extension = | 134 no_permissions_extension = |
132 AddMediaGalleriesApp("no", read_permissions, profile_.get()); | 135 AddMediaGalleriesApp("no", read_permissions, profile_.get()); |
133 } | 136 } |
134 | 137 |
135 virtual void TearDown() OVERRIDE { | 138 virtual void TearDown() OVERRIDE { |
136 Verify(); | 139 Verify(); |
| 140 extensions::ManifestHandler::ClearRegistryForTesting(); |
137 } | 141 } |
138 | 142 |
139 void Verify() { | 143 void Verify() { |
140 const MediaGalleriesPrefInfoMap& known_galleries = | 144 const MediaGalleriesPrefInfoMap& known_galleries = |
141 gallery_prefs_->known_galleries(); | 145 gallery_prefs_->known_galleries(); |
142 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); | 146 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); |
143 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); | 147 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); |
144 it != known_galleries.end(); | 148 it != known_galleries.end(); |
145 ++it) { | 149 ++it) { |
146 VerifyGalleryInfo(it->second, it->first); | 150 VerifyGalleryInfo(it->second, it->first); |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // Remove a user added gallery and it should go away. | 741 // Remove a user added gallery and it should go away. |
738 gallery_prefs()->ForgetGalleryById(user_added_id); | 742 gallery_prefs()->ForgetGalleryById(user_added_id); |
739 expected_galleries_.erase(user_added_id); | 743 expected_galleries_.erase(user_added_id); |
740 expected_device_map[device_id].erase(user_added_id); | 744 expected_device_map[device_id].erase(user_added_id); |
741 | 745 |
742 EXPECT_EQ(2, observer1.notifications()); | 746 EXPECT_EQ(2, observer1.notifications()); |
743 EXPECT_EQ(3, observer2.notifications()); | 747 EXPECT_EQ(3, observer2.notifications()); |
744 } | 748 } |
745 | 749 |
746 } // namespace chrome | 750 } // namespace chrome |
OLD | NEW |