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 #include "base/json/json_file_value_serializer.h" | 5 #include "base/json/json_file_value_serializer.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Returns the default icon that ExtensionIconManager gives when an extension | 95 // Returns the default icon that ExtensionIconManager gives when an extension |
96 // doesn't have an icon. | 96 // doesn't have an icon. |
97 SkBitmap GetDefaultIcon() { | 97 SkBitmap GetDefaultIcon() { |
98 std::string dummy_id = crx_file::id_util::GenerateId("whatever"); | 98 std::string dummy_id = crx_file::id_util::GenerateId("whatever"); |
99 ExtensionIconManager manager; | 99 ExtensionIconManager manager; |
100 return manager.GetIcon(dummy_id); | 100 return manager.GetIcon(dummy_id); |
101 } | 101 } |
102 | 102 |
103 // Tests loading an icon for an extension, removing it, then re-loading it. | 103 // Tests loading an icon for an extension, removing it, then re-loading it. |
104 TEST_F(ExtensionIconManagerTest, LoadRemoveLoad) { | 104 TEST_F(ExtensionIconManagerTest, LoadRemoveLoad) { |
105 scoped_ptr<Profile> profile(new TestingProfile()); | 105 std::unique_ptr<Profile> profile(new TestingProfile()); |
106 SkBitmap default_icon = GetDefaultIcon(); | 106 SkBitmap default_icon = GetDefaultIcon(); |
107 | 107 |
108 base::FilePath test_dir; | 108 base::FilePath test_dir; |
109 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); | 109 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
110 base::FilePath manifest_path = test_dir.AppendASCII( | 110 base::FilePath manifest_path = test_dir.AppendASCII( |
111 "extensions/image_loading_tracker/app.json"); | 111 "extensions/image_loading_tracker/app.json"); |
112 | 112 |
113 JSONFileValueDeserializer deserializer(manifest_path); | 113 JSONFileValueDeserializer deserializer(manifest_path); |
114 scoped_ptr<base::DictionaryValue> manifest = | 114 std::unique_ptr<base::DictionaryValue> manifest = |
115 base::DictionaryValue::From(deserializer.Deserialize(NULL, NULL)); | 115 base::DictionaryValue::From(deserializer.Deserialize(NULL, NULL)); |
116 ASSERT_TRUE(manifest.get() != NULL); | 116 ASSERT_TRUE(manifest.get() != NULL); |
117 | 117 |
118 std::string error; | 118 std::string error; |
119 scoped_refptr<Extension> extension(Extension::Create( | 119 scoped_refptr<Extension> extension(Extension::Create( |
120 manifest_path.DirName(), Manifest::INVALID_LOCATION, *manifest.get(), | 120 manifest_path.DirName(), Manifest::INVALID_LOCATION, *manifest.get(), |
121 Extension::NO_FLAGS, &error)); | 121 Extension::NO_FLAGS, &error)); |
122 ASSERT_TRUE(extension.get()); | 122 ASSERT_TRUE(extension.get()); |
123 TestIconManager icon_manager(this); | 123 TestIconManager icon_manager(this); |
124 | 124 |
(...skipping 12 matching lines...) Expand all Loading... |
137 WaitForImageLoad(); | 137 WaitForImageLoad(); |
138 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); | 138 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); |
139 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); | 139 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); |
140 | 140 |
141 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); | 141 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); |
142 } | 142 } |
143 | 143 |
144 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
145 // Tests loading an icon for a component extension. | 145 // Tests loading an icon for a component extension. |
146 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) { | 146 TEST_F(ExtensionIconManagerTest, LoadComponentExtensionResource) { |
147 scoped_ptr<Profile> profile(new TestingProfile()); | 147 std::unique_ptr<Profile> profile(new TestingProfile()); |
148 SkBitmap default_icon = GetDefaultIcon(); | 148 SkBitmap default_icon = GetDefaultIcon(); |
149 | 149 |
150 base::FilePath test_dir; | 150 base::FilePath test_dir; |
151 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); | 151 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); |
152 base::FilePath manifest_path = test_dir.AppendASCII( | 152 base::FilePath manifest_path = test_dir.AppendASCII( |
153 "extensions/file_manager/app.json"); | 153 "extensions/file_manager/app.json"); |
154 | 154 |
155 JSONFileValueDeserializer deserializer(manifest_path); | 155 JSONFileValueDeserializer deserializer(manifest_path); |
156 scoped_ptr<base::DictionaryValue> manifest = | 156 std::unique_ptr<base::DictionaryValue> manifest = |
157 base::DictionaryValue::From(deserializer.Deserialize(NULL, NULL)); | 157 base::DictionaryValue::From(deserializer.Deserialize(NULL, NULL)); |
158 ASSERT_TRUE(manifest.get() != NULL); | 158 ASSERT_TRUE(manifest.get() != NULL); |
159 | 159 |
160 std::string error; | 160 std::string error; |
161 scoped_refptr<Extension> extension(Extension::Create( | 161 scoped_refptr<Extension> extension(Extension::Create( |
162 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(), | 162 manifest_path.DirName(), Manifest::COMPONENT, *manifest.get(), |
163 Extension::NO_FLAGS, &error)); | 163 Extension::NO_FLAGS, &error)); |
164 ASSERT_TRUE(extension.get()); | 164 ASSERT_TRUE(extension.get()); |
165 | 165 |
166 TestIconManager icon_manager(this); | 166 TestIconManager icon_manager(this); |
167 // Load the icon and grab the bitmap. | 167 // Load the icon and grab the bitmap. |
168 icon_manager.LoadIcon(profile.get(), extension.get()); | 168 icon_manager.LoadIcon(profile.get(), extension.get()); |
169 WaitForImageLoad(); | 169 WaitForImageLoad(); |
170 SkBitmap first_icon = icon_manager.GetIcon(extension->id()); | 170 SkBitmap first_icon = icon_manager.GetIcon(extension->id()); |
171 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon)); | 171 EXPECT_FALSE(gfx::BitmapsAreEqual(first_icon, default_icon)); |
172 | 172 |
173 // Remove the icon from the manager. | 173 // Remove the icon from the manager. |
174 icon_manager.RemoveIcon(extension->id()); | 174 icon_manager.RemoveIcon(extension->id()); |
175 | 175 |
176 // Now re-load the icon - we should get the same result bitmap (and not the | 176 // Now re-load the icon - we should get the same result bitmap (and not the |
177 // default icon). | 177 // default icon). |
178 icon_manager.LoadIcon(profile.get(), extension.get()); | 178 icon_manager.LoadIcon(profile.get(), extension.get()); |
179 WaitForImageLoad(); | 179 WaitForImageLoad(); |
180 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); | 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); |
181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); | 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); |
182 | 182 |
183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); | 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); |
184 } | 184 } |
185 #endif | 185 #endif |
OLD | NEW |