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

Side by Side Diff: ash/wm/custom_frame_view_ash_unittest.cc

Issue 183793011: App windows on ChromeOS cannot be sized to their maximum height (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@appwindow_chromeos_insets
Patch Set: Addressed review comments Created 6 years, 9 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 | « ash/wm/custom_frame_view_ash.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 "ash/wm/custom_frame_view_ash.h" 5 #include "ash/wm/custom_frame_view_ash.h"
6 6
7 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "grit/ash_resources.h" 9 #include "grit/ash_resources.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h" 11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/widget/widget.h" 12 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_delegate.h" 13 #include "ui/views/widget/widget_delegate.h"
14 14
15 namespace ash { 15 namespace ash {
16 16
17 namespace {
18
19 // A views::WidgetDelegate which uses a CustomFrameViewAsh. 17 // A views::WidgetDelegate which uses a CustomFrameViewAsh.
20 class TestWidgetDelegate : public views::WidgetDelegateView { 18 class TestWidgetDelegate : public views::WidgetDelegateView {
21 public: 19 public:
22 TestWidgetDelegate() { 20 TestWidgetDelegate() {
23 } 21 }
24 virtual ~TestWidgetDelegate() { 22 virtual ~TestWidgetDelegate() {
25 } 23 }
26 24
27 virtual views::NonClientFrameView* CreateNonClientFrameView( 25 virtual views::NonClientFrameView* CreateNonClientFrameView(
28 views::Widget* widget) OVERRIDE { 26 views::Widget* widget) OVERRIDE {
29 custom_frame_view_ = new CustomFrameViewAsh(widget); 27 custom_frame_view_ = new CustomFrameViewAsh(widget);
30 return custom_frame_view_; 28 return custom_frame_view_;
31 } 29 }
32 30
33 CustomFrameViewAsh* custom_frame_view() { 31 CustomFrameViewAsh* custom_frame_view() const {
34 return custom_frame_view_; 32 return custom_frame_view_;
35 } 33 }
36 34
37 private: 35 private:
38 // Not owned. 36 // Not owned.
39 CustomFrameViewAsh* custom_frame_view_; 37 CustomFrameViewAsh* custom_frame_view_;
40 38
41 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); 39 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
42 }; 40 };
43 41
44 } // namespace 42 class TestWidgetConstraintsDelegate : public TestWidgetDelegate {
43 public:
44 TestWidgetConstraintsDelegate() {
45 }
46 virtual ~TestWidgetConstraintsDelegate() {
47 }
45 48
46 typedef test::AshTestBase CustomFrameViewAshTest; 49 // views::View implementation.
50 virtual gfx::Size GetMinimumSize() OVERRIDE {
51 return minimum_size_;
52 }
53
54 virtual gfx::Size GetMaximumSize() OVERRIDE {
55 return maximum_size_;
56 }
57
58 virtual views::View* GetContentsView() OVERRIDE {
59 // Set this instance as the contents view so that the maximum and minimum
60 // size constraints will be used.
61 return this;
62 }
63
64 void set_minimum_size(const gfx::Size& min_size) {
65 minimum_size_ = min_size;
66 }
67
68 void set_maximum_size(const gfx::Size& max_size) {
69 maximum_size_ = max_size;
70 }
71
72 int GetTitleBarHeight() const {
73 return custom_frame_view()->NonClientTopBorderHeight();
74 }
75
76 private:
77 gfx::Size minimum_size_;
78 gfx::Size maximum_size_;
79
80 DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate);
81 };
82
83 class CustomFrameViewAshTest : public test::AshTestBase {
84 public:
85 CustomFrameViewAshTest() {}
86 virtual ~CustomFrameViewAshTest() {}
87
88 protected:
89 scoped_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) {
90 scoped_ptr<views::Widget> widget(new views::Widget);
91 views::Widget::InitParams params;
92 params.delegate = delegate;
93 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
94 params.bounds = gfx::Rect(0, 0, 100, 100);
95 params.context = CurrentContext();
96 widget->Init(params);
97 return widget.Pass();
98 }
99
100 private:
101 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
102 };
47 103
48 // Test that the height of the header is correct upon initially displaying 104 // Test that the height of the header is correct upon initially displaying
49 // the widget. 105 // the widget.
50 TEST_F(CustomFrameViewAshTest, HeaderHeight) { 106 TEST_F(CustomFrameViewAshTest, HeaderHeight) {
51 TestWidgetDelegate* delegate = new TestWidgetDelegate; 107 TestWidgetDelegate* delegate = new TestWidgetDelegate;
52 108
53 scoped_ptr<views::Widget> widget(new views::Widget); 109 scoped_ptr<views::Widget> widget(CreateWidget(delegate));
54 views::Widget::InitParams params;
55 params.delegate = delegate;
56 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
57 params.bounds = gfx::Rect(0, 0, 100, 100);
58 params.context = CurrentContext();
59 widget->Init(params);
60 widget->Show(); 110 widget->Show();
61 111
62 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 112 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
63 gfx::ImageSkia* close_button = 113 gfx::ImageSkia* close_button =
64 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_CONTROL_BACKGROUND_H); 114 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_CONTROL_BACKGROUND_H);
65 115
66 // |kSeparatorSize| should match |kHeaderContentSeparatorSize| in 116 // |kSeparatorSize| should match |kHeaderContentSeparatorSize| in
67 // header_painter.cc 117 // header_painter.cc
68 // TODO(pkotwicz): Clean this test up once the separator overlays the window 118 // TODO(pkotwicz): Clean this test up once the separator overlays the window
69 // controls. 119 // controls.
70 const int kSeparatorSize = 1; 120 const int kSeparatorSize = 1;
71 121
72 // The header should have enough room for the window controls and the 122 // The header should have enough room for the window controls and the
73 // separator line. 123 // separator line.
74 EXPECT_EQ(close_button->height() + kSeparatorSize, 124 EXPECT_EQ(close_button->height() + kSeparatorSize,
75 delegate->custom_frame_view()->GetHeaderView()->height()); 125 delegate->custom_frame_view()->GetHeaderView()->height());
76 126
77 widget->Maximize(); 127 widget->Maximize();
78 EXPECT_EQ(close_button->height() + kSeparatorSize, 128 EXPECT_EQ(close_button->height() + kSeparatorSize,
79 delegate->custom_frame_view()->GetHeaderView()->height()); 129 delegate->custom_frame_view()->GetHeaderView()->height());
80 } 130 }
81 131
132 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
133 // sizes when the client view does not specify any size constraints.
134 TEST_F(CustomFrameViewAshTest, NoSizeConstraints) {
135 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
136 scoped_ptr<views::Widget> widget(CreateWidget(delegate));
137
138 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
139 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
140 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
141
142 EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height());
143
144 // A width and height constraint of 0 denotes unbounded.
145 EXPECT_EQ(0, max_frame_size.width());
146 EXPECT_EQ(0, max_frame_size.height());
147 }
148
149 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
150 // sizes when the client view specifies size constraints.
151 TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) {
152 gfx::Size min_client_size(500, 500);
153 gfx::Size max_client_size(800, 800);
154 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
155 delegate->set_minimum_size(min_client_size);
156 delegate->set_maximum_size(max_client_size);
157 scoped_ptr<views::Widget> widget(CreateWidget(delegate));
158
159 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
160 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
161 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
162
163 EXPECT_EQ(min_client_size.width(), min_frame_size.width());
164 EXPECT_EQ(max_client_size.width(), max_frame_size.width());
165 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
166 min_frame_size.height());
167 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
168 max_frame_size.height());
169 }
170
82 } // namespace ash 171 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/custom_frame_view_ash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698