Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / panels / detached_panel_browsertest.cc
blob04d79138f4a4c315ec132ad493dffedb69730964
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 EXPECT_TRUE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
46 else
47 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
48 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON));
50 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
52 EXPECT_EQ(panel::ALL_ROUNDED, panel_testing->GetWindowCornerStyle());
54 Panel::AttentionMode expected_attention_mode =
55 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
56 Panel::USE_SYSTEM_ATTENTION);
57 EXPECT_EQ(expected_attention_mode, panel->attention_mode());
59 panel_manager->CloseAll();
62 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnActive) {
63 // Create a detached panel that is initially active.
64 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
65 scoped_ptr<NativePanelTesting> native_panel_testing(
66 CreateNativePanelTesting(panel));
68 // Test that the attention should not be drawn if the detached panel is in
69 // focus.
70 EXPECT_FALSE(panel->IsDrawingAttention());
71 panel->FlashFrame(true);
72 EXPECT_FALSE(panel->IsDrawingAttention());
73 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
75 panel->Close();
78 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnInactive) {
79 // Create an inactive detached panel.
80 Panel* panel =
81 CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
82 scoped_ptr<NativePanelTesting> native_panel_testing(
83 CreateNativePanelTesting(panel));
85 // Test that the attention is drawn when the detached panel is not in focus.
86 EXPECT_FALSE(panel->IsActive());
87 EXPECT_FALSE(panel->IsDrawingAttention());
88 panel->FlashFrame(true);
89 EXPECT_TRUE(panel->IsDrawingAttention());
90 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
92 // Stop drawing attention.
93 panel->FlashFrame(false);
94 EXPECT_FALSE(panel->IsDrawingAttention());
95 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
97 PanelManager::GetInstance()->CloseAll();
100 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionResetOnActivate) {
101 // Create an inactive detached panel.
102 Panel* panel =
103 CreateInactiveDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
104 scoped_ptr<NativePanelTesting> native_panel_testing(
105 CreateNativePanelTesting(panel));
107 // Test that the attention is drawn when the detached panel is not in focus.
108 panel->FlashFrame(true);
109 EXPECT_TRUE(panel->IsDrawingAttention());
110 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
112 // Test that the attention is cleared when panel gets focus.
113 panel->Activate();
114 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
115 EXPECT_FALSE(panel->IsDrawingAttention());
116 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
118 PanelManager::GetInstance()->CloseAll();
121 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) {
122 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
123 EXPECT_FALSE(panel->IsMinimized());
125 // Clicking on an active detached panel's titlebar has no effect, regardless
126 // of modifier.
127 scoped_ptr<NativePanelTesting> test_panel(
128 CreateNativePanelTesting(panel));
129 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
130 test_panel->ReleaseMouseButtonTitlebar();
131 EXPECT_TRUE(panel->IsActive());
132 EXPECT_FALSE(panel->IsMinimized());
134 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin(),
135 panel::APPLY_TO_ALL);
136 test_panel->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
137 EXPECT_TRUE(panel->IsActive());
138 EXPECT_FALSE(panel->IsMinimized());
140 // Clicking on an inactive detached panel's titlebar activates it.
141 DeactivatePanel(panel);
142 test_panel->PressLeftMouseButtonTitlebar(panel->GetBounds().origin());
143 test_panel->ReleaseMouseButtonTitlebar();
144 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
145 EXPECT_FALSE(panel->IsMinimized());
147 PanelManager::GetInstance()->CloseAll();
150 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
151 UpdateDetachedPanelOnPrimaryDisplayChange) {
152 PanelManager* panel_manager = PanelManager::GetInstance();
154 // Create a big detached panel on the primary display.
155 gfx::Rect initial_bounds(50, 50, 700, 500);
156 Panel* panel = CreateDetachedPanel("1", initial_bounds);
157 EXPECT_EQ(initial_bounds, panel->GetBounds());
159 // Make the primary display smaller.
160 // Expect that the panel should be resized to fit within the display.
161 gfx::Rect primary_display_area(0, 0, 500, 300);
162 gfx::Rect primary_work_area(0, 0, 500, 280);
163 mock_display_settings_provider()->SetPrimaryDisplay(
164 primary_display_area, primary_work_area);
166 gfx::Rect bounds = panel->GetBounds();
167 EXPECT_LE(primary_work_area.x(), bounds.x());
168 EXPECT_LE(bounds.x(), primary_work_area.right());
169 EXPECT_LE(primary_work_area.y(), bounds.y());
170 EXPECT_LE(bounds.y(), primary_work_area.bottom());
172 panel_manager->CloseAll();
175 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
176 UpdateDetachedPanelOnSecondaryDisplayChange) {
177 PanelManager* panel_manager = PanelManager::GetInstance();
179 // Setup 2 displays with secondary display on the right side of primary
180 // display.
181 gfx::Rect primary_display_area(0, 0, 400, 600);
182 gfx::Rect primary_work_area(0, 0, 400, 560);
183 mock_display_settings_provider()->SetPrimaryDisplay(
184 primary_display_area, primary_work_area);
185 gfx::Rect secondary_display_area(400, 0, 400, 500);
186 gfx::Rect secondary_work_area(400, 0, 400, 460);
187 mock_display_settings_provider()->SetSecondaryDisplay(
188 secondary_display_area, secondary_work_area);
190 // Create a big detached panel on the seconday display.
191 gfx::Rect initial_bounds(450, 50, 350, 400);
192 Panel* panel = CreateDetachedPanel("1", initial_bounds);
193 EXPECT_EQ(initial_bounds, panel->GetBounds());
195 // Move down the secondary display and make it smaller.
196 // Expect that the panel should be resized to fit within the display.
197 secondary_display_area.SetRect(400, 100, 300, 400);
198 secondary_work_area.SetRect(400, 100, 300, 360);
199 mock_display_settings_provider()->SetSecondaryDisplay(
200 secondary_display_area, secondary_work_area);
202 gfx::Rect bounds = panel->GetBounds();
203 EXPECT_LE(secondary_work_area.x(), bounds.x());
204 EXPECT_LE(bounds.x(), secondary_work_area.right());
205 EXPECT_LE(secondary_work_area.y(), bounds.y());
206 EXPECT_LE(bounds.y(), secondary_work_area.bottom());
208 panel_manager->CloseAll();
211 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
212 KeepShowingDetachedPanelCreatedBeforeFullScreenMode) {
213 // Create a detached panel.
214 CreatePanelParams params("1", gfx::Rect(300, 200, 250, 200), SHOW_AS_ACTIVE);
215 params.create_mode = PanelManager::CREATE_AS_DETACHED;
216 Panel* panel = CreatePanelWithParams(params);
217 scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
219 // Panel should be visible at first.
220 EXPECT_TRUE(panel_testing->IsWindowVisible());
222 // Panel's visibility should not be affected when entering full-screen mode.
223 mock_display_settings_provider()->EnableFullScreenMode(true);
224 EXPECT_TRUE(panel_testing->IsWindowVisible());
226 // Panel's visibility should not be affected when leaving full-screen mode.
227 mock_display_settings_provider()->EnableFullScreenMode(false);
228 EXPECT_TRUE(panel_testing->IsWindowVisible());
230 PanelManager::GetInstance()->CloseAll();
233 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest,
234 HideDetachedPanelCreatedOnFullScreenMode) {
235 // Enable full-screen mode first.
236 mock_display_settings_provider()->EnableFullScreenMode(true);
238 // Create a detached panel without waiting it to be shown since it is not
239 // supposed to be shown on full-screen mode.
240 CreatePanelParams params("1", gfx::Rect(300, 200, 250, 200), SHOW_AS_ACTIVE);
241 params.create_mode = PanelManager::CREATE_AS_DETACHED;
242 params.wait_for_fully_created = false;
243 Panel* panel = CreatePanelWithParams(params);
244 scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
246 // Panel should not be shown on full-screen mode.
247 EXPECT_FALSE(panel_testing->IsWindowVisible());
249 // Panel should become visible when leaving full-screen mode.
250 mock_display_settings_provider()->EnableFullScreenMode(false);
251 EXPECT_TRUE(panel_testing->IsWindowVisible());
253 PanelManager::GetInstance()->CloseAll();