Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / panels / detached_panel_browsertest.cc
blob2497570a3b0c1a4858c5f2b0de21802d33ee80ca
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 "base/message_loop/message_loop.h"
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
7 #include "chrome/browser/ui/panels/detached_panel_collection.h"
8 #include "chrome/browser/ui/panels/native_panel.h"
9 #include "chrome/browser/ui/panels/panel.h"
10 #include "chrome/browser/ui/panels/panel_manager.h"
12 class DetachedPanelBrowserTest : public BasePanelBrowserTest {
15 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) {
16 PanelManager* panel_manager = PanelManager::GetInstance();
17 DetachedPanelCollection* detached_collection =
18 panel_manager->detached_collection();
20 // Create an initially detached panel (as opposed to other tests which create
21 // a docked panel, then detaches it).
22 gfx::Rect bounds(300, 200, 250, 200);
23 CreatePanelParams params("1", bounds, SHOW_AS_ACTIVE);
24 params.create_mode = PanelManager::CREATE_AS_DETACHED;
25 Panel* panel = CreatePanelWithParams(params);
26 scoped_ptr<NativePanelTesting> panel_testing(
27 CreateNativePanelTesting(panel));
29 EXPECT_EQ(1, panel_manager->num_panels());
30 EXPECT_TRUE(detached_collection->HasPanel(panel));
32 EXPECT_EQ(bounds.x(), panel->GetBounds().x());
33 // Ignore checking y position since the detached panel will be placed near
34 // the top if the stacking mode is enabled.
35 if (!PanelManager::IsPanelStackingEnabled())
36 EXPECT_EQ(bounds.y(), panel->GetBounds().y());
37 EXPECT_EQ(bounds.width(), panel->GetBounds().width());
38 EXPECT_EQ(bounds.height(), panel->GetBounds().height());
39 EXPECT_FALSE(panel->IsAlwaysOnTop());
41 EXPECT_TRUE(panel_testing->IsButtonVisible(panel::CLOSE_BUTTON));
42 // The minimize button will not be shown on some Linux desktop environment
43 // that does not support system minimize.
44 if (PanelManager::CanUseSystemMinimize() &&
45 PanelManager::IsPanelStackingEnabled()) {
46 EXPECT_TRUE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
47 } else {
48 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
50 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON));
52 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
54 EXPECT_EQ(panel::ALL_ROUNDED, panel_testing->GetWindowCornerStyle());
56 Panel::AttentionMode expected_attention_mode =
57 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
58 Panel::USE_SYSTEM_ATTENTION);
59 EXPECT_EQ(expected_attention_mode, panel->attention_mode());
61 panel_manager->CloseAll();
64 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnActive) {
65 // Create a detached panel that is initially active.
66 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
67 scoped_ptr<NativePanelTesting> native_panel_testing(
68 CreateNativePanelTesting(panel));
70 // Test that the attention should not be drawn if the detached panel is in
71 // focus.
72 EXPECT_FALSE(panel->IsDrawingAttention());
73 panel->FlashFrame(true);
74 EXPECT_FALSE(panel->IsDrawingAttention());
75 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
77 panel->Close();
80 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnInactive) {
81 // Create an inactive detached panel.
82 Panel* panel =
83 CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
84 scoped_ptr<NativePanelTesting> native_panel_testing(
85 CreateNativePanelTesting(panel));
87 // Test that the attention is drawn when the detached panel is not in focus.
88 EXPECT_FALSE(panel->IsActive());
89 EXPECT_FALSE(panel->IsDrawingAttention());
90 panel->FlashFrame(true);
91 EXPECT_TRUE(panel->IsDrawingAttention());
92 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
94 // Stop drawing attention.
95 panel->FlashFrame(false);
96 EXPECT_FALSE(panel->IsDrawingAttention());
97 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
99 PanelManager::GetInstance()->CloseAll();
102 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionResetOnActivate) {
103 // Create an inactive detached panel.
104 Panel* panel =
105 CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
106 scoped_ptr<NativePanelTesting> native_panel_testing(
107 CreateNativePanelTesting(panel));
109 // Test that the attention is drawn when the detached panel is not in focus.
110 panel->FlashFrame(true);
111 EXPECT_TRUE(panel->IsDrawingAttention());
112 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
114 // Test that the attention is cleared when panel gets focus.
115 panel->Activate();
116 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
117 EXPECT_FALSE(panel->IsDrawingAttention());
118 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
120 PanelManager::GetInstance()->CloseAll();
123 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) {
124 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
125 EXPECT_FALSE(panel->IsMinimized());
127 // Clicking on an active detached panel's titlebar has no effect, regardless
128 // of modifier.
129 scoped_ptr<NativePanelTesting> test_panel(
130 CreateNativePanelTesting(panel));
131 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
132 test_panel->ReleaseMouseButtonTitlebar();
133 EXPECT_TRUE(panel->IsActive());
134 EXPECT_FALSE(panel->IsMinimized());
136 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin(),
137 panel::APPLY_TO_ALL);
138 test_panel->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
139 EXPECT_TRUE(panel->IsActive());
140 EXPECT_FALSE(panel->IsMinimized());
142 // Clicking on an inactive detached panel's titlebar activates it.
143 DeactivatePanel(panel);
144 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
145 test_panel->ReleaseMouseButtonTitlebar();
146 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
147 EXPECT_FALSE(panel->IsMinimized());
149 PanelManager::GetInstance()->CloseAll();
152 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
153 UpdateDetachedPanelOnPrimaryDisplayChange) {
154 PanelManager* panel_manager = PanelManager::GetInstance();
156 // Create a big detached panel on the primary display.
157 gfx::Rect initial_bounds(50, 50, 700, 500);
158 Panel* panel = CreateDetachedPanel("1", initial_bounds);
159 EXPECT_EQ(initial_bounds, panel->GetBounds());
161 // Make the primary display smaller.
162 // Expect that the panel should be resized to fit within the display.
163 gfx::Rect primary_display_area(0, 0, 500, 300);
164 gfx::Rect primary_work_area(0, 0, 500, 280);
165 mock_display_settings_provider()->SetPrimaryDisplay(
166 primary_display_area, primary_work_area);
168 gfx::Rect bounds = panel->GetBounds();
169 EXPECT_LE(primary_work_area.x(), bounds.x());
170 EXPECT_LE(bounds.x(), primary_work_area.right());
171 EXPECT_LE(primary_work_area.y(), bounds.y());
172 EXPECT_LE(bounds.y(), primary_work_area.bottom());
174 panel_manager->CloseAll();
177 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
178 UpdateDetachedPanelOnSecondaryDisplayChange) {
179 PanelManager* panel_manager = PanelManager::GetInstance();
181 // Setup 2 displays with secondary display on the right side of primary
182 // display.
183 gfx::Rect primary_display_area(0, 0, 400, 600);
184 gfx::Rect primary_work_area(0, 0, 400, 560);
185 mock_display_settings_provider()->SetPrimaryDisplay(
186 primary_display_area, primary_work_area);
187 gfx::Rect secondary_display_area(400, 0, 400, 500);
188 gfx::Rect secondary_work_area(400, 0, 400, 460);
189 mock_display_settings_provider()->SetSecondaryDisplay(
190 secondary_display_area, secondary_work_area);
192 // Create a big detached panel on the seconday display.
193 gfx::Rect initial_bounds(450, 50, 350, 400);
194 Panel* panel = CreateDetachedPanel("1", initial_bounds);
195 EXPECT_EQ(initial_bounds, panel->GetBounds());
197 // Move down the secondary display and make it smaller.
198 // Expect that the panel should be resized to fit within the display.
199 secondary_display_area.SetRect(400, 100, 300, 400);
200 secondary_work_area.SetRect(400, 100, 300, 360);
201 mock_display_settings_provider()->SetSecondaryDisplay(
202 secondary_display_area, secondary_work_area);
204 gfx::Rect bounds = panel->GetBounds();
205 EXPECT_LE(secondary_work_area.x(), bounds.x());
206 EXPECT_LE(bounds.x(), secondary_work_area.right());
207 EXPECT_LE(secondary_work_area.y(), bounds.y());
208 EXPECT_LE(bounds.y(), secondary_work_area.bottom());
210 panel_manager->CloseAll();
213 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
214 KeepShowingDetachedPanelCreatedBeforeFullScreenMode) {
215 // Create a detached panel.
216 CreatePanelParams params("1", gfx::Rect(300, 200, 250, 200), SHOW_AS_ACTIVE);
217 params.create_mode = PanelManager::CREATE_AS_DETACHED;
218 Panel* panel = CreatePanelWithParams(params);
219 scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
221 // Panel should be visible at first.
222 EXPECT_TRUE(panel_testing->IsWindowVisible());
224 // Panel's visibility should not be affected when entering full-screen mode.
225 mock_display_settings_provider()->EnableFullScreenMode(true);
226 EXPECT_TRUE(panel_testing->IsWindowVisible());
228 // Panel's visibility should not be affected when leaving full-screen mode.
229 mock_display_settings_provider()->EnableFullScreenMode(false);
230 EXPECT_TRUE(panel_testing->IsWindowVisible());
232 PanelManager::GetInstance()->CloseAll();
235 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
236 HideDetachedPanelCreatedOnFullScreenMode) {
237 // Enable full-screen mode first.
238 mock_display_settings_provider()->EnableFullScreenMode(true);
240 // Create a detached panel without waiting it to be shown since it is not
241 // supposed to be shown on full-screen mode.
242 CreatePanelParams params("1", gfx::Rect(300, 200, 250, 200), SHOW_AS_ACTIVE);
243 params.create_mode = PanelManager::CREATE_AS_DETACHED;
244 params.wait_for_fully_created = false;
245 Panel* panel = CreatePanelWithParams(params);
246 scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
248 // Panel should not be shown on full-screen mode.
249 EXPECT_FALSE(panel_testing->IsWindowVisible());
251 // Panel should become visible when leaving full-screen mode.
252 mock_display_settings_provider()->EnableFullScreenMode(false);
253 EXPECT_TRUE(panel_testing->IsWindowVisible());
255 PanelManager::GetInstance()->CloseAll();