Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 11232049: Revert 162636 - Use LANCZOS3 resize algorithm to generate missing image reps for extension action i… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_actions_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
29 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
32 #include "ui/gfx/size.h" 32 #include "ui/gfx/size.h"
33 #include "ui/gfx/size_conversions.h"
34 #include "ui/gfx/image/image_skia.h" 33 #include "ui/gfx/image/image_skia.h"
35 #include "ui/gfx/image/image_skia_operations.h" 34 #include "ui/gfx/image/image_skia_operations.h"
36 #include "ui/gfx/skia_util.h" 35 #include "ui/gfx/skia_util.h"
37 36
38 #if defined (OS_MACOSX) 37 #if defined (OS_MACOSX)
39 #include "ui/gfx/image/image_unittest_util.h" 38 #include "ui/gfx/image/image_unittest_util.h"
40 #endif 39 #endif
41 40
42 using content::WebContents; 41 using content::WebContents;
43 42
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Tell the extension to update the icon using ImageData object. 162 // Tell the extension to update the icon using ImageData object.
164 GetBrowserActionsBar().Press(0); 163 GetBrowserActionsBar().Press(0);
165 ASSERT_TRUE(catcher.GetNextResult()); 164 ASSERT_TRUE(catcher.GetNextResult());
166 165
167 action_icon = icon_factory.GetIcon(0); 166 action_icon = icon_factory.GetIcon(0);
168 167
169 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 168 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
170 EXPECT_GT(action_icon_current_id, action_icon_last_id); 169 EXPECT_GT(action_icon_current_id, action_icon_last_id);
171 action_icon_last_id = action_icon_current_id; 170 action_icon_last_id = action_icon_current_id;
172 171
172 EXPECT_FALSE(
173 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
174
173 EXPECT_TRUE(ImagesAreEqualAtScale( 175 EXPECT_TRUE(ImagesAreEqualAtScale(
174 AddBackgroundForViews(*action_icon.ToImageSkia()), 176 AddBackgroundForViews(*action_icon.ToImageSkia()),
175 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 177 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
176 ui::SCALE_FACTOR_100P)); 178 ui::SCALE_FACTOR_100P));
177 179
178 // Tell the extension to update the icon using path. 180 // Tell the extension to update the icon using path.
179 GetBrowserActionsBar().Press(0); 181 GetBrowserActionsBar().Press(0);
180 ASSERT_TRUE(catcher.GetNextResult()); 182 ASSERT_TRUE(catcher.GetNextResult());
181 183
182 action_icon = icon_factory.GetIcon(0); 184 action_icon = icon_factory.GetIcon(0);
183 185
184 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 186 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
185 EXPECT_GT(action_icon_current_id, action_icon_last_id); 187 EXPECT_GT(action_icon_current_id, action_icon_last_id);
186 action_icon_last_id = action_icon_current_id; 188 action_icon_last_id = action_icon_current_id;
187 189
190 EXPECT_FALSE(
191 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
192
188 EXPECT_TRUE(ImagesAreEqualAtScale( 193 EXPECT_TRUE(ImagesAreEqualAtScale(
189 AddBackgroundForViews(*action_icon.ToImageSkia()), 194 AddBackgroundForViews(*action_icon.ToImageSkia()),
190 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 195 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
191 ui::SCALE_FACTOR_100P)); 196 ui::SCALE_FACTOR_100P));
192 197
193 // Tell the extension to update the icon using dictionary of ImageData 198 // Tell the extension to update the icon using dictionary of ImageData
194 // objects. 199 // objects.
195 GetBrowserActionsBar().Press(0); 200 GetBrowserActionsBar().Press(0);
196 ASSERT_TRUE(catcher.GetNextResult()); 201 ASSERT_TRUE(catcher.GetNextResult());
197 202
198 action_icon = icon_factory.GetIcon(0); 203 action_icon = icon_factory.GetIcon(0);
199 204
200 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 205 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
201 EXPECT_GT(action_icon_current_id, action_icon_last_id); 206 EXPECT_GT(action_icon_current_id, action_icon_last_id);
202 action_icon_last_id = action_icon_current_id; 207 action_icon_last_id = action_icon_current_id;
203 208
209 EXPECT_TRUE(
210 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
211
204 EXPECT_TRUE(ImagesAreEqualAtScale( 212 EXPECT_TRUE(ImagesAreEqualAtScale(
205 AddBackgroundForViews(*action_icon.ToImageSkia()), 213 AddBackgroundForViews(*action_icon.ToImageSkia()),
206 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 214 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
207 ui::SCALE_FACTOR_100P)); 215 ui::SCALE_FACTOR_100P));
208 216
209 // Tell the extension to update the icon using dictionary of paths. 217 // Tell the extension to update the icon using dictionary of paths.
210 GetBrowserActionsBar().Press(0); 218 GetBrowserActionsBar().Press(0);
211 ASSERT_TRUE(catcher.GetNextResult()); 219 ASSERT_TRUE(catcher.GetNextResult());
212 220
213 action_icon = icon_factory.GetIcon(0); 221 action_icon = icon_factory.GetIcon(0);
214 222
215 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 223 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
216 EXPECT_GT(action_icon_current_id, action_icon_last_id); 224 EXPECT_GT(action_icon_current_id, action_icon_last_id);
217 action_icon_last_id = action_icon_current_id; 225 action_icon_last_id = action_icon_current_id;
218 226
227 EXPECT_TRUE(
228 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
229
219 EXPECT_TRUE(ImagesAreEqualAtScale( 230 EXPECT_TRUE(ImagesAreEqualAtScale(
220 AddBackgroundForViews(*action_icon.ToImageSkia()), 231 AddBackgroundForViews(*action_icon.ToImageSkia()),
221 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 232 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
222 ui::SCALE_FACTOR_100P)); 233 ui::SCALE_FACTOR_100P));
223 234
224 // Tell the extension to update the icon using dictionary of ImageData 235 // Tell the extension to update the icon using dictionary of ImageData
225 // objects, but setting only size 19. 236 // objects, but setting only size 19.
226 GetBrowserActionsBar().Press(0); 237 GetBrowserActionsBar().Press(0);
227 ASSERT_TRUE(catcher.GetNextResult()); 238 ASSERT_TRUE(catcher.GetNextResult());
228 239
229 action_icon = icon_factory.GetIcon(0); 240 action_icon = icon_factory.GetIcon(0);
230 241
231 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 242 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
232 EXPECT_GT(action_icon_current_id, action_icon_last_id); 243 EXPECT_GT(action_icon_current_id, action_icon_last_id);
233 action_icon_last_id = action_icon_current_id; 244 action_icon_last_id = action_icon_current_id;
234 245
246 EXPECT_FALSE(
247 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
248
235 EXPECT_TRUE(ImagesAreEqualAtScale( 249 EXPECT_TRUE(ImagesAreEqualAtScale(
236 AddBackgroundForViews(*action_icon.ToImageSkia()), 250 AddBackgroundForViews(*action_icon.ToImageSkia()),
237 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 251 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
238 ui::SCALE_FACTOR_100P)); 252 ui::SCALE_FACTOR_100P));
239 253
240 const float scale = ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P);
241 const gfx::Size scaled_up_pixel_size = gfx::ToFlooredSize(
242 action_icon.ToImageSkia()->size().Scale(scale));
243
244 SkBitmap action_icon_scaled_up = skia::ImageOperations::Resize(
245 *action_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_LANCZOS3,
246 scaled_up_pixel_size.width(), scaled_up_pixel_size.height());
247
248 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
249 EXPECT_TRUE(gfx::BitmapsAreEqual(
250 action_icon_scaled_up,
251 action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
252
253 // Tell the extension to update the icon using dictionary of paths, but 254 // Tell the extension to update the icon using dictionary of paths, but
254 // setting only size 19. 255 // setting only size 19.
255 GetBrowserActionsBar().Press(0); 256 GetBrowserActionsBar().Press(0);
256 ASSERT_TRUE(catcher.GetNextResult()); 257 ASSERT_TRUE(catcher.GetNextResult());
257 258
258 action_icon = icon_factory.GetIcon(0); 259 action_icon = icon_factory.GetIcon(0);
259 260
260 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 261 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
261 EXPECT_GT(action_icon_current_id, action_icon_last_id); 262 EXPECT_GT(action_icon_current_id, action_icon_last_id);
262 action_icon_last_id = action_icon_current_id; 263 action_icon_last_id = action_icon_current_id;
263 264
265 EXPECT_FALSE(
266 action_icon.ToImageSkia()->HasRepresentation(ui::SCALE_FACTOR_200P));
267
264 EXPECT_TRUE(ImagesAreEqualAtScale( 268 EXPECT_TRUE(ImagesAreEqualAtScale(
265 AddBackgroundForViews(*action_icon.ToImageSkia()), 269 AddBackgroundForViews(*action_icon.ToImageSkia()),
266 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 270 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
267 ui::SCALE_FACTOR_100P)); 271 ui::SCALE_FACTOR_100P));
268 272
269 // Tell the extension to update the icon using dictionary of ImageData 273 // Tell the extension to update the icon using dictionary of ImageData
270 // objects, but setting only size 38. 274 // objects, but setting only size 38.
271 GetBrowserActionsBar().Press(0); 275 GetBrowserActionsBar().Press(0);
272 ASSERT_TRUE(catcher.GetNextResult()); 276 ASSERT_TRUE(catcher.GetNextResult());
273 277
274 action_icon = icon_factory.GetIcon(0); 278 action_icon = icon_factory.GetIcon(0);
275 279
280 const gfx::ImageSkia* action_icon_skia = action_icon.ToImageSkia();
281
282 EXPECT_FALSE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_100P));
283 EXPECT_TRUE(action_icon_skia->HasRepresentation(ui::SCALE_FACTOR_200P));
284
276 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID(); 285 action_icon_current_id = action_icon.ToSkBitmap()->getGenerationID();
277 EXPECT_GT(action_icon_current_id, action_icon_last_id); 286 EXPECT_GT(action_icon_current_id, action_icon_last_id);
278 action_icon_last_id = action_icon_current_id; 287 action_icon_last_id = action_icon_current_id;
279 288
289 EXPECT_TRUE(gfx::BitmapsAreEqual(
290 *action_icon.ToSkBitmap(),
291 action_icon_skia->GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap()));
292
280 EXPECT_TRUE(ImagesAreEqualAtScale( 293 EXPECT_TRUE(ImagesAreEqualAtScale(
281 AddBackgroundForViews(*action_icon.ToImageSkia()), 294 AddBackgroundForViews(*action_icon_skia),
282 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
283 ui::SCALE_FACTOR_100P));
284
285 #if !defined(TOOLKIT_GTK)
286 EXPECT_TRUE(ImagesAreEqualAtScale(
287 AddBackgroundForViews(*action_icon.ToImageSkia()),
288 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(), 295 *GetBrowserActionsBar().GetIcon(0).ToImageSkia(),
289 ui::SCALE_FACTOR_200P)); 296 ui::SCALE_FACTOR_200P));
290 #endif
291 297
292 // Try setting icon with empty dictionary of ImageData objects. 298 // Try setting icon with empty dictionary of ImageData objects.
293 GetBrowserActionsBar().Press(0); 299 GetBrowserActionsBar().Press(0);
294 ASSERT_FALSE(catcher.GetNextResult()); 300 ASSERT_FALSE(catcher.GetNextResult());
295 EXPECT_EQ(kEmptyImageDataError, catcher.message()); 301 EXPECT_EQ(kEmptyImageDataError, catcher.message());
296 302
297 // Try setting icon with empty dictionary of path objects. 303 // Try setting icon with empty dictionary of path objects.
298 GetBrowserActionsBar().Press(0); 304 GetBrowserActionsBar().Press(0);
299 ASSERT_FALSE(catcher.GetNextResult()); 305 ASSERT_FALSE(catcher.GetNextResult());
300 EXPECT_EQ(kEmptyPathError, catcher.message()); 306 EXPECT_EQ(kEmptyPathError, catcher.message());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 ASSERT_TRUE(catcher.GetNextResult()); 646 ASSERT_TRUE(catcher.GetNextResult());
641 647
642 // Test the getters for a specific tab. 648 // Test the getters for a specific tab.
643 ui_test_utils::NavigateToURL(browser(), 649 ui_test_utils::NavigateToURL(browser(),
644 GURL(extension->GetResourceURL("update2.html"))); 650 GURL(extension->GetResourceURL("update2.html")));
645 ASSERT_TRUE(catcher.GetNextResult()); 651 ASSERT_TRUE(catcher.GetNextResult());
646 } 652 }
647 653
648 } // namespace 654 } // namespace
649 } // namespace extensions 655 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/extension_action/extension_actions_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698