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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "chrome/browser/extensions/browser_action_test_util.h" | 11 #include "chrome/browser/extensions/browser_action_test_util.h" |
12 #include "chrome/browser/extensions/extension_action_icon_factory.h" | |
12 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/extensions/extension_action.h" | 22 #include "chrome/common/extensions/extension_action.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; | 134 ASSERT_TRUE(RunExtensionTest("browser_action/no_icon")) << message_; |
134 const Extension* extension = GetSingleLoadedExtension(); | 135 const Extension* extension = GetSingleLoadedExtension(); |
135 ASSERT_TRUE(extension) << message_; | 136 ASSERT_TRUE(extension) << message_; |
136 | 137 |
137 #if defined (OS_MACOSX) | 138 #if defined (OS_MACOSX) |
138 // We need this on mac so we don't loose 2x representations from browser icon | 139 // We need this on mac so we don't loose 2x representations from browser icon |
139 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. | 140 // in transformations gfx::ImageSkia -> NSImage -> gfx::ImageSkia. |
140 gfx::test::SetSupportedScaleFactorsTo1xAnd2x(); | 141 gfx::test::SetSupportedScaleFactorsTo1xAnd2x(); |
141 #endif | 142 #endif |
142 | 143 |
144 // We should not be creating icons asynchronoulsy, so we don't need an | |
Jeffrey Yasskin
2012/09/17 20:18:39
sp: asynchronoulsy
tbarzic
2012/09/17 22:06:10
Done.
| |
145 // observer. | |
146 ExtensionActionIconFactory icon_factory(extension, | |
147 extension->browser_action(), | |
148 NULL); | |
143 // Test that there is a browser action in the toolbar. | 149 // Test that there is a browser action in the toolbar. |
144 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); | 150 ASSERT_EQ(1, GetBrowserActionsBar().NumberOfBrowserActions()); |
145 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); | 151 EXPECT_TRUE(GetBrowserActionsBar().HasIcon(0)); |
146 | 152 |
147 gfx::Image action_icon = extension->browser_action()->GetIcon(0); | 153 gfx::Image action_icon = icon_factory.GetIcon(0); |
148 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); | 154 uint32_t action_icon_last_id = action_icon.ToSkBitmap()->getGenerationID(); |
149 | 155 |
150 // Let's check that |GetIcon| doesn't always return bitmap with new id. | 156 // Let's check that |GetIcon| doesn't always return bitmap with new id. |
151 ASSERT_EQ(action_icon_last_id, | 157 ASSERT_EQ(action_icon_last_id, |
152 extension->browser_action()->GetIcon(0).ToSkBitmap()-> | 158 icon_factory.GetIcon(0).ToSkBitmap()->getGenerationID()); |
153 getGenerationID()); | |
154 | 159 |
155 uint32_t action_icon_current_id = 0; | 160 uint32_t action_icon_current_id = 0; |
156 | 161 |
157 ResultCatcher catcher; | 162 ResultCatcher catcher; |
158 | 163 |
159 // Tell the extension to update the icon using ImageData object. | 164 // Tell the extension to update the icon using ImageData object. |
160 GetBrowserActionsBar().Press(0); | 165 GetBrowserActionsBar().Press(0); |
161 ASSERT_TRUE(catcher.GetNextResult()); | 166 ASSERT_TRUE(catcher.GetNextResult()); |
162 | 167 |
163 action_icon = extension->browser_action()->GetIcon(0); | 168 action_icon = icon_factory.GetIcon(0); |
164 | 169 |
165 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 170 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
166 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 171 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
167 action_icon_last_id = action_icon_current_id; | 172 action_icon_last_id = action_icon_current_id; |
168 | 173 |
169 EXPECT_FALSE( | 174 EXPECT_FALSE( |
170 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 175 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
171 | 176 |
172 EXPECT_TRUE(ImagesAreEqualAtScale( | 177 EXPECT_TRUE(ImagesAreEqualAtScale( |
173 AddBackgroundForViews(*action_icon.ToImageSkia()), | 178 AddBackgroundForViews(*action_icon.ToImageSkia()), |
174 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 179 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
175 ui::SCALE_FACTOR_100P)); | 180 ui::SCALE_FACTOR_100P)); |
176 | 181 |
177 // Tell the extension to update the icon using path. | 182 // Tell the extension to update the icon using path. |
178 GetBrowserActionsBar().Press(0); | 183 GetBrowserActionsBar().Press(0); |
179 ASSERT_TRUE(catcher.GetNextResult()); | 184 ASSERT_TRUE(catcher.GetNextResult()); |
180 | 185 |
181 action_icon = extension->browser_action()->GetIcon(0); | 186 action_icon = icon_factory.GetIcon(0); |
182 | 187 |
183 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 188 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
184 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 189 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
185 action_icon_last_id = action_icon_current_id; | 190 action_icon_last_id = action_icon_current_id; |
186 | 191 |
187 EXPECT_FALSE( | 192 EXPECT_FALSE( |
188 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 193 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
189 | 194 |
190 EXPECT_TRUE(ImagesAreEqualAtScale( | 195 EXPECT_TRUE(ImagesAreEqualAtScale( |
191 AddBackgroundForViews(*action_icon.ToImageSkia()), | 196 AddBackgroundForViews(*action_icon.ToImageSkia()), |
192 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 197 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
193 ui::SCALE_FACTOR_100P)); | 198 ui::SCALE_FACTOR_100P)); |
194 | 199 |
195 // Tell the extension to update the icon using dictionary of ImageData | 200 // Tell the extension to update the icon using dictionary of ImageData |
196 // objects. | 201 // objects. |
197 GetBrowserActionsBar().Press(0); | 202 GetBrowserActionsBar().Press(0); |
198 ASSERT_TRUE(catcher.GetNextResult()); | 203 ASSERT_TRUE(catcher.GetNextResult()); |
199 | 204 |
200 action_icon = extension->browser_action()->GetIcon(0); | 205 action_icon = icon_factory.GetIcon(0); |
201 | 206 |
202 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 207 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
203 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 208 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
204 action_icon_last_id = action_icon_current_id; | 209 action_icon_last_id = action_icon_current_id; |
205 | 210 |
206 EXPECT_TRUE( | 211 EXPECT_TRUE( |
207 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 212 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
208 | 213 |
209 EXPECT_TRUE(ImagesAreEqualAtScale( | 214 EXPECT_TRUE(ImagesAreEqualAtScale( |
210 AddBackgroundForViews(*action_icon.ToImageSkia()), | 215 AddBackgroundForViews(*action_icon.ToImageSkia()), |
211 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 216 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
212 ui::SCALE_FACTOR_100P)); | 217 ui::SCALE_FACTOR_100P)); |
213 | 218 |
214 // Tell the extension to update the icon using dictionary of paths. | 219 // Tell the extension to update the icon using dictionary of paths. |
215 GetBrowserActionsBar().Press(0); | 220 GetBrowserActionsBar().Press(0); |
216 ASSERT_TRUE(catcher.GetNextResult()); | 221 ASSERT_TRUE(catcher.GetNextResult()); |
217 | 222 |
218 action_icon = extension->browser_action()->GetIcon(0); | 223 action_icon = icon_factory.GetIcon(0); |
219 | 224 |
220 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 225 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
221 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 226 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
222 action_icon_last_id = action_icon_current_id; | 227 action_icon_last_id = action_icon_current_id; |
223 | 228 |
224 EXPECT_TRUE( | 229 EXPECT_TRUE( |
225 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 230 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
226 | 231 |
227 EXPECT_TRUE(ImagesAreEqualAtScale( | 232 EXPECT_TRUE(ImagesAreEqualAtScale( |
228 AddBackgroundForViews(*action_icon.ToImageSkia()), | 233 AddBackgroundForViews(*action_icon.ToImageSkia()), |
229 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 234 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
230 ui::SCALE_FACTOR_100P)); | 235 ui::SCALE_FACTOR_100P)); |
231 | 236 |
232 // Tell the extension to update the icon using dictionary of ImageData | 237 // Tell the extension to update the icon using dictionary of ImageData |
233 // objects, but setting only size 19. | 238 // objects, but setting only size 19. |
234 GetBrowserActionsBar().Press(0); | 239 GetBrowserActionsBar().Press(0); |
235 ASSERT_TRUE(catcher.GetNextResult()); | 240 ASSERT_TRUE(catcher.GetNextResult()); |
236 | 241 |
237 action_icon = extension->browser_action()->GetIcon(0); | 242 action_icon = icon_factory.GetIcon(0); |
238 | 243 |
239 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 244 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
240 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 245 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
241 action_icon_last_id = action_icon_current_id; | 246 action_icon_last_id = action_icon_current_id; |
242 | 247 |
243 EXPECT_FALSE( | 248 EXPECT_FALSE( |
244 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 249 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
245 | 250 |
246 EXPECT_TRUE(ImagesAreEqualAtScale( | 251 EXPECT_TRUE(ImagesAreEqualAtScale( |
247 AddBackgroundForViews(*action_icon.ToImageSkia()), | 252 AddBackgroundForViews(*action_icon.ToImageSkia()), |
248 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 253 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
249 ui::SCALE_FACTOR_100P)); | 254 ui::SCALE_FACTOR_100P)); |
250 | 255 |
251 // Tell the extension to update the icon using dictionary of paths, but | 256 // Tell the extension to update the icon using dictionary of paths, but |
252 // setting only size 19. | 257 // setting only size 19. |
253 GetBrowserActionsBar().Press(0); | 258 GetBrowserActionsBar().Press(0); |
254 ASSERT_TRUE(catcher.GetNextResult()); | 259 ASSERT_TRUE(catcher.GetNextResult()); |
255 | 260 |
256 action_icon = extension->browser_action()->GetIcon(0); | 261 action_icon = icon_factory.GetIcon(0); |
257 | 262 |
258 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 263 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
259 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 264 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
260 action_icon_last_id = action_icon_current_id; | 265 action_icon_last_id = action_icon_current_id; |
261 | 266 |
262 EXPECT_FALSE( | 267 EXPECT_FALSE( |
263 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); | 268 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P)); |
264 | 269 |
265 EXPECT_TRUE(ImagesAreEqualAtScale( | 270 EXPECT_TRUE(ImagesAreEqualAtScale( |
266 AddBackgroundForViews(*action_icon.ToImageSkia()), | 271 AddBackgroundForViews(*action_icon.ToImageSkia()), |
267 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), | 272 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), |
268 ui::SCALE_FACTOR_100P)); | 273 ui::SCALE_FACTOR_100P)); |
269 | 274 |
270 // Tell the extension to update the icon using dictionary of ImageData | 275 // Tell the extension to update the icon using dictionary of ImageData |
271 // objects, but setting only size 38. | 276 // objects, but setting only size 38. |
272 GetBrowserActionsBar().Press(0); | 277 GetBrowserActionsBar().Press(0); |
273 ASSERT_TRUE(catcher.GetNextResult()); | 278 ASSERT_TRUE(catcher.GetNextResult()); |
274 | 279 |
275 action_icon = extension->browser_action()->GetIcon(0); | 280 action_icon = icon_factory.GetIcon(0); |
276 | 281 |
277 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); | 282 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia(); |
278 | 283 |
279 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P)); | 284 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P)); |
280 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P)); | 285 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P)); |
281 | 286 |
282 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); | 287 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); |
283 EXPECT_GT(action_icon_current_id, action_icon_last_id); | 288 EXPECT_GT(action_icon_current_id, action_icon_last_id); |
284 action_icon_last_id = action_icon_current_id; | 289 action_icon_last_id = action_icon_current_id; |
285 | 290 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 GURL(extension->GetResourceURL("update.html"))); | 649 GURL(extension->GetResourceURL("update.html"))); |
645 ASSERT_TRUE(catcher.GetNextResult()); | 650 ASSERT_TRUE(catcher.GetNextResult()); |
646 | 651 |
647 // Test the getters for a specific tab. | 652 // Test the getters for a specific tab. |
648 ui_test_utils::NavigateToURL(browser(), | 653 ui_test_utils::NavigateToURL(browser(), |
649 GURL(extension->GetResourceURL("update2.html"))); | 654 GURL(extension->GetResourceURL("update2.html"))); |
650 ASSERT_TRUE(catcher.GetNextResult()); | 655 ASSERT_TRUE(catcher.GetNextResult()); |
651 } | 656 } |
652 | 657 |
653 } // namespace | 658 } // namespace |
OLD | NEW |