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

Side by Side Diff: ui/wm/core/shadow_unittest.cc

Issue 581273002: Shadows: crop corner tiles instead of hiding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding shadow_unittest Created 6 years, 3 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 | « ui/wm/core/shadow.cc ('k') | ui/wm/wm.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/wm/core/shadow.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/aura/test/aura_test_base.h"
10 #include "ui/aura/test/test_windows.h"
11 #include "ui/aura/window.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/layer.h"
14 #include "ui/compositor/layer_tree_owner.h"
15 #include "ui/resources/grit/ui_resources.h"
16
17 namespace wm {
18
19 typedef aura::test::AuraTestBase ShadowTest;
20
21 // Mock for the ResourceBundle::Delegate class.
22 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate {
23 public:
24 MockResourceBundleDelegate() : last_resource_id_(0) {
25 SkBitmap bitmap_small, bitmap_large;
26 bitmap_small.allocPixels(SkImageInfo::MakeN32Premul(129, 129));
Daniel Erat 2014/09/19 00:28:58 nit: mind moving these numbers into constants?
hshi1 2014/09/19 00:41:13 Done.
27 bitmap_large.allocPixels(SkImageInfo::MakeN32Premul(269, 269));
28 image_small_ = gfx::Image::CreateFrom1xBitmap(bitmap_small);
29 image_large_ = gfx::Image::CreateFrom1xBitmap(bitmap_large);
30 }
31 virtual ~MockResourceBundleDelegate() {}
32
33 // ResourceBundle::Delegate overrides.
34 virtual base::FilePath GetPathForResourcePack(
35 const base::FilePath& pack_path,
36 ui::ScaleFactor scale_factor) OVERRIDE {
37 return base::FilePath();
38 }
39 virtual base::FilePath GetPathForLocalePack(
40 const base::FilePath& pack_path,
41 const std::string& locale) OVERRIDE {
42 return base::FilePath();
43 }
44 virtual gfx::Image GetImageNamed(int resource_id) OVERRIDE {
45 last_resource_id_ = resource_id;
46 switch (resource_id) {
47 case IDR_WINDOW_BUBBLE_SHADOW_SMALL:
48 return image_small_;
49 case IDR_AURA_SHADOW_ACTIVE:
50 case IDR_AURA_SHADOW_INACTIVE:
51 return image_large_;
52 default:
53 NOTREACHED();
54 return gfx::Image();
55 }
56 }
57 virtual gfx::Image GetNativeImageNamed(
58 int resource_id, ui::ResourceBundle::ImageRTL rtl) OVERRIDE {
59 return gfx::Image();
60 }
61 virtual base::RefCountedStaticMemory* LoadDataResourceBytes(
62 int resource_id, ui::ScaleFactor scale_factor) OVERRIDE {
63 return NULL;
64 }
65 virtual bool GetRawDataResource(
66 int resource_id, ui::ScaleFactor scale_factor,
67 base::StringPiece* value) OVERRIDE {
68 return false;
69 }
70 virtual bool GetLocalizedString(
71 int message_id, base::string16* value) OVERRIDE {
72 return false;
73 }
74 virtual scoped_ptr<gfx::Font> GetFont(
75 ui::ResourceBundle::FontStyle style) OVERRIDE {
76 return scoped_ptr<gfx::Font>();
77 }
78
79 int last_resource_id() const { return last_resource_id_; }
80
81 private:
82 gfx::Image image_small_;
83 gfx::Image image_large_;
84 int last_resource_id_;
85 };
86
87 // Test if the proper image is set for the specified style.
88 TEST_F(ShadowTest, UpdateImagesForStyle) {
89 scoped_ptr<MockResourceBundleDelegate> delegate(
90 new MockResourceBundleDelegate());
Daniel Erat 2014/09/19 00:28:58 mind making a ShadowTest class and moving this cod
hshi1 2014/09/19 00:41:13 Done.
91 ui::ResourceBundle::InitSharedInstanceWithLocale(
92 "en-US", delegate.get(), ui::ResourceBundle::LOAD_COMMON_RESOURCES);
Daniel Erat 2014/09/19 00:28:58 nit: indent four spaces; same below
hshi1 2014/09/19 00:41:13 Done.
93
94 scoped_ptr<Shadow> shadow(new Shadow());
95
96 shadow->Init(Shadow::STYLE_SMALL);
97 EXPECT_EQ(delegate->last_resource_id(), IDR_WINDOW_BUBBLE_SHADOW_SMALL);
Daniel Erat 2014/09/19 00:28:58 i was going to suggest that it'd be better to chec
hshi1 2014/09/19 00:41:13 Acknowledged.
98 shadow->SetStyle(Shadow::STYLE_ACTIVE);
99 EXPECT_EQ(delegate->last_resource_id(), IDR_AURA_SHADOW_ACTIVE);
100 shadow->SetStyle(Shadow::STYLE_INACTIVE);
101 EXPECT_EQ(delegate->last_resource_id(), IDR_AURA_SHADOW_INACTIVE);
102
103 ui::ResourceBundle::CleanupSharedInstance();
104 }
105
106 // Test if the proper content bounds is calculated based on the current style.
107 TEST_F(ShadowTest, SetContentBounds) {
108 scoped_ptr<MockResourceBundleDelegate> delegate(
109 new MockResourceBundleDelegate());
110 ui::ResourceBundle::InitSharedInstanceWithLocale(
111 "en-US", delegate.get(), ui::ResourceBundle::LOAD_COMMON_RESOURCES);
112
113 scoped_ptr<Shadow> shadow(new Shadow());
114
115 // verify that layer bounds are inset from content bounds
Daniel Erat 2014/09/19 00:28:58 nit: capitalize "Verify" and add a trailing period
hshi1 2014/09/19 00:41:13 Done.
116 shadow->Init(Shadow::STYLE_ACTIVE);
117 gfx::Rect content_bounds(100, 100, 300, 300);
118 shadow->SetContentBounds(content_bounds);
119 EXPECT_EQ(shadow->content_bounds(), content_bounds);
120 EXPECT_EQ(shadow->layer()->bounds(), gfx::Rect(36, 36, 428, 428));
Daniel Erat 2014/09/19 00:28:58 could you make these numbers be a function of the
hshi1 2014/09/19 00:41:13 actually the layer bounds are only related to the
121
122 shadow->SetStyle(Shadow::STYLE_SMALL);
123 EXPECT_EQ(shadow->content_bounds(), content_bounds);
124 EXPECT_EQ(shadow->layer()->bounds(), gfx::Rect(96, 96, 308, 308));
Daniel Erat 2014/09/19 00:28:58 does this exercise the change that you're making,
hshi1 2014/09/19 00:41:13 No unfortunately it doesn't exercise the current c
Daniel Erat 2014/09/19 00:44:00 got it. :-/ thanks for the tests, in any case.
danakj 2014/09/19 00:44:38 You can add an accessor for those if you want.
oshima 2014/09/19 14:24:01 I think it's worth it.
125
126 ui::ResourceBundle::CleanupSharedInstance();
127 }
128 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/shadow.cc ('k') | ui/wm/wm.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698