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

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

Issue 2550593002: Update WM shadows for MD. (Closed)
Patch Set: fix border for small windows Created 4 years 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') | 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 "ui/wm/core/shadow.h" 5 #include "ui/wm/core/shadow.h"
6 6
7 #include <memory>
8
9 #include "base/macros.h" 7 #include "base/macros.h"
10 #include "base/path_service.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
17 #include "ui/compositor/layer.h"
18 #include "ui/compositor/layer_tree_owner.h"
19 #include "ui/resources/grit/ui_resources.h"
20 9
21 namespace wm { 10 namespace wm {
22
23 namespace { 11 namespace {
24 12
25 const int kSmallBitmapSize = 129; 13 using ShadowTest = aura::test::AuraTestBase;
26 const int kLargeBitmapSize = 269;
27
28 // Mock for the ResourceBundle::Delegate class.
29 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate {
30 public:
31 MockResourceBundleDelegate() : last_resource_id_(0) {
32 SkBitmap bitmap_small, bitmap_large;
33 bitmap_small.allocPixels(
34 SkImageInfo::MakeN32Premul(kSmallBitmapSize, kSmallBitmapSize));
35 bitmap_large.allocPixels(
36 SkImageInfo::MakeN32Premul(kLargeBitmapSize, kLargeBitmapSize));
37 image_small_ = gfx::Image::CreateFrom1xBitmap(bitmap_small);
38 image_large_ = gfx::Image::CreateFrom1xBitmap(bitmap_large);
39 }
40 ~MockResourceBundleDelegate() override {}
41
42 // ResourceBundle::Delegate:
43 base::FilePath GetPathForResourcePack(const base::FilePath& pack_path,
44 ui::ScaleFactor scale_factor) override {
45 return base::FilePath();
46 }
47 base::FilePath GetPathForLocalePack(const base::FilePath& pack_path,
48 const std::string& locale) override {
49 return base::FilePath();
50 }
51 gfx::Image GetImageNamed(int resource_id) override {
52 last_resource_id_ = resource_id;
53 switch (resource_id) {
54 case IDR_WINDOW_BUBBLE_SHADOW_SMALL:
55 return image_small_;
56 case IDR_AURA_SHADOW_ACTIVE:
57 case IDR_AURA_SHADOW_INACTIVE:
58 return image_large_;
59 default:
60 NOTREACHED();
61 return gfx::Image();
62 }
63 }
64 gfx::Image GetNativeImageNamed(int resource_id) override {
65 return gfx::Image();
66 }
67 base::RefCountedStaticMemory* LoadDataResourceBytes(
68 int resource_id,
69 ui::ScaleFactor scale_factor) override {
70 return NULL;
71 }
72 bool GetRawDataResource(int resource_id,
73 ui::ScaleFactor scale_factor,
74 base::StringPiece* value) override {
75 return false;
76 }
77 bool GetLocalizedString(int message_id, base::string16* value) override {
78 return false;
79 }
80
81 int last_resource_id() const { return last_resource_id_; }
82
83 private:
84 gfx::Image image_small_;
85 gfx::Image image_large_;
86 int last_resource_id_;
87
88 DISALLOW_COPY_AND_ASSIGN(MockResourceBundleDelegate);
89 };
90
91 } // namespace
92
93 class ShadowTest: public aura::test::AuraTestBase {
94 public:
95 ShadowTest() {}
96 ~ShadowTest() override {}
97
98 MockResourceBundleDelegate* delegate() { return delegate_.get(); }
99
100 // aura::testAuraBase:
101 void SetUp() override {
102 aura::test::AuraTestBase::SetUp();
103 delegate_.reset(new MockResourceBundleDelegate());
104 if (ResourceBundle::HasSharedInstance())
105 ui::ResourceBundle::CleanupSharedInstance();
106 ui::ResourceBundle::InitSharedInstanceWithLocale(
107 "en-US", delegate(), ui::ResourceBundle::LOAD_COMMON_RESOURCES);
108 }
109 void TearDown() override {
110 ui::ResourceBundle::CleanupSharedInstance();
111 base::FilePath ui_test_pak_path;
112 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
113 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
114 aura::test::AuraTestBase::TearDown();
115 }
116 private:
117 std::unique_ptr<MockResourceBundleDelegate> delegate_;
118 DISALLOW_COPY_AND_ASSIGN(ShadowTest);
119 };
120
121 // Test if the proper image is set for the specified style.
122 TEST_F(ShadowTest, UpdateImagesForStyle) {
123 Shadow shadow;
124
125 shadow.Init(Shadow::STYLE_SMALL);
126 EXPECT_EQ(delegate()->last_resource_id(), IDR_WINDOW_BUBBLE_SHADOW_SMALL);
127 shadow.SetStyle(Shadow::STYLE_ACTIVE);
128 EXPECT_EQ(delegate()->last_resource_id(), IDR_AURA_SHADOW_ACTIVE);
129 shadow.SetStyle(Shadow::STYLE_INACTIVE);
130 EXPECT_EQ(delegate()->last_resource_id(), IDR_AURA_SHADOW_INACTIVE);
131 }
132 14
133 // Test if the proper content bounds is calculated based on the current style. 15 // Test if the proper content bounds is calculated based on the current style.
134 TEST_F(ShadowTest, SetContentBounds) { 16 TEST_F(ShadowTest, SetContentBounds) {
17 // Verify that layer bounds are outset from content bounds.
135 Shadow shadow; 18 Shadow shadow;
19 {
20 shadow.Init(Shadow::STYLE_ACTIVE);
21 gfx::Rect content_bounds(100, 100, 300, 300);
22 shadow.SetContentBounds(content_bounds);
23 EXPECT_EQ(content_bounds, shadow.content_bounds());
24 gfx::Rect shadow_bounds(content_bounds);
25 int elevation = 24;
26 shadow_bounds.Inset(-gfx::Insets(2 * elevation) +
27 gfx::Insets(elevation, 0, -elevation, 0));
28 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
29 }
136 30
137 // Verify that layer bounds are inset from content bounds. 31 {
138 shadow.Init(Shadow::STYLE_ACTIVE); 32 shadow.SetStyle(Shadow::STYLE_SMALL);
139 gfx::Rect content_bounds(100, 100, 300, 300); 33 gfx::Rect content_bounds(100, 100, 300, 300);
140 shadow.SetContentBounds(content_bounds); 34 shadow.SetContentBounds(content_bounds);
141 EXPECT_EQ(shadow.content_bounds(), content_bounds); 35 EXPECT_EQ(content_bounds, shadow.content_bounds());
142 EXPECT_EQ(shadow.layer()->bounds(), gfx::Rect(36, 36, 428, 428)); 36 gfx::Rect shadow_bounds(content_bounds);
37 int elevation = 6;
38 shadow_bounds.Inset(-gfx::Insets(2 * elevation) +
39 gfx::Insets(elevation, 0, -elevation, 0));
40 EXPECT_EQ(shadow_bounds, shadow.layer()->bounds());
41 }
42 }
143 43
144 shadow.SetStyle(Shadow::STYLE_SMALL); 44 } // namespace
145 EXPECT_EQ(shadow.content_bounds(), content_bounds);
146 EXPECT_EQ(shadow.layer()->bounds(), gfx::Rect(96, 96, 308, 308));
147 }
148 } // namespace wm 45 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/shadow.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698