| 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 "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" | |
| 11 | |
| 12 class DetachedPanelBrowserTest : public BasePanelBrowserTest { | |
| 13 }; | |
| 14 | |
| 15 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) { | |
| 16 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 17 DetachedPanelCollection* detached_collection = | |
| 18 panel_manager->detached_collection(); | |
| 19 | |
| 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 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 27 CreateNativePanelTesting(panel)); | |
| 28 | |
| 29 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 30 EXPECT_TRUE(detached_collection->HasPanel(panel)); | |
| 31 | |
| 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()); | |
| 40 | |
| 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)); | |
| 49 } | |
| 50 EXPECT_FALSE(panel_testing->IsButtonVisible(panel::RESTORE_BUTTON)); | |
| 51 | |
| 52 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse()); | |
| 53 | |
| 54 EXPECT_EQ(panel::ALL_ROUNDED, panel_testing->GetWindowCornerStyle()); | |
| 55 | |
| 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()); | |
| 60 | |
| 61 panel_manager->CloseAll(); | |
| 62 } | |
| 63 | |
| 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 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 68 CreateNativePanelTesting(panel)); | |
| 69 | |
| 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()); | |
| 76 | |
| 77 panel->Close(); | |
| 78 } | |
| 79 | |
| 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 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 85 CreateNativePanelTesting(panel)); | |
| 86 | |
| 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()); | |
| 93 | |
| 94 // Stop drawing attention. | |
| 95 panel->FlashFrame(false); | |
| 96 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 97 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | |
| 98 | |
| 99 PanelManager::GetInstance()->CloseAll(); | |
| 100 } | |
| 101 | |
| 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 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 107 CreateNativePanelTesting(panel)); | |
| 108 | |
| 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()); | |
| 113 | |
| 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()); | |
| 119 | |
| 120 PanelManager::GetInstance()->CloseAll(); | |
| 121 } | |
| 122 | |
| 123 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) { | |
| 124 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); | |
| 125 EXPECT_FALSE(panel->IsMinimized()); | |
| 126 | |
| 127 // Clicking on an active detached panel's titlebar has no effect, regardless | |
| 128 // of modifier. | |
| 129 std::unique_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()); | |
| 135 | |
| 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()); | |
| 141 | |
| 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()); | |
| 148 | |
| 149 PanelManager::GetInstance()->CloseAll(); | |
| 150 } | |
| 151 | |
| 152 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, | |
| 153 UpdateDetachedPanelOnPrimaryDisplayChange) { | |
| 154 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 155 | |
| 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()); | |
| 160 | |
| 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); | |
| 167 | |
| 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()); | |
| 173 | |
| 174 panel_manager->CloseAll(); | |
| 175 } | |
| 176 | |
| 177 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, | |
| 178 UpdateDetachedPanelOnSecondaryDisplayChange) { | |
| 179 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 180 | |
| 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); | |
| 191 | |
| 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()); | |
| 196 | |
| 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); | |
| 203 | |
| 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()); | |
| 209 | |
| 210 panel_manager->CloseAll(); | |
| 211 } | |
| 212 | |
| 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 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 220 CreateNativePanelTesting(panel)); | |
| 221 | |
| 222 // Panel should be visible at first. | |
| 223 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 224 | |
| 225 // Panel's visibility should not be affected when entering full-screen mode. | |
| 226 mock_display_settings_provider()->EnableFullScreenMode(true); | |
| 227 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 228 | |
| 229 // Panel's visibility should not be affected when leaving full-screen mode. | |
| 230 mock_display_settings_provider()->EnableFullScreenMode(false); | |
| 231 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 232 | |
| 233 PanelManager::GetInstance()->CloseAll(); | |
| 234 } | |
| 235 | |
| 236 IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, | |
| 237 HideDetachedPanelCreatedOnFullScreenMode) { | |
| 238 // Enable full-screen mode first. | |
| 239 mock_display_settings_provider()->EnableFullScreenMode(true); | |
| 240 | |
| 241 // Create a detached panel without waiting it to be shown since it is not | |
| 242 // supposed to be shown on full-screen mode. | |
| 243 CreatePanelParams params("1", gfx::Rect(300, 200, 250, 200), SHOW_AS_ACTIVE); | |
| 244 params.create_mode = PanelManager::CREATE_AS_DETACHED; | |
| 245 params.wait_for_fully_created = false; | |
| 246 Panel* panel = CreatePanelWithParams(params); | |
| 247 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 248 CreateNativePanelTesting(panel)); | |
| 249 | |
| 250 // Panel should not be shown on full-screen mode. | |
| 251 EXPECT_FALSE(panel_testing->IsWindowVisible()); | |
| 252 | |
| 253 // Panel should become visible when leaving full-screen mode. | |
| 254 mock_display_settings_provider()->EnableFullScreenMode(false); | |
| 255 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 256 | |
| 257 PanelManager::GetInstance()->CloseAll(); | |
| 258 } | |
| OLD | NEW |