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