OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "build/build_config.h" | |
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | |
7 #include "chrome/browser/ui/panels/panel.h" | |
8 #include "chrome/browser/ui/panels/panel_constants.h" | |
9 #include "chrome/browser/ui/views/panels/panel_frame_view.h" | |
10 #include "chrome/browser/ui/views/panels/panel_view.h" | |
11 #include "chrome/browser/ui/views/tab_icon_view.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "ui/views/controls/button/image_button.h" | |
14 #include "ui/views/controls/button/menu_button.h" | |
15 #include "ui/views/controls/image_view.h" | |
16 #include "ui/views/controls/label.h" | |
17 #include "ui/views/controls/link.h" | |
18 #include "ui/views/controls/textfield/textfield.h" | |
19 | |
20 #if defined(OS_WIN) | |
21 #include "ui/views/win/hwnd_util.h" | |
22 #endif | |
23 | |
24 // BasePanelBrowserTest now creates refactored Panels. Refactor | |
25 // has only been done for Mac panels so far. | |
26 class PanelViewTest : public BasePanelBrowserTest { | |
27 public: | |
28 PanelViewTest() : BasePanelBrowserTest() { } | |
29 | |
30 protected: | |
31 PanelView* GetPanelView(Panel* panel) const { | |
32 return static_cast<PanelView*>(panel->native_panel()); | |
33 } | |
34 }; | |
35 | |
36 IN_PROC_BROWSER_TEST_F(PanelViewTest, ActivePanelWindowProperties) { | |
37 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 150), SHOW_AS_ACTIVE); | |
38 Panel* panel = CreatePanelWithParams(params); | |
39 EXPECT_TRUE(panel->IsActive()); | |
40 | |
41 // Validate window styles. We want to ensure that the window is created | |
42 // with expected styles regardless of its active state. | |
43 #if defined(OS_WIN) | |
44 HWND native_window = views::HWNDForWidget(GetPanelView(panel)->window()); | |
45 | |
46 LONG styles = ::GetWindowLong(native_window, GWL_STYLE); | |
47 EXPECT_EQ(0, styles & WS_MAXIMIZEBOX); | |
48 EXPECT_EQ(0, styles & WS_MINIMIZEBOX); | |
49 | |
50 LONG ext_styles = ::GetWindowLong(native_window, GWL_EXSTYLE); | |
51 EXPECT_EQ(WS_EX_TOPMOST, ext_styles & WS_EX_TOPMOST); | |
52 | |
53 RECT window_rect; | |
54 EXPECT_TRUE(::GetWindowRect(native_window, &window_rect)); | |
55 EXPECT_EQ(200, window_rect.right - window_rect.left); | |
56 EXPECT_EQ(150, window_rect.bottom - window_rect.top); | |
57 | |
58 EXPECT_TRUE(::IsWindowVisible(native_window)); | |
59 #endif | |
60 | |
61 panel->Close(); | |
62 } | |
63 | |
64 IN_PROC_BROWSER_TEST_F(PanelViewTest, InactivePanelWindowProperties) { | |
65 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 150), SHOW_AS_INACTIVE); | |
66 Panel* panel = CreatePanelWithParams(params); | |
67 EXPECT_FALSE(panel->IsActive()); | |
68 | |
69 // Validate window styles. We want to ensure that the window is created | |
70 // with expected styles regardless of its active state. | |
71 #if defined(OS_WIN) | |
72 HWND native_window = views::HWNDForWidget(GetPanelView(panel)->window()); | |
73 | |
74 LONG styles = ::GetWindowLong(native_window, GWL_STYLE); | |
75 EXPECT_EQ(0, styles & WS_MAXIMIZEBOX); | |
76 EXPECT_EQ(0, styles & WS_MINIMIZEBOX); | |
77 | |
78 LONG ext_styles = ::GetWindowLong(native_window, GWL_EXSTYLE); | |
79 EXPECT_EQ(WS_EX_TOPMOST, ext_styles & WS_EX_TOPMOST); | |
80 | |
81 RECT window_rect; | |
82 EXPECT_TRUE(::GetWindowRect(native_window, &window_rect)); | |
83 EXPECT_EQ(200, window_rect.right - window_rect.left); | |
84 EXPECT_EQ(150, window_rect.bottom - window_rect.top); | |
85 | |
86 EXPECT_TRUE(::IsWindowVisible(native_window)); | |
87 #endif | |
88 | |
89 panel->Close(); | |
90 } | |
91 | |
92 IN_PROC_BROWSER_TEST_F(PanelViewTest, PanelLayout) { | |
93 // Create a fixed-size panel to avoid possible collapsing of the title | |
94 // if the enforced min sizes are too small. | |
95 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 200, 50)); | |
96 PanelFrameView* frame_view = GetPanelView(panel)->GetFrameView(); | |
97 | |
98 TabIconView* title_icon = frame_view->title_icon(); | |
99 views::View* title_text = frame_view->title_label(); | |
100 views::View* close_button = frame_view->close_button(); | |
101 views::View* minimize_button = frame_view->minimize_button(); | |
102 views::View* restore_button = frame_view->restore_button(); | |
103 | |
104 // We should have icon, text, minimize, restore and close buttons. Only one of | |
105 // minimize and restore buttons are visible. | |
106 EXPECT_EQ(5, frame_view->child_count()); | |
107 EXPECT_TRUE(frame_view->Contains(title_icon)); | |
108 EXPECT_TRUE(frame_view->Contains(title_text)); | |
109 EXPECT_TRUE(frame_view->Contains(close_button)); | |
110 EXPECT_TRUE(frame_view->Contains(minimize_button)); | |
111 EXPECT_TRUE(frame_view->Contains(restore_button)); | |
112 | |
113 // These controls should be visible. | |
114 EXPECT_TRUE(title_icon->visible()); | |
115 EXPECT_TRUE(title_text->visible()); | |
116 EXPECT_TRUE(close_button->visible()); | |
117 EXPECT_TRUE(minimize_button->visible()); | |
118 EXPECT_FALSE(restore_button->visible()); | |
119 | |
120 // Validate their layouts. | |
121 int titlebar_height = panel::kTitlebarHeight; | |
122 EXPECT_GT(title_icon->width(), 0); | |
123 EXPECT_GT(title_icon->height(), 0); | |
124 EXPECT_LT(title_icon->height(), titlebar_height); | |
125 EXPECT_GT(title_text->width(), 0); | |
126 EXPECT_GT(title_text->height(), 0); | |
127 EXPECT_LT(title_text->height(), titlebar_height); | |
128 EXPECT_GT(minimize_button->width(), 0); | |
129 EXPECT_GT(minimize_button->height(), 0); | |
130 EXPECT_LT(minimize_button->height(), titlebar_height); | |
131 EXPECT_GT(close_button->width(), 0); | |
132 EXPECT_GT(close_button->height(), 0); | |
133 EXPECT_LT(close_button->height(), titlebar_height); | |
134 EXPECT_LT(title_icon->x() + title_icon->width(), title_text->x()); | |
135 EXPECT_LT(title_text->x() + title_text->width(), minimize_button->x()); | |
136 EXPECT_LT(minimize_button->x() + minimize_button->width(), close_button->x()); | |
137 } | |
138 | |
139 IN_PROC_BROWSER_TEST_F(PanelViewTest, CheckTitleOnlyHeight) { | |
140 gfx::Rect bounds(0, 0, 200, 50); | |
141 Panel* panel = CreatePanelWithBounds("PanelTest", bounds); | |
142 | |
143 // Change panel to title-only and check its height. | |
144 panel->SetExpansionState(Panel::TITLE_ONLY); | |
145 WaitForBoundsAnimationFinished(panel); | |
146 EXPECT_EQ(panel->TitleOnlyHeight(), panel->GetBounds().height()); | |
147 EXPECT_EQ(0, GetPanelView(panel)->height()); // client area height. | |
148 | |
149 panel->Close(); | |
150 } | |
151 | |
152 IN_PROC_BROWSER_TEST_F(PanelViewTest, CheckMinimizedHeight) { | |
153 gfx::Rect bounds(0, 0, 200, 50); | |
154 Panel* panel = CreatePanelWithBounds("PanelTest", bounds); | |
155 | |
156 // Change panel to minimized and check its height. | |
157 panel->SetExpansionState(Panel::MINIMIZED); | |
158 WaitForBoundsAnimationFinished(panel); | |
159 EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height()); | |
160 EXPECT_EQ(0, GetPanelView(panel)->height()); // client area height. | |
161 | |
162 panel->Close(); | |
163 } | |
OLD | NEW |