Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 static const int kSmallBitmapSize = 129; | |
| 20 static const int kLargeBitmapSize = 269; | |
|
oshima
2014/09/19 14:24:02
nit: put them in anonymous namespace and remove st
hshi1
2014/09/19 14:47:35
Done.
| |
| 21 | |
| 22 // Mock for the ResourceBundle::Delegate class. | |
| 23 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { | |
| 24 public: | |
| 25 MockResourceBundleDelegate() : last_resource_id_(0) { | |
| 26 SkBitmap bitmap_small, bitmap_large; | |
| 27 bitmap_small.allocPixels( | |
| 28 SkImageInfo::MakeN32Premul(kSmallBitmapSize, kSmallBitmapSize)); | |
| 29 bitmap_large.allocPixels( | |
| 30 SkImageInfo::MakeN32Premul(kLargeBitmapSize, kLargeBitmapSize)); | |
| 31 image_small_ = gfx::Image::CreateFrom1xBitmap(bitmap_small); | |
| 32 image_large_ = gfx::Image::CreateFrom1xBitmap(bitmap_large); | |
| 33 } | |
| 34 virtual ~MockResourceBundleDelegate() {} | |
| 35 | |
| 36 // ResourceBundle::Delegate overrides. | |
|
oshima
2014/09/19 14:24:02
just // ResourceBundle::Delegate:
(overrdies. is
hshi1
2014/09/19 14:47:35
Done.
| |
| 37 virtual base::FilePath GetPathForResourcePack( | |
| 38 const base::FilePath& pack_path, | |
| 39 ui::ScaleFactor scale_factor) OVERRIDE { | |
| 40 return base::FilePath(); | |
| 41 } | |
| 42 virtual base::FilePath GetPathForLocalePack( | |
| 43 const base::FilePath& pack_path, | |
| 44 const std::string& locale) OVERRIDE { | |
| 45 return base::FilePath(); | |
| 46 } | |
| 47 virtual gfx::Image GetImageNamed(int resource_id) OVERRIDE { | |
| 48 last_resource_id_ = resource_id; | |
| 49 switch (resource_id) { | |
| 50 case IDR_WINDOW_BUBBLE_SHADOW_SMALL: | |
| 51 return image_small_; | |
| 52 case IDR_AURA_SHADOW_ACTIVE: | |
| 53 case IDR_AURA_SHADOW_INACTIVE: | |
| 54 return image_large_; | |
| 55 default: | |
| 56 NOTREACHED(); | |
| 57 return gfx::Image(); | |
| 58 } | |
| 59 } | |
| 60 virtual gfx::Image GetNativeImageNamed( | |
| 61 int resource_id, ui::ResourceBundle::ImageRTL rtl) OVERRIDE { | |
| 62 return gfx::Image(); | |
| 63 } | |
| 64 virtual base::RefCountedStaticMemory* LoadDataResourceBytes( | |
| 65 int resource_id, ui::ScaleFactor scale_factor) OVERRIDE { | |
| 66 return NULL; | |
| 67 } | |
| 68 virtual bool GetRawDataResource( | |
| 69 int resource_id, ui::ScaleFactor scale_factor, | |
| 70 base::StringPiece* value) OVERRIDE { | |
| 71 return false; | |
| 72 } | |
| 73 virtual bool GetLocalizedString( | |
| 74 int message_id, base::string16* value) OVERRIDE { | |
| 75 return false; | |
| 76 } | |
| 77 virtual scoped_ptr<gfx::Font> GetFont( | |
| 78 ui::ResourceBundle::FontStyle style) OVERRIDE { | |
| 79 return scoped_ptr<gfx::Font>(); | |
| 80 } | |
| 81 | |
| 82 int last_resource_id() const { return last_resource_id_; } | |
|
oshima
2014/09/19 14:24:02
nit: indent
hshi1
2014/09/19 14:47:35
Done.
| |
| 83 | |
| 84 private: | |
| 85 gfx::Image image_small_; | |
| 86 gfx::Image image_large_; | |
| 87 int last_resource_id_; | |
| 88 }; | |
|
oshima
2014/09/19 14:24:02
DISALLOW_COPY_AND_ASSIGN
hshi1
2014/09/19 14:47:35
Done.
| |
| 89 | |
| 90 class ShadowTest: public aura::test::AuraTestBase { | |
| 91 public: | |
| 92 ShadowTest() {} | |
| 93 virtual ~ShadowTest() {} | |
| 94 | |
| 95 MockResourceBundleDelegate* delegate() const { return delegate_.get(); } | |
| 96 | |
|
oshima
2014/09/19 14:24:01
nit: // aura::test:AuraTestBase:
hshi1
2014/09/19 14:47:35
Done.
| |
| 97 virtual void SetUp() OVERRIDE { | |
| 98 aura::test::AuraTestBase::SetUp(); | |
| 99 delegate_.reset(new MockResourceBundleDelegate()); | |
| 100 if (ResourceBundle::HasSharedInstance()) | |
| 101 ui::ResourceBundle::CleanupSharedInstance(); | |
| 102 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 103 "en-US", delegate(), ui::ResourceBundle::LOAD_COMMON_RESOURCES); | |
| 104 } | |
| 105 virtual void TearDown() OVERRIDE { | |
| 106 ui::ResourceBundle::CleanupSharedInstance(); | |
|
oshima
2014/09/19 14:24:01
You need
base::FilePath ui_test_pak_path;
ASSERT_
hshi1
2014/09/19 14:47:35
Ok but it requires me to add "+ui/base/ui_base_pat
| |
| 107 aura::test::AuraTestBase::TearDown(); | |
| 108 } | |
| 109 private: | |
| 110 scoped_ptr<MockResourceBundleDelegate> delegate_; | |
| 111 }; | |
|
oshima
2014/09/19 14:24:01
private: DISALLOW_COPY_AND_ASSIGN
hshi1
2014/09/19 14:47:35
Done.
| |
| 112 | |
| 113 // Test if the proper image is set for the specified style. | |
| 114 TEST_F(ShadowTest, UpdateImagesForStyle) { | |
| 115 scoped_ptr<Shadow> shadow(new Shadow()); | |
| 116 | |
| 117 shadow->Init(Shadow::STYLE_SMALL); | |
| 118 EXPECT_EQ(delegate()->last_resource_id(), IDR_WINDOW_BUBBLE_SHADOW_SMALL); | |
| 119 shadow->SetStyle(Shadow::STYLE_ACTIVE); | |
| 120 EXPECT_EQ(delegate()->last_resource_id(), IDR_AURA_SHADOW_ACTIVE); | |
| 121 shadow->SetStyle(Shadow::STYLE_INACTIVE); | |
| 122 EXPECT_EQ(delegate()->last_resource_id(), IDR_AURA_SHADOW_INACTIVE); | |
| 123 } | |
| 124 | |
| 125 // Test if the proper content bounds is calculated based on the current style. | |
| 126 TEST_F(ShadowTest, SetContentBounds) { | |
| 127 scoped_ptr<Shadow> shadow(new Shadow()); | |
| 128 | |
| 129 // Verify that layer bounds are inset from content bounds. | |
| 130 shadow->Init(Shadow::STYLE_ACTIVE); | |
| 131 gfx::Rect content_bounds(100, 100, 300, 300); | |
| 132 shadow->SetContentBounds(content_bounds); | |
| 133 EXPECT_EQ(shadow->content_bounds(), content_bounds); | |
| 134 EXPECT_EQ(shadow->layer()->bounds(), gfx::Rect(36, 36, 428, 428)); | |
| 135 | |
| 136 shadow->SetStyle(Shadow::STYLE_SMALL); | |
| 137 EXPECT_EQ(shadow->content_bounds(), content_bounds); | |
| 138 EXPECT_EQ(shadow->layer()->bounds(), gfx::Rect(96, 96, 308, 308)); | |
| 139 } | |
| 140 } // namespace wm | |
| OLD | NEW |