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

Side by Side Diff: extensions/browser/extension_icon_image_unittest.cc

Issue 882243002: [Extensions] Make extension actions use gfx::Image over gfx::ImageSkia. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 10 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
« no previous file with comments | « extensions/browser/extension_icon_image.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_icon_image.h" 5 #include "extensions/browser/extension_icon_image.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_file_value_serializer.h" 9 #include "base/json/json_file_value_serializer.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 // When requesting another representation, we should not crash and return some 555 // When requesting another representation, we should not crash and return some
556 // image of the size. It could be blank or a rescale from the existing 1.0f 556 // image of the size. It could be blank or a rescale from the existing 1.0f
557 // icon. 557 // icon.
558 representation = image_skia.GetRepresentation(2.0f); 558 representation = image_skia.GetRepresentation(2.0f);
559 559
560 EXPECT_EQ(16, representation.GetWidth()); 560 EXPECT_EQ(16, representation.GetWidth());
561 EXPECT_EQ(16, representation.GetHeight()); 561 EXPECT_EQ(16, representation.GetHeight());
562 EXPECT_EQ(2.0f, representation.scale()); 562 EXPECT_EQ(2.0f, representation.scale());
563 } 563 }
564 564
565 // Test that new representations added to the image of an IconImage are cached
566 // for future use.
567 TEST_F(ExtensionIconImageTest, ImageCachesNewRepresentations) {
568 // Load up an extension and create an icon image.
569 scoped_refptr<Extension> extension(
570 CreateExtension("extension_icon_image", Manifest::INVALID_LOCATION));
571 ASSERT_TRUE(extension.get() != NULL);
572 gfx::ImageSkia default_icon = GetDefaultIcon();
573 scoped_ptr<IconImage> icon_image(
574 new IconImage(browser_context(),
575 extension.get(),
576 IconsInfo::GetIcons(extension.get()),
577 16,
578 default_icon,
579 this));
580
581 // Load an image representation.
582 gfx::ImageSkiaRep representation =
583 icon_image->image_skia().GetRepresentation(1.0f);
584 WaitForImageLoad();
585
586 // Cache for later use.
587 gfx::Image prior_image = icon_image->image();
588
589 // Now the fun part: access the image from the IconImage, and create a png
590 // representation of it.
591 gfx::Image image = icon_image->image();
592 scoped_refptr<base::RefCountedMemory> image_as_png = image.As1xPNGBytes();
593
594 // Access the image from the IconImage again, and get a png representation.
595 // The two png representations should be exactly equal (the same object),
596 // because image storage is shared, so when we created one from the first
597 // image, all other images should also have that representation...
598 gfx::Image image2 = icon_image->image();
599 EXPECT_EQ(image_as_png.get(), image2.As1xPNGBytes().get());
600
601 // ...even images that were copied before the representation was constructed.
602 EXPECT_EQ(image_as_png.get(), prior_image.As1xPNGBytes().get());
603 }
604
565 } // namespace extensions 605 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_icon_image.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698