| 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 <stddef.h> | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/run_loop.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "build/build_config.h" | |
| 11 #include "chrome/app/chrome_command_ids.h" | |
| 12 #include "chrome/browser/chrome_notification_types.h" | |
| 13 #include "chrome/browser/devtools/devtools_window.h" | |
| 14 #include "chrome/browser/extensions/extension_apitest.h" | |
| 15 #include "chrome/browser/net/url_request_mock_util.h" | |
| 16 #include "chrome/browser/prefs/browser_prefs.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 18 #include "chrome/browser/ui/browser.h" | |
| 19 #include "chrome/browser/ui/browser_commands.h" | |
| 20 #include "chrome/browser/ui/browser_finder.h" | |
| 21 #include "chrome/browser/ui/browser_list.h" | |
| 22 #include "chrome/browser/ui/browser_window.h" | |
| 23 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | |
| 24 #include "chrome/browser/ui/panels/docked_panel_collection.h" | |
| 25 #include "chrome/browser/ui/panels/native_panel.h" | |
| 26 #include "chrome/browser/ui/panels/panel.h" | |
| 27 #include "chrome/browser/ui/panels/panel_manager.h" | |
| 28 #include "chrome/browser/ui/panels/test_panel_active_state_observer.h" | |
| 29 #include "chrome/browser/web_applications/web_app.h" | |
| 30 #include "chrome/common/chrome_switches.h" | |
| 31 #include "chrome/common/url_constants.h" | |
| 32 #include "chrome/grit/generated_resources.h" | |
| 33 #include "chrome/test/base/interactive_test_utils.h" | |
| 34 #include "chrome/test/base/ui_test_utils.h" | |
| 35 #include "components/app_modal/app_modal_dialog.h" | |
| 36 #include "components/app_modal/native_app_modal_dialog.h" | |
| 37 #include "components/prefs/pref_service.h" | |
| 38 #include "content/public/browser/native_web_keyboard_event.h" | |
| 39 #include "content/public/browser/notification_service.h" | |
| 40 #include "content/public/browser/web_contents.h" | |
| 41 #include "content/public/common/url_constants.h" | |
| 42 #include "content/public/test/browser_test_utils.h" | |
| 43 #include "extensions/browser/extension_registry.h" | |
| 44 #include "extensions/common/constants.h" | |
| 45 #include "net/test/url_request/url_request_mock_http_job.h" | |
| 46 #include "testing/gtest/include/gtest/gtest.h" | |
| 47 #include "ui/base/hit_test.h" | |
| 48 #include "ui/base/l10n/l10n_util.h" | |
| 49 #include "ui/events/event.h" | |
| 50 #include "ui/events/event_utils.h" | |
| 51 #include "ui/events/keycodes/dom/dom_code.h" | |
| 52 | |
| 53 using content::WebContents; | |
| 54 | |
| 55 class PanelBrowserTest : public BasePanelBrowserTest { | |
| 56 public: | |
| 57 PanelBrowserTest() : BasePanelBrowserTest() { | |
| 58 } | |
| 59 | |
| 60 protected: | |
| 61 // Helper function for debugging. | |
| 62 void PrintAllPanelBounds() { | |
| 63 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); | |
| 64 DLOG(WARNING) << "PanelBounds:"; | |
| 65 for (size_t i = 0; i < panels.size(); ++i) { | |
| 66 DLOG(WARNING) << "#=" << i | |
| 67 << ", ptr=" << panels[i] | |
| 68 << ", x=" << panels[i]->GetBounds().x() | |
| 69 << ", y=" << panels[i]->GetBounds().y() | |
| 70 << ", width=" << panels[i]->GetBounds().width() | |
| 71 << ", height" << panels[i]->GetBounds().height(); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 std::vector<gfx::Rect> GetAllPanelBounds() { | |
| 76 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 77 std::vector<gfx::Rect> bounds; | |
| 78 for (size_t i = 0; i < panels.size(); i++) | |
| 79 bounds.push_back(panels[i]->GetBounds()); | |
| 80 return bounds; | |
| 81 } | |
| 82 | |
| 83 std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds, | |
| 84 const std::vector<int>& delta_x) { | |
| 85 std::vector<gfx::Rect> new_bounds = bounds; | |
| 86 for (size_t i = 0; i < bounds.size(); ++i) | |
| 87 new_bounds[i].Offset(delta_x[i], 0); | |
| 88 return new_bounds; | |
| 89 } | |
| 90 | |
| 91 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() { | |
| 92 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 93 std::vector<Panel::ExpansionState> expansion_states; | |
| 94 for (size_t i = 0; i < panels.size(); i++) | |
| 95 expansion_states.push_back(panels[i]->expansion_state()); | |
| 96 return expansion_states; | |
| 97 } | |
| 98 | |
| 99 std::vector<bool> GetAllPanelActiveStates() { | |
| 100 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 101 std::vector<bool> active_states; | |
| 102 for (size_t i = 0; i < panels.size(); i++) | |
| 103 active_states.push_back(panels[i]->IsActive()); | |
| 104 return active_states; | |
| 105 } | |
| 106 | |
| 107 std::vector<bool> ProduceExpectedActiveStates( | |
| 108 int expected_active_panel_index) { | |
| 109 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 110 std::vector<bool> active_states; | |
| 111 for (int i = 0; i < static_cast<int>(panels.size()); i++) | |
| 112 active_states.push_back(i == expected_active_panel_index); | |
| 113 return active_states; | |
| 114 } | |
| 115 | |
| 116 void WaitForPanelActiveStates(const std::vector<bool>& old_states, | |
| 117 const std::vector<bool>& new_states) { | |
| 118 DCHECK(old_states.size() == new_states.size()); | |
| 119 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 120 for (size_t i = 0; i < old_states.size(); i++) { | |
| 121 if (old_states[i] != new_states[i]){ | |
| 122 WaitForPanelActiveState( | |
| 123 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE); | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 void TestMinimizeRestore() { | |
| 129 // This constant is used to generate a point 'sufficiently higher then | |
| 130 // top edge of the panel'. On some platforms (Mac) we extend hover area | |
| 131 // a bit above the minimized panel as well, so it takes significant | |
| 132 // distance to 'move mouse out' of the hover-sensitive area. | |
| 133 const int kFarEnoughFromHoverArea = 153; | |
| 134 | |
| 135 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 136 std::vector<Panel*> panels = panel_manager->panels(); | |
| 137 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds(); | |
| 138 std::vector<gfx::Rect> expected_bounds = test_begin_bounds; | |
| 139 std::vector<Panel::ExpansionState> expected_expansion_states( | |
| 140 panels.size(), Panel::EXPANDED); | |
| 141 std::vector<NativePanelTesting*> native_panels_testing(panels.size()); | |
| 142 for (size_t i = 0; i < panels.size(); ++i) { | |
| 143 native_panels_testing[i] = CreateNativePanelTesting(panels[i]); | |
| 144 } | |
| 145 | |
| 146 // Verify titlebar click does not minimize. | |
| 147 for (size_t index = 0; index < panels.size(); ++index) { | |
| 148 // Press left mouse button. Verify nothing changed. | |
| 149 native_panels_testing[index]->PressLeftMouseButtonTitlebar( | |
| 150 panels[index]->GetBounds().origin()); | |
| 151 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); | |
| 152 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); | |
| 153 | |
| 154 // Release mouse button. Verify nothing changed. | |
| 155 native_panels_testing[index]->ReleaseMouseButtonTitlebar(); | |
| 156 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); | |
| 157 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); | |
| 158 } | |
| 159 | |
| 160 // Minimize all panels for next stage in test. | |
| 161 for (size_t index = 0; index < panels.size(); ++index) { | |
| 162 panels[index]->Minimize(); | |
| 163 expected_bounds[index].set_height(panel::kMinimizedPanelHeight); | |
| 164 expected_bounds[index].set_y( | |
| 165 test_begin_bounds[index].y() + | |
| 166 test_begin_bounds[index].height() - panel::kMinimizedPanelHeight); | |
| 167 expected_expansion_states[index] = Panel::MINIMIZED; | |
| 168 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); | |
| 169 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); | |
| 170 } | |
| 171 | |
| 172 // Setup bounds and expansion states for minimized and titlebar-only | |
| 173 // states. | |
| 174 std::vector<Panel::ExpansionState> titlebar_exposed_states( | |
| 175 panels.size(), Panel::TITLE_ONLY); | |
| 176 std::vector<gfx::Rect> minimized_bounds = expected_bounds; | |
| 177 std::vector<Panel::ExpansionState> minimized_states( | |
| 178 panels.size(), Panel::MINIMIZED); | |
| 179 std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds; | |
| 180 for (size_t index = 0; index < panels.size(); ++index) { | |
| 181 titlebar_exposed_bounds[index].set_height( | |
| 182 panels[index]->native_panel()->TitleOnlyHeight()); | |
| 183 titlebar_exposed_bounds[index].set_y( | |
| 184 test_begin_bounds[index].y() + | |
| 185 test_begin_bounds[index].height() - | |
| 186 panels[index]->native_panel()->TitleOnlyHeight()); | |
| 187 } | |
| 188 | |
| 189 // Test hover. All panels are currently in minimized state. | |
| 190 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); | |
| 191 for (size_t index = 0; index < panels.size(); ++index) { | |
| 192 // Hover mouse on minimized panel. | |
| 193 // Verify titlebar is exposed on all panels. | |
| 194 gfx::Point hover_point(panels[index]->GetBounds().origin()); | |
| 195 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); | |
| 196 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); | |
| 197 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); | |
| 198 | |
| 199 // Hover mouse above the panel. Verify all panels are minimized. | |
| 200 hover_point.set_y( | |
| 201 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea); | |
| 202 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); | |
| 203 EXPECT_EQ(minimized_bounds, GetAllPanelBounds()); | |
| 204 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); | |
| 205 | |
| 206 // Hover mouse below minimized panel. | |
| 207 // Verify titlebar is exposed on all panels. | |
| 208 hover_point.set_y(panels[index]->GetBounds().y() + | |
| 209 panels[index]->GetBounds().height() + 5); | |
| 210 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); | |
| 211 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); | |
| 212 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); | |
| 213 | |
| 214 // Hover below titlebar exposed panel. Verify nothing changed. | |
| 215 hover_point.set_y(panels[index]->GetBounds().y() + | |
| 216 panels[index]->GetBounds().height() + 6); | |
| 217 MoveMouse(hover_point); | |
| 218 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); | |
| 219 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); | |
| 220 | |
| 221 // Hover mouse above panel. Verify all panels are minimized. | |
| 222 hover_point.set_y( | |
| 223 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea); | |
| 224 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); | |
| 225 EXPECT_EQ(minimized_bounds, GetAllPanelBounds()); | |
| 226 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); | |
| 227 } | |
| 228 | |
| 229 // Test restore. All panels are currently in minimized state. | |
| 230 for (size_t index = 0; index < panels.size(); ++index) { | |
| 231 // Hover on the last panel. This is to test the case of clicking on the | |
| 232 // panel when it's in titlebar exposed state. | |
| 233 if (index == panels.size() - 1) | |
| 234 MoveMouse(minimized_bounds[index].origin()); | |
| 235 | |
| 236 // Click minimized or title bar exposed panel as the case may be. | |
| 237 // Verify panel is restored to its original size. | |
| 238 native_panels_testing[index]->PressLeftMouseButtonTitlebar( | |
| 239 panels[index]->GetBounds().origin()); | |
| 240 native_panels_testing[index]->ReleaseMouseButtonTitlebar(); | |
| 241 expected_bounds[index].set_height( | |
| 242 test_begin_bounds[index].height()); | |
| 243 expected_bounds[index].set_y(test_begin_bounds[index].y()); | |
| 244 expected_expansion_states[index] = Panel::EXPANDED; | |
| 245 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); | |
| 246 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); | |
| 247 | |
| 248 // Hover again on the last panel which is now restored, to reset the | |
| 249 // titlebar exposed state. | |
| 250 if (index == panels.size() - 1) | |
| 251 MoveMouse(minimized_bounds[index].origin()); | |
| 252 } | |
| 253 | |
| 254 // The below could be separate tests, just adding a TODO here for tracking. | |
| 255 // TODO(prasadt): Add test for dragging when in titlebar exposed state. | |
| 256 // TODO(prasadt): Add test in presence of auto hiding task bar. | |
| 257 | |
| 258 for (size_t i = 0; i < panels.size(); ++i) | |
| 259 delete native_panels_testing[i]; | |
| 260 } | |
| 261 }; | |
| 262 | |
| 263 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CheckDockedPanelProperties) { | |
| 264 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 265 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
| 266 | |
| 267 // Create 3 docked panels that are in expanded, title-only or minimized states | |
| 268 // respectively. | |
| 269 Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100)); | |
| 270 Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100)); | |
| 271 Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100)); | |
| 272 panel2->SetExpansionState(Panel::TITLE_ONLY); | |
| 273 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); | |
| 274 panel3->SetExpansionState(Panel::MINIMIZED); | |
| 275 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | |
| 276 std::unique_ptr<NativePanelTesting> panel1_testing( | |
| 277 CreateNativePanelTesting(panel1)); | |
| 278 std::unique_ptr<NativePanelTesting> panel2_testing( | |
| 279 CreateNativePanelTesting(panel2)); | |
| 280 std::unique_ptr<NativePanelTesting> panel3_testing( | |
| 281 CreateNativePanelTesting(panel3)); | |
| 282 | |
| 283 // Ensure that the layout message can get a chance to be processed so that | |
| 284 // the button visibility can be updated. | |
| 285 base::RunLoop().RunUntilIdle(); | |
| 286 | |
| 287 EXPECT_EQ(3, panel_manager->num_panels()); | |
| 288 EXPECT_TRUE(docked_collection->HasPanel(panel1)); | |
| 289 EXPECT_TRUE(docked_collection->HasPanel(panel2)); | |
| 290 EXPECT_TRUE(docked_collection->HasPanel(panel3)); | |
| 291 | |
| 292 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | |
| 293 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); | |
| 294 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | |
| 295 | |
| 296 EXPECT_TRUE(panel1->IsAlwaysOnTop()); | |
| 297 EXPECT_TRUE(panel2->IsAlwaysOnTop()); | |
| 298 EXPECT_TRUE(panel3->IsAlwaysOnTop()); | |
| 299 | |
| 300 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON)); | |
| 301 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON)); | |
| 302 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON)); | |
| 303 | |
| 304 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); | |
| 305 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); | |
| 306 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); | |
| 307 | |
| 308 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON)); | |
| 309 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON)); | |
| 310 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON)); | |
| 311 | |
| 312 // Expanded panel cannot be resized at the bottom. | |
| 313 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel1->CanResizeByMouse()); | |
| 314 EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse()); | |
| 315 EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse()); | |
| 316 | |
| 317 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle()); | |
| 318 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle()); | |
| 319 EXPECT_EQ(panel::TOP_ROUNDED, panel3_testing->GetWindowCornerStyle()); | |
| 320 | |
| 321 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode()); | |
| 322 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode()); | |
| 323 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode()); | |
| 324 | |
| 325 panel_manager->CloseAll(); | |
| 326 } | |
| 327 | |
| 328 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | |
| 329 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 330 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | |
| 331 | |
| 332 Panel* panel = CreatePanel("PanelTest"); | |
| 333 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 334 | |
| 335 gfx::Rect bounds = panel->GetBounds(); | |
| 336 EXPECT_GT(bounds.x(), 0); | |
| 337 EXPECT_GT(bounds.y(), 0); | |
| 338 EXPECT_GT(bounds.width(), 0); | |
| 339 EXPECT_GT(bounds.height(), 0); | |
| 340 | |
| 341 EXPECT_EQ(bounds.right(), | |
| 342 panel_manager->docked_collection()->StartingRightPosition()); | |
| 343 | |
| 344 CloseWindowAndWait(panel); | |
| 345 | |
| 346 EXPECT_EQ(0, panel_manager->num_panels()); | |
| 347 } | |
| 348 | |
| 349 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) { | |
| 350 gfx::Rect work_area = PanelManager::GetInstance()-> | |
| 351 display_settings_provider()->GetPrimaryWorkArea(); | |
| 352 Panel* panel = CreatePanelWithBounds("BigPanel", work_area); | |
| 353 gfx::Rect bounds = panel->GetBounds(); | |
| 354 EXPECT_EQ(panel->max_size().width(), bounds.width()); | |
| 355 EXPECT_LT(bounds.width(), work_area.width()); | |
| 356 EXPECT_EQ(panel->max_size().height(), bounds.height()); | |
| 357 EXPECT_LT(bounds.height(), work_area.height()); | |
| 358 panel->Close(); | |
| 359 } | |
| 360 | |
| 361 class WaitForStableInitialSize : public TestPanelNotificationObserver { | |
| 362 public: | |
| 363 explicit WaitForStableInitialSize(Panel* panel) | |
| 364 : TestPanelNotificationObserver( | |
| 365 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
| 366 content::NotificationService::AllSources()), | |
| 367 panel_(panel) {} | |
| 368 ~WaitForStableInitialSize() override {} | |
| 369 | |
| 370 protected: | |
| 371 bool AtExpectedState() override { | |
| 372 return panel_->GetBounds().height() > panel_->TitleOnlyHeight(); | |
| 373 } | |
| 374 Panel* panel_; | |
| 375 }; | |
| 376 | |
| 377 class WaitForAutoResizeWider : public TestPanelNotificationObserver { | |
| 378 public: | |
| 379 explicit WaitForAutoResizeWider(Panel* panel) | |
| 380 : TestPanelNotificationObserver( | |
| 381 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
| 382 content::NotificationService::AllSources()), | |
| 383 panel_(panel), | |
| 384 initial_size_(panel->GetBounds().size()) {} | |
| 385 ~WaitForAutoResizeWider() override {} | |
| 386 | |
| 387 protected: | |
| 388 bool AtExpectedState() override { | |
| 389 return panel_->GetBounds().width() > initial_size_.width(); | |
| 390 } | |
| 391 Panel* panel_; | |
| 392 gfx::Size initial_size_; | |
| 393 }; | |
| 394 | |
| 395 class WaitForAutoResizeNarrower : public TestPanelNotificationObserver { | |
| 396 public: | |
| 397 explicit WaitForAutoResizeNarrower(Panel* panel) | |
| 398 : TestPanelNotificationObserver( | |
| 399 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
| 400 content::NotificationService::AllSources()), | |
| 401 panel_(panel), | |
| 402 initial_size_(panel->GetBounds().size()) {} | |
| 403 ~WaitForAutoResizeNarrower() override {} | |
| 404 | |
| 405 protected: | |
| 406 bool AtExpectedState() override { | |
| 407 return panel_->GetBounds().width() < initial_size_.width(); | |
| 408 } | |
| 409 Panel* panel_; | |
| 410 gfx::Size initial_size_; | |
| 411 }; | |
| 412 | |
| 413 // crbug.com/160504 | |
| 414 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { | |
| 415 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 416 panel_manager->enable_auto_sizing(true); | |
| 417 // Bigger space is needed by this test. | |
| 418 mock_display_settings_provider()->SetPrimaryDisplay( | |
| 419 gfx::Rect(0, 0, 1200, 900), gfx::Rect(0, 0, 1200, 900)); | |
| 420 | |
| 421 // Create a test panel with web contents loaded. | |
| 422 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 423 GURL url(ui_test_utils::GetTestUrl( | |
| 424 base::FilePath(kTestDir), | |
| 425 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 426 params.url = url; | |
| 427 Panel* panel = CreatePanelWithParams(params); | |
| 428 | |
| 429 // Ensure panel has auto resized to original web content size. | |
| 430 // The resize will update the docked panel collection. | |
| 431 WaitForStableInitialSize initial_resize(panel); | |
| 432 initial_resize.Wait(); | |
| 433 gfx::Rect initial_bounds = panel->GetBounds(); | |
| 434 | |
| 435 // Expand the test page. The resize will update the docked panel collection. | |
| 436 WaitForAutoResizeWider enlarge(panel); | |
| 437 EXPECT_TRUE(content::ExecuteScript( | |
| 438 panel->GetWebContents(), "changeSize(50);")); | |
| 439 enlarge.Wait(); | |
| 440 gfx::Rect bounds_on_grow = panel->GetBounds(); | |
| 441 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); | |
| 442 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); | |
| 443 | |
| 444 // Shrink the test page. The resize will update the docked panel collection. | |
| 445 WaitForAutoResizeNarrower shrink(panel); | |
| 446 EXPECT_TRUE(content::ExecuteScript( | |
| 447 panel->GetWebContents(), "changeSize(-30);")); | |
| 448 shrink.Wait(); | |
| 449 gfx::Rect bounds_on_shrink = panel->GetBounds(); | |
| 450 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); | |
| 451 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); | |
| 452 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); | |
| 453 | |
| 454 // Verify resizing turns off auto-resizing and panel no longer auto-resizes. | |
| 455 gfx::Rect previous_bounds = panel->GetBounds(); | |
| 456 // These should be identical because the panel is expanded. | |
| 457 EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size()); | |
| 458 gfx::Size new_size(previous_bounds.size()); | |
| 459 new_size.Enlarge(5, 5); | |
| 460 gfx::Rect new_bounds(previous_bounds.origin(), new_size); | |
| 461 panel->SetBounds(new_bounds); | |
| 462 EXPECT_FALSE(panel->auto_resizable()); | |
| 463 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size()); | |
| 464 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); | |
| 465 | |
| 466 // Turn back on auto-resize and verify that panel auto resizes. | |
| 467 content::WindowedNotificationObserver auto_resize_enabled( | |
| 468 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
| 469 content::NotificationService::AllSources()); | |
| 470 panel->SetAutoResizable(true); | |
| 471 auto_resize_enabled.Wait(); | |
| 472 gfx::Rect bounds_auto_resize_enabled = panel->GetBounds(); | |
| 473 EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width()); | |
| 474 EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height()); | |
| 475 | |
| 476 panel->Close(); | |
| 477 } | |
| 478 | |
| 479 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ResizePanel) { | |
| 480 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 481 panel_manager->enable_auto_sizing(true); | |
| 482 | |
| 483 Panel* panel = CreatePanel("TestPanel"); | |
| 484 EXPECT_TRUE(panel->auto_resizable()); | |
| 485 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 486 | |
| 487 // Verify resizing turns off auto-resizing and that it works. | |
| 488 gfx::Rect original_bounds = panel->GetBounds(); | |
| 489 // These should be identical because the panel is expanded. | |
| 490 EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size()); | |
| 491 gfx::Size new_size(original_bounds.size()); | |
| 492 new_size.Enlarge(5, 5); | |
| 493 gfx::Rect new_bounds(original_bounds.origin(), new_size); | |
| 494 panel->SetBounds(new_bounds); | |
| 495 EXPECT_FALSE(panel->auto_resizable()); | |
| 496 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size()); | |
| 497 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); | |
| 498 | |
| 499 // Verify current height unaffected when panel is not expanded. | |
| 500 panel->SetExpansionState(Panel::MINIMIZED); | |
| 501 int original_height = panel->GetBounds().height(); | |
| 502 new_size.Enlarge(5, 5); | |
| 503 new_bounds.set_size(new_size); | |
| 504 panel->SetBounds(new_bounds); | |
| 505 EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width()); | |
| 506 EXPECT_EQ(original_height, panel->GetBounds().height()); | |
| 507 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); | |
| 508 | |
| 509 panel->Close(); | |
| 510 } | |
| 511 | |
| 512 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) { | |
| 513 // Create a detached panel, instead of docked panel because it cannot be | |
| 514 // moved to any location. | |
| 515 Panel* panel = CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 100)); | |
| 516 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 517 CreateNativePanelTesting(panel)); | |
| 518 | |
| 519 // Validates that no animation should be triggered when the panel is being | |
| 520 // dragged. | |
| 521 gfx::Point mouse_location(panel->GetBounds().origin()); | |
| 522 panel_testing->PressLeftMouseButtonTitlebar(mouse_location); | |
| 523 panel_testing->DragTitlebar(mouse_location + gfx::Vector2d(-100, 5)); | |
| 524 EXPECT_FALSE(panel_testing->IsAnimatingBounds()); | |
| 525 panel_testing->FinishDragTitlebar(); | |
| 526 | |
| 527 // Set bounds with animation. | |
| 528 gfx::Rect bounds = gfx::Rect(10, 20, 150, 160); | |
| 529 panel->SetPanelBounds(bounds); | |
| 530 EXPECT_TRUE(panel_testing->IsAnimatingBounds()); | |
| 531 WaitForBoundsAnimationFinished(panel); | |
| 532 EXPECT_FALSE(panel_testing->IsAnimatingBounds()); | |
| 533 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 534 | |
| 535 // Set bounds without animation. | |
| 536 bounds = gfx::Rect(30, 40, 200, 220); | |
| 537 panel->SetPanelBoundsInstantly(bounds); | |
| 538 EXPECT_FALSE(panel_testing->IsAnimatingBounds()); | |
| 539 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 540 | |
| 541 panel->Close(); | |
| 542 } | |
| 543 | |
| 544 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { | |
| 545 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100)); | |
| 546 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 547 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds()); | |
| 548 | |
| 549 panel->SetExpansionState(Panel::MINIMIZED); | |
| 550 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 551 gfx::Rect bounds = panel->GetBounds(); | |
| 552 gfx::Rect restored = panel->GetRestoredBounds(); | |
| 553 EXPECT_EQ(bounds.x(), restored.x()); | |
| 554 EXPECT_GT(bounds.y(), restored.y()); | |
| 555 EXPECT_EQ(bounds.width(), restored.width()); | |
| 556 EXPECT_LT(bounds.height(), restored.height()); | |
| 557 | |
| 558 panel->SetExpansionState(Panel::TITLE_ONLY); | |
| 559 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
| 560 bounds = panel->GetBounds(); | |
| 561 restored = panel->GetRestoredBounds(); | |
| 562 EXPECT_EQ(bounds.x(), restored.x()); | |
| 563 EXPECT_GT(bounds.y(), restored.y()); | |
| 564 EXPECT_EQ(bounds.width(), restored.width()); | |
| 565 EXPECT_LT(bounds.height(), restored.height()); | |
| 566 | |
| 567 panel->SetExpansionState(Panel::MINIMIZED); | |
| 568 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 569 bounds = panel->GetBounds(); | |
| 570 restored = panel->GetRestoredBounds(); | |
| 571 EXPECT_EQ(bounds.x(), restored.x()); | |
| 572 EXPECT_GT(bounds.y(), restored.y()); | |
| 573 EXPECT_EQ(bounds.width(), restored.width()); | |
| 574 EXPECT_LT(bounds.height(), restored.height()); | |
| 575 | |
| 576 panel->SetExpansionState(Panel::EXPANDED); | |
| 577 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds()); | |
| 578 | |
| 579 // Verify that changing the panel bounds does not affect the restored height. | |
| 580 int saved_restored_height = restored.height(); | |
| 581 panel->SetExpansionState(Panel::MINIMIZED); | |
| 582 bounds = gfx::Rect(10, 20, 300, 400); | |
| 583 panel->SetPanelBounds(bounds); | |
| 584 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); | |
| 585 | |
| 586 panel->SetExpansionState(Panel::TITLE_ONLY); | |
| 587 bounds = gfx::Rect(20, 30, 100, 200); | |
| 588 panel->SetPanelBounds(bounds); | |
| 589 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); | |
| 590 | |
| 591 panel->SetExpansionState(Panel::EXPANDED); | |
| 592 bounds = gfx::Rect(40, 60, 300, 400); | |
| 593 panel->SetPanelBounds(bounds); | |
| 594 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); | |
| 595 panel->set_full_size(bounds.size()); | |
| 596 EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height()); | |
| 597 | |
| 598 panel->Close(); | |
| 599 } | |
| 600 | |
| 601 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestore) { | |
| 602 // Test with one panel. | |
| 603 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); | |
| 604 TestMinimizeRestore(); | |
| 605 | |
| 606 PanelManager::GetInstance()->CloseAll(); | |
| 607 } | |
| 608 | |
| 609 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) { | |
| 610 // Test with two panels. | |
| 611 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); | |
| 612 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110)); | |
| 613 TestMinimizeRestore(); | |
| 614 | |
| 615 PanelManager::GetInstance()->CloseAll(); | |
| 616 } | |
| 617 | |
| 618 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreThreePanels) { | |
| 619 // Test with three panels. | |
| 620 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); | |
| 621 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110)); | |
| 622 CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120)); | |
| 623 TestMinimizeRestore(); | |
| 624 | |
| 625 PanelManager::GetInstance()->CloseAll(); | |
| 626 } | |
| 627 | |
| 628 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreButtonClick) { | |
| 629 // Test with three panels. | |
| 630 Panel* panel1 = CreatePanel("PanelTest1"); | |
| 631 Panel* panel2 = CreatePanel("PanelTest2"); | |
| 632 Panel* panel3 = CreatePanel("PanelTest3"); | |
| 633 EXPECT_FALSE(panel1->IsMinimized()); | |
| 634 EXPECT_FALSE(panel2->IsMinimized()); | |
| 635 EXPECT_FALSE(panel3->IsMinimized()); | |
| 636 | |
| 637 // Click restore button on an expanded panel. Expect no change. | |
| 638 panel1->OnRestoreButtonClicked(panel::NO_MODIFIER); | |
| 639 EXPECT_FALSE(panel1->IsMinimized()); | |
| 640 EXPECT_FALSE(panel2->IsMinimized()); | |
| 641 EXPECT_FALSE(panel3->IsMinimized()); | |
| 642 | |
| 643 // Click minimize button on an expanded panel. Only that panel will minimize. | |
| 644 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER); | |
| 645 EXPECT_TRUE(panel1->IsMinimized()); | |
| 646 EXPECT_FALSE(panel2->IsMinimized()); | |
| 647 EXPECT_FALSE(panel3->IsMinimized()); | |
| 648 | |
| 649 // Click minimize button on a minimized panel. Expect no change. | |
| 650 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER); | |
| 651 EXPECT_TRUE(panel1->IsMinimized()); | |
| 652 EXPECT_FALSE(panel2->IsMinimized()); | |
| 653 EXPECT_FALSE(panel3->IsMinimized()); | |
| 654 | |
| 655 // Minimize all panels by clicking minimize button on an expanded panel | |
| 656 // with the apply-all modifier. | |
| 657 panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL); | |
| 658 EXPECT_TRUE(panel1->IsMinimized()); | |
| 659 EXPECT_TRUE(panel2->IsMinimized()); | |
| 660 EXPECT_TRUE(panel3->IsMinimized()); | |
| 661 | |
| 662 // Click restore button on a minimized panel. Only that panel will restore. | |
| 663 panel2->OnRestoreButtonClicked(panel::NO_MODIFIER); | |
| 664 EXPECT_TRUE(panel1->IsMinimized()); | |
| 665 EXPECT_FALSE(panel2->IsMinimized()); | |
| 666 EXPECT_TRUE(panel3->IsMinimized()); | |
| 667 | |
| 668 // Restore all panels by clicking restore button on a minimized panel. | |
| 669 panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL); | |
| 670 EXPECT_FALSE(panel1->IsMinimized()); | |
| 671 EXPECT_FALSE(panel2->IsMinimized()); | |
| 672 EXPECT_FALSE(panel3->IsMinimized()); | |
| 673 } | |
| 674 | |
| 675 // http://crbug.com/243891 flaky on Linux | |
| 676 #if defined(OS_LINUX) | |
| 677 #define MAYBE_RestoreAllWithTitlebarClick DISABLED_RestoreAllWithTitlebarClick | |
| 678 #else | |
| 679 #define MAYBE_RestoreAllWithTitlebarClick RestoreAllWithTitlebarClick | |
| 680 #endif | |
| 681 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_RestoreAllWithTitlebarClick) { | |
| 682 // Test with three panels. | |
| 683 Panel* panel1 = CreatePanel("PanelTest1"); | |
| 684 Panel* panel2 = CreatePanel("PanelTest2"); | |
| 685 Panel* panel3 = CreatePanel("PanelTest3"); | |
| 686 EXPECT_FALSE(panel1->IsMinimized()); | |
| 687 EXPECT_FALSE(panel2->IsMinimized()); | |
| 688 EXPECT_FALSE(panel3->IsMinimized()); | |
| 689 | |
| 690 std::unique_ptr<NativePanelTesting> test_panel1( | |
| 691 CreateNativePanelTesting(panel1)); | |
| 692 std::unique_ptr<NativePanelTesting> test_panel2( | |
| 693 CreateNativePanelTesting(panel2)); | |
| 694 std::unique_ptr<NativePanelTesting> test_panel3( | |
| 695 CreateNativePanelTesting(panel3)); | |
| 696 | |
| 697 // Click on an expanded panel's titlebar using the apply-all modifier. | |
| 698 // Verify expansion state is unchanged. | |
| 699 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), | |
| 700 panel::APPLY_TO_ALL); | |
| 701 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 702 EXPECT_FALSE(panel1->IsMinimized()); | |
| 703 EXPECT_FALSE(panel2->IsMinimized()); | |
| 704 EXPECT_FALSE(panel3->IsMinimized()); | |
| 705 | |
| 706 // Click on a minimized panel's titlebar using the apply-all modifier. | |
| 707 panel1->Minimize(); | |
| 708 panel2->Minimize(); | |
| 709 panel3->Minimize(); | |
| 710 EXPECT_TRUE(panel1->IsMinimized()); | |
| 711 EXPECT_TRUE(panel2->IsMinimized()); | |
| 712 EXPECT_TRUE(panel3->IsMinimized()); | |
| 713 | |
| 714 // Nothing changes until mouse is released. | |
| 715 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), | |
| 716 panel::APPLY_TO_ALL); | |
| 717 EXPECT_TRUE(panel1->IsMinimized()); | |
| 718 EXPECT_TRUE(panel2->IsMinimized()); | |
| 719 EXPECT_TRUE(panel3->IsMinimized()); | |
| 720 // Verify all panels restored when mouse is released. | |
| 721 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 722 EXPECT_FALSE(panel1->IsMinimized()); | |
| 723 EXPECT_FALSE(panel2->IsMinimized()); | |
| 724 EXPECT_FALSE(panel3->IsMinimized()); | |
| 725 | |
| 726 // Minimize a single panel. Then click on expanded panel with apply-all | |
| 727 // modifier. Verify nothing changes. | |
| 728 panel1->Minimize(); | |
| 729 EXPECT_TRUE(panel1->IsMinimized()); | |
| 730 EXPECT_FALSE(panel2->IsMinimized()); | |
| 731 EXPECT_FALSE(panel3->IsMinimized()); | |
| 732 | |
| 733 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), | |
| 734 panel::APPLY_TO_ALL); | |
| 735 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 736 EXPECT_TRUE(panel1->IsMinimized()); | |
| 737 EXPECT_FALSE(panel2->IsMinimized()); | |
| 738 EXPECT_FALSE(panel3->IsMinimized()); | |
| 739 | |
| 740 // Minimize another panel. Then click on a minimized panel with apply-all | |
| 741 // modifier to restore all panels. | |
| 742 panel2->Minimize(); | |
| 743 EXPECT_TRUE(panel1->IsMinimized()); | |
| 744 EXPECT_TRUE(panel2->IsMinimized()); | |
| 745 EXPECT_FALSE(panel3->IsMinimized()); | |
| 746 | |
| 747 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), | |
| 748 panel::APPLY_TO_ALL); | |
| 749 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 750 EXPECT_FALSE(panel1->IsMinimized()); | |
| 751 EXPECT_FALSE(panel2->IsMinimized()); | |
| 752 EXPECT_FALSE(panel3->IsMinimized()); | |
| 753 | |
| 754 // Click on the single minimized panel. Verify all are restored. | |
| 755 panel1->Minimize(); | |
| 756 EXPECT_TRUE(panel1->IsMinimized()); | |
| 757 EXPECT_FALSE(panel2->IsMinimized()); | |
| 758 EXPECT_FALSE(panel3->IsMinimized()); | |
| 759 | |
| 760 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), | |
| 761 panel::APPLY_TO_ALL); | |
| 762 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 763 EXPECT_FALSE(panel1->IsMinimized()); | |
| 764 EXPECT_FALSE(panel2->IsMinimized()); | |
| 765 EXPECT_FALSE(panel3->IsMinimized()); | |
| 766 | |
| 767 // Click on the single expanded panel. Verify nothing changes. | |
| 768 panel1->Minimize(); | |
| 769 panel3->Minimize(); | |
| 770 EXPECT_TRUE(panel1->IsMinimized()); | |
| 771 EXPECT_FALSE(panel2->IsMinimized()); | |
| 772 EXPECT_TRUE(panel3->IsMinimized()); | |
| 773 | |
| 774 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), | |
| 775 panel::APPLY_TO_ALL); | |
| 776 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 777 EXPECT_TRUE(panel1->IsMinimized()); | |
| 778 EXPECT_FALSE(panel2->IsMinimized()); | |
| 779 EXPECT_TRUE(panel3->IsMinimized()); | |
| 780 | |
| 781 // Hover over a minimized panel and click on the titlebar while it is in | |
| 782 // title-only mode. Should restore all panels. | |
| 783 panel2->Minimize(); | |
| 784 EXPECT_TRUE(panel1->IsMinimized()); | |
| 785 EXPECT_TRUE(panel2->IsMinimized()); | |
| 786 EXPECT_TRUE(panel3->IsMinimized()); | |
| 787 | |
| 788 MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin()); | |
| 789 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 790 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); | |
| 791 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); | |
| 792 | |
| 793 test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(), | |
| 794 panel::APPLY_TO_ALL); | |
| 795 test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 796 EXPECT_FALSE(panel1->IsMinimized()); | |
| 797 EXPECT_FALSE(panel2->IsMinimized()); | |
| 798 EXPECT_FALSE(panel3->IsMinimized()); | |
| 799 | |
| 800 // Draw attention to a minimized panel. Click on a minimized panel that is | |
| 801 // not drawing attention. Verify restore all applies without affecting | |
| 802 // draw attention. | |
| 803 panel1->Minimize(); | |
| 804 panel2->Minimize(); | |
| 805 panel3->Minimize(); | |
| 806 EXPECT_TRUE(panel1->IsMinimized()); | |
| 807 EXPECT_TRUE(panel2->IsMinimized()); | |
| 808 EXPECT_TRUE(panel3->IsMinimized()); | |
| 809 | |
| 810 panel1->FlashFrame(true); | |
| 811 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 812 | |
| 813 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), | |
| 814 panel::APPLY_TO_ALL); | |
| 815 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 816 EXPECT_FALSE(panel1->IsMinimized()); | |
| 817 EXPECT_FALSE(panel2->IsMinimized()); | |
| 818 EXPECT_FALSE(panel3->IsMinimized()); | |
| 819 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 820 | |
| 821 // Restore all panels by clicking on the minimized panel that is drawing | |
| 822 // attention. Verify restore all applies and clears draw attention. | |
| 823 panel1->Minimize(); | |
| 824 panel2->Minimize(); | |
| 825 panel3->Minimize(); | |
| 826 EXPECT_TRUE(panel1->IsMinimized()); | |
| 827 EXPECT_TRUE(panel2->IsMinimized()); | |
| 828 EXPECT_TRUE(panel3->IsMinimized()); | |
| 829 | |
| 830 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), | |
| 831 panel::APPLY_TO_ALL); | |
| 832 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); | |
| 833 EXPECT_FALSE(panel1->IsMinimized()); | |
| 834 EXPECT_FALSE(panel2->IsMinimized()); | |
| 835 EXPECT_FALSE(panel3->IsMinimized()); | |
| 836 EXPECT_FALSE(panel1->IsDrawingAttention()); | |
| 837 | |
| 838 PanelManager::GetInstance()->CloseAll(); | |
| 839 } | |
| 840 | |
| 841 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 842 MinimizeRestoreOnAutoHidingDesktopBar) { | |
| 843 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 844 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
| 845 int expected_bottom_on_expanded = docked_collection->work_area().bottom(); | |
| 846 int expected_bottom_on_title_only = expected_bottom_on_expanded; | |
| 847 int expected_bottom_on_minimized = expected_bottom_on_expanded; | |
| 848 | |
| 849 // Turn on auto-hiding. | |
| 850 static const int bottom_bar_thickness = 40; | |
| 851 mock_display_settings_provider()->EnableAutoHidingDesktopBar( | |
| 852 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, | |
| 853 true, | |
| 854 bottom_bar_thickness); | |
| 855 expected_bottom_on_title_only -= bottom_bar_thickness; | |
| 856 | |
| 857 Panel* panel = CreatePanel("1"); | |
| 858 int initial_height = panel->GetBounds().height(); | |
| 859 | |
| 860 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 861 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom()); | |
| 862 | |
| 863 panel->Minimize(); | |
| 864 WaitForBoundsAnimationFinished(panel); | |
| 865 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 866 EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height()); | |
| 867 EXPECT_EQ(expected_bottom_on_minimized, panel->GetBounds().bottom()); | |
| 868 | |
| 869 panel->SetExpansionState(Panel::TITLE_ONLY); | |
| 870 WaitForBoundsAnimationFinished(panel); | |
| 871 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
| 872 EXPECT_EQ(panel::kTitlebarHeight, panel->GetBounds().height()); | |
| 873 EXPECT_EQ(expected_bottom_on_title_only, panel->GetBounds().bottom()); | |
| 874 | |
| 875 panel->Restore(); | |
| 876 WaitForBoundsAnimationFinished(panel); | |
| 877 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 878 EXPECT_EQ(initial_height, panel->GetBounds().height()); | |
| 879 EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom()); | |
| 880 | |
| 881 panel->Close(); | |
| 882 } | |
| 883 | |
| 884 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ChangeAutoHideTaskBarThickness) { | |
| 885 PanelManager* manager = PanelManager::GetInstance(); | |
| 886 DockedPanelCollection* docked_collection = manager->docked_collection(); | |
| 887 int initial_starting_right_position = | |
| 888 docked_collection->StartingRightPosition(); | |
| 889 | |
| 890 int bottom_bar_thickness = 20; | |
| 891 int right_bar_thickness = 30; | |
| 892 mock_display_settings_provider()->EnableAutoHidingDesktopBar( | |
| 893 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, | |
| 894 true, | |
| 895 bottom_bar_thickness); | |
| 896 mock_display_settings_provider()->EnableAutoHidingDesktopBar( | |
| 897 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, | |
| 898 true, | |
| 899 right_bar_thickness); | |
| 900 EXPECT_EQ(initial_starting_right_position, | |
| 901 docked_collection->StartingRightPosition()); | |
| 902 | |
| 903 Panel* panel = CreatePanel("PanelTest"); | |
| 904 panel->SetExpansionState(Panel::TITLE_ONLY); | |
| 905 WaitForBoundsAnimationFinished(panel); | |
| 906 | |
| 907 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness, | |
| 908 panel->GetBounds().bottom()); | |
| 909 EXPECT_EQ(docked_collection->StartingRightPosition(), | |
| 910 panel->GetBounds().right()); | |
| 911 | |
| 912 initial_starting_right_position = docked_collection->StartingRightPosition(); | |
| 913 int bottom_bar_thickness_delta = 10; | |
| 914 bottom_bar_thickness += bottom_bar_thickness_delta; | |
| 915 int right_bar_thickness_delta = 15; | |
| 916 right_bar_thickness += right_bar_thickness_delta; | |
| 917 mock_display_settings_provider()->SetDesktopBarThickness( | |
| 918 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, | |
| 919 bottom_bar_thickness); | |
| 920 mock_display_settings_provider()->SetDesktopBarThickness( | |
| 921 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, | |
| 922 right_bar_thickness); | |
| 923 base::MessageLoopForUI::current()->RunUntilIdle(); | |
| 924 EXPECT_EQ(initial_starting_right_position, | |
| 925 docked_collection->StartingRightPosition()); | |
| 926 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness, | |
| 927 panel->GetBounds().bottom()); | |
| 928 EXPECT_EQ(docked_collection->StartingRightPosition(), | |
| 929 panel->GetBounds().right()); | |
| 930 | |
| 931 initial_starting_right_position = docked_collection->StartingRightPosition(); | |
| 932 bottom_bar_thickness_delta = 20; | |
| 933 bottom_bar_thickness -= bottom_bar_thickness_delta; | |
| 934 right_bar_thickness_delta = 10; | |
| 935 right_bar_thickness -= right_bar_thickness_delta; | |
| 936 mock_display_settings_provider()->SetDesktopBarThickness( | |
| 937 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, | |
| 938 bottom_bar_thickness); | |
| 939 mock_display_settings_provider()->SetDesktopBarThickness( | |
| 940 DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, | |
| 941 right_bar_thickness); | |
| 942 base::MessageLoopForUI::current()->RunUntilIdle(); | |
| 943 EXPECT_EQ(docked_collection->StartingRightPosition(), | |
| 944 initial_starting_right_position); | |
| 945 EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness, | |
| 946 panel->GetBounds().bottom()); | |
| 947 EXPECT_EQ(docked_collection->StartingRightPosition(), | |
| 948 panel->GetBounds().right()); | |
| 949 | |
| 950 panel->Close(); | |
| 951 } | |
| 952 | |
| 953 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivatePanelOrTabbedWindow) { | |
| 954 if (!WmSupportWindowActivation()) { | |
| 955 LOG(WARNING) << "Skipping test due to WM problems."; | |
| 956 return; | |
| 957 } | |
| 958 | |
| 959 Panel* panel1 = CreatePanel("Panel1"); | |
| 960 Panel* panel2 = CreatePanel("Panel2"); | |
| 961 | |
| 962 // Activate main tabbed window. | |
| 963 browser()->window()->Activate(); | |
| 964 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); | |
| 965 | |
| 966 // Activate a panel. | |
| 967 panel2->Activate(); | |
| 968 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); | |
| 969 | |
| 970 // Activate the main tabbed window back. | |
| 971 browser()->window()->Activate(); | |
| 972 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); | |
| 973 | |
| 974 // Activate another panel. | |
| 975 panel1->Activate(); | |
| 976 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); | |
| 977 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); | |
| 978 | |
| 979 // Switch focus between panels. | |
| 980 panel2->Activate(); | |
| 981 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); | |
| 982 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); | |
| 983 | |
| 984 PanelManager::GetInstance()->CloseAll(); | |
| 985 } | |
| 986 | |
| 987 // TODO(jianli): To be enabled for other platforms. | |
| 988 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 989 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic | |
| 990 #else | |
| 991 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic | |
| 992 #endif | |
| 993 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) { | |
| 994 if (!WmSupportWindowActivation()) { | |
| 995 LOG(WARNING) << "Skipping test due to WM problems."; | |
| 996 return; | |
| 997 } | |
| 998 | |
| 999 // Create an active panel. | |
| 1000 Panel* panel = CreatePanel("PanelTest"); | |
| 1001 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1002 CreateNativePanelTesting(panel)); | |
| 1003 | |
| 1004 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state | |
| 1005 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); | |
| 1006 | |
| 1007 // Deactivate the panel. | |
| 1008 panel->Deactivate(); | |
| 1009 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); | |
| 1010 | |
| 1011 // On GTK there is no way to deactivate a window. So the Deactivate() call | |
| 1012 // above does not actually deactivate the window, but simply lowers it. | |
| 1013 #if !defined(OS_LINUX) | |
| 1014 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false)); | |
| 1015 #endif | |
| 1016 | |
| 1017 // This test does not reactivate the panel because the panel might not be | |
| 1018 // reactivated programmatically once it is deactivated. | |
| 1019 } | |
| 1020 | |
| 1021 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivateDeactivateMultiple) { | |
| 1022 if (!WmSupportWindowActivation()) { | |
| 1023 LOG(WARNING) << "Skipping test due to WM problems."; | |
| 1024 return; | |
| 1025 } | |
| 1026 | |
| 1027 BrowserWindow* tabbed_window = browser()->window(); | |
| 1028 | |
| 1029 // Create 4 panels in the following screen layout: | |
| 1030 // P3 P2 P1 P0 | |
| 1031 const int kNumPanels = 4; | |
| 1032 for (int i = 0; i < kNumPanels; ++i) | |
| 1033 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100)); | |
| 1034 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); | |
| 1035 | |
| 1036 std::vector<bool> expected_active_states; | |
| 1037 std::vector<bool> last_active_states; | |
| 1038 | |
| 1039 // The last created panel, P3, should be active. | |
| 1040 expected_active_states = ProduceExpectedActiveStates(3); | |
| 1041 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); | |
| 1042 EXPECT_FALSE(tabbed_window->IsActive()); | |
| 1043 | |
| 1044 // Activating P1 should cause P3 to lose focus. | |
| 1045 panels[1]->Activate(); | |
| 1046 last_active_states = expected_active_states; | |
| 1047 expected_active_states = ProduceExpectedActiveStates(1); | |
| 1048 WaitForPanelActiveStates(last_active_states, expected_active_states); | |
| 1049 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); | |
| 1050 | |
| 1051 // Minimizing inactive panel P2 should not affect other panels' active states. | |
| 1052 panels[2]->SetExpansionState(Panel::MINIMIZED); | |
| 1053 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); | |
| 1054 EXPECT_FALSE(tabbed_window->IsActive()); | |
| 1055 } | |
| 1056 | |
| 1057 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) { | |
| 1058 Panel* panel = CreateInactivePanel("P1"); | |
| 1059 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1060 CreateNativePanelTesting(panel)); | |
| 1061 | |
| 1062 // Test that the attention is drawn when the expanded panel is not in focus. | |
| 1063 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 1064 EXPECT_FALSE(panel->IsActive()); | |
| 1065 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1066 panel->FlashFrame(true); | |
| 1067 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1068 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); | |
| 1069 | |
| 1070 // Stop drawing attention. | |
| 1071 panel->FlashFrame(false); | |
| 1072 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1073 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | |
| 1074 | |
| 1075 // Draw attention, then minimize. Titlebar should remain visible. | |
| 1076 panel->FlashFrame(true); | |
| 1077 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1078 | |
| 1079 panel->Minimize(); | |
| 1080 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1081 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | |
| 1082 | |
| 1083 // Stop drawing attention. Titlebar should no longer be visible. | |
| 1084 panel->FlashFrame(false); | |
| 1085 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1086 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 1087 | |
| 1088 panel->Close(); | |
| 1089 } | |
| 1090 | |
| 1091 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) { | |
| 1092 Panel* panel1 = CreateInactivePanel("P1"); | |
| 1093 Panel* panel2 = CreateInactivePanel("P2"); | |
| 1094 | |
| 1095 std::unique_ptr<NativePanelTesting> native_panel1_testing( | |
| 1096 CreateNativePanelTesting(panel1)); | |
| 1097 | |
| 1098 // Test that the attention is drawn and the title-bar is brought up when the | |
| 1099 // minimized panel is drawing attention. | |
| 1100 panel1->Minimize(); | |
| 1101 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1102 panel1->FlashFrame(true); | |
| 1103 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 1104 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1105 EXPECT_TRUE(native_panel1_testing->VerifyDrawingAttention()); | |
| 1106 | |
| 1107 // Test that we cannot bring up other minimized panel if the mouse is over | |
| 1108 // the panel that draws attension. | |
| 1109 panel2->Minimize(); | |
| 1110 gfx::Point hover_point(panel1->GetBounds().origin()); | |
| 1111 MoveMouse(hover_point); | |
| 1112 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1113 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1114 | |
| 1115 // Test that we cannot bring down the panel that is drawing the attention. | |
| 1116 hover_point.set_y(hover_point.y() - 200); | |
| 1117 MoveMouse(hover_point); | |
| 1118 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1119 | |
| 1120 // Test that the attention is cleared when activated. | |
| 1121 panel1->Activate(); | |
| 1122 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); | |
| 1123 EXPECT_FALSE(panel1->IsDrawingAttention()); | |
| 1124 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | |
| 1125 EXPECT_FALSE(native_panel1_testing->VerifyDrawingAttention()); | |
| 1126 | |
| 1127 PanelManager::GetInstance()->CloseAll(); | |
| 1128 } | |
| 1129 | |
| 1130 // Verify that minimized state of a panel is correct after draw attention | |
| 1131 // is stopped when there are other minimized panels. | |
| 1132 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, StopDrawingAttentionWhileMinimized) { | |
| 1133 Panel* panel1 = CreateInactivePanel("P1"); | |
| 1134 Panel* panel2 = CreateInactivePanel("P2"); | |
| 1135 | |
| 1136 panel1->Minimize(); | |
| 1137 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1138 panel2->Minimize(); | |
| 1139 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1140 | |
| 1141 // Verify panel returns to minimized state when no longer drawing attention. | |
| 1142 panel1->FlashFrame(true); | |
| 1143 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 1144 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1145 | |
| 1146 panel1->FlashFrame(false); | |
| 1147 EXPECT_FALSE(panel1->IsDrawingAttention()); | |
| 1148 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1149 | |
| 1150 // Hover over other minimized panel to bring up titlebars. | |
| 1151 gfx::Point hover_point(panel2->GetBounds().origin()); | |
| 1152 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); | |
| 1153 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1154 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); | |
| 1155 | |
| 1156 // Verify panel keeps titlebar visible when no longer drawing attention | |
| 1157 // if titlebars are up. | |
| 1158 panel1->FlashFrame(true); | |
| 1159 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 1160 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1161 | |
| 1162 panel1->FlashFrame(false); | |
| 1163 EXPECT_FALSE(panel1->IsDrawingAttention()); | |
| 1164 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1165 | |
| 1166 // Move mouse away. All panels should return to minimized state. | |
| 1167 hover_point.set_y(hover_point.y() - 200); | |
| 1168 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); | |
| 1169 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1170 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1171 | |
| 1172 // Verify minimized panel that is drawing attention stays in title-only mode | |
| 1173 // after attention is cleared if mouse is in the titlebar area. | |
| 1174 panel1->FlashFrame(true); | |
| 1175 EXPECT_TRUE(panel1->IsDrawingAttention()); | |
| 1176 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1177 | |
| 1178 gfx::Point hover_point_in_panel(panel1->GetBounds().origin()); | |
| 1179 MoveMouse(hover_point_in_panel); | |
| 1180 | |
| 1181 panel1->FlashFrame(false); | |
| 1182 EXPECT_FALSE(panel1->IsDrawingAttention()); | |
| 1183 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1184 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1185 | |
| 1186 // Typical user scenario will detect the mouse in the panel | |
| 1187 // after attention is cleared, causing titles to pop up, so | |
| 1188 // we simulate that here. | |
| 1189 MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel); | |
| 1190 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 1191 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); | |
| 1192 | |
| 1193 // Move mouse away and panels should go back to fully minimized state. | |
| 1194 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); | |
| 1195 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1196 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1197 | |
| 1198 PanelManager::GetInstance()->CloseAll(); | |
| 1199 } | |
| 1200 | |
| 1201 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) { | |
| 1202 // Create an active panel. | |
| 1203 Panel* panel = CreatePanel("P1"); | |
| 1204 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1205 CreateNativePanelTesting(panel)); | |
| 1206 | |
| 1207 // Test that the attention should not be drawn if the expanded panel is in | |
| 1208 // focus. | |
| 1209 panel->FlashFrame(true); | |
| 1210 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1211 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | |
| 1212 | |
| 1213 panel->Close(); | |
| 1214 } | |
| 1215 | |
| 1216 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) { | |
| 1217 Panel* panel = CreateInactivePanel("P1"); | |
| 1218 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1219 CreateNativePanelTesting(panel)); | |
| 1220 | |
| 1221 panel->FlashFrame(true); | |
| 1222 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1223 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); | |
| 1224 | |
| 1225 // Test that the attention is cleared when panel gets focus. | |
| 1226 panel->Activate(); | |
| 1227 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); | |
| 1228 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1229 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | |
| 1230 | |
| 1231 panel->Close(); | |
| 1232 } | |
| 1233 | |
| 1234 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1235 DrawAttentionMinimizedNotResetOnActivate) { | |
| 1236 Panel* panel = CreateInactivePanel("P1"); | |
| 1237 | |
| 1238 panel->Minimize(); | |
| 1239 EXPECT_TRUE(panel->IsMinimized()); | |
| 1240 panel->FlashFrame(true); | |
| 1241 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1242 | |
| 1243 // Simulate panel being activated while minimized. Cannot call | |
| 1244 // Activate() as that expands the panel. | |
| 1245 panel->OnActiveStateChanged(true); | |
| 1246 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged. | |
| 1247 | |
| 1248 // Unminimize panel to show that attention would have been cleared | |
| 1249 // if panel had not been minimized. | |
| 1250 panel->Restore(); | |
| 1251 EXPECT_FALSE(panel->IsMinimized()); | |
| 1252 EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged. | |
| 1253 | |
| 1254 panel->OnActiveStateChanged(true); | |
| 1255 EXPECT_FALSE(panel->IsDrawingAttention()); // Attention cleared. | |
| 1256 | |
| 1257 panel->Close(); | |
| 1258 } | |
| 1259 | |
| 1260 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) { | |
| 1261 Panel* panel = CreateInactivePanel("P1"); | |
| 1262 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1263 CreateNativePanelTesting(panel)); | |
| 1264 | |
| 1265 panel->FlashFrame(true); | |
| 1266 EXPECT_TRUE(panel->IsDrawingAttention()); | |
| 1267 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); | |
| 1268 | |
| 1269 // Test that the attention is cleared when panel gets focus. | |
| 1270 native_panel_testing->PressLeftMouseButtonTitlebar( | |
| 1271 panel->GetBounds().origin()); | |
| 1272 native_panel_testing->ReleaseMouseButtonTitlebar(); | |
| 1273 | |
| 1274 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); | |
| 1275 EXPECT_FALSE(panel->IsDrawingAttention()); | |
| 1276 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); | |
| 1277 | |
| 1278 panel->Close(); | |
| 1279 } | |
| 1280 | |
| 1281 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
| 1282 #if defined(OS_MACOSX) | |
| 1283 #define MAYBE_MinimizeImmediatelyAfterRestore \ | |
| 1284 DISABLED_MinimizeImmediatelyAfterRestore | |
| 1285 #else | |
| 1286 #define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore | |
| 1287 #endif | |
| 1288 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1289 MAYBE_MinimizeImmediatelyAfterRestore) { | |
| 1290 CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1291 Panel* panel = CreatePanelWithParams(params); | |
| 1292 std::unique_ptr<NativePanelTesting> native_panel_testing( | |
| 1293 CreateNativePanelTesting(panel)); | |
| 1294 | |
| 1295 PanelActiveStateObserver signal(panel, false); | |
| 1296 panel->Minimize(); // this should deactivate. | |
| 1297 signal.Wait(); | |
| 1298 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 1299 | |
| 1300 panel->Restore(); | |
| 1301 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 1302 | |
| 1303 // Verify that minimizing a panel right after expansion works. | |
| 1304 panel->Minimize(); | |
| 1305 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | |
| 1306 | |
| 1307 panel->Close(); | |
| 1308 } | |
| 1309 | |
| 1310 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) { | |
| 1311 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1312 Panel* panel = CreatePanelWithParams(params); | |
| 1313 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | |
| 1314 | |
| 1315 PanelActiveStateObserver signal(panel, false); | |
| 1316 panel->Minimize(); | |
| 1317 signal.Wait(); | |
| 1318 panel->Close(); | |
| 1319 } | |
| 1320 | |
| 1321 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) { | |
| 1322 Panel* panel = CreateInactivePanel("1"); | |
| 1323 | |
| 1324 panel->Activate(); | |
| 1325 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); | |
| 1326 | |
| 1327 panel->Close(); | |
| 1328 } | |
| 1329 | |
| 1330 // TODO(dimich): try/enable on other platforms. See bug 103253 for details on | |
| 1331 // why this is disabled on windows. | |
| 1332 #if defined(OS_MACOSX) | |
| 1333 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ | |
| 1334 MinimizeTwoPanelsWithoutTabbedWindow | |
| 1335 #else | |
| 1336 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ | |
| 1337 DISABLED_MinimizeTwoPanelsWithoutTabbedWindow | |
| 1338 #endif | |
| 1339 | |
| 1340 // When there are 2 panels and no chrome window, minimizing one panel does | |
| 1341 // not expand/focuses another. | |
| 1342 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1343 MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) { | |
| 1344 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); | |
| 1345 Panel* panel1 = CreatePanelWithParams(params); | |
| 1346 Panel* panel2 = CreatePanelWithParams(params); | |
| 1347 | |
| 1348 // Close main tabbed window. | |
| 1349 content::WindowedNotificationObserver signal( | |
| 1350 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 1351 content::Source<Browser>(browser())); | |
| 1352 chrome::CloseWindow(browser()); | |
| 1353 signal.Wait(); | |
| 1354 | |
| 1355 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | |
| 1356 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | |
| 1357 panel1->Activate(); | |
| 1358 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); | |
| 1359 | |
| 1360 panel1->SetExpansionState(Panel::MINIMIZED); | |
| 1361 base::RunLoop().RunUntilIdle(); | |
| 1362 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); | |
| 1363 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1364 | |
| 1365 panel2->SetExpansionState(Panel::MINIMIZED); | |
| 1366 base::RunLoop().RunUntilIdle(); | |
| 1367 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); | |
| 1368 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); | |
| 1369 | |
| 1370 // Verify that panel1 is still minimized and not active. | |
| 1371 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); | |
| 1372 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 1373 | |
| 1374 // Another check for the same. | |
| 1375 EXPECT_FALSE(panel1->IsActive()); | |
| 1376 EXPECT_FALSE(panel2->IsActive()); | |
| 1377 | |
| 1378 panel1->Close(); | |
| 1379 panel2->Close(); | |
| 1380 } | |
| 1381 | |
| 1382 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1383 NonExtensionDomainPanelsCloseOnUninstall) { | |
| 1384 // Create a test extension. | |
| 1385 base::DictionaryValue empty_value; | |
| 1386 scoped_refptr<extensions::Extension> extension = | |
| 1387 CreateExtension(FILE_PATH_LITERAL("TestExtension"), | |
| 1388 extensions::Manifest::INTERNAL, empty_value); | |
| 1389 std::string extension_app_name = | |
| 1390 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | |
| 1391 | |
| 1392 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 1393 EXPECT_EQ(0, panel_manager->num_panels()); | |
| 1394 | |
| 1395 // Create a panel with the extension as host. | |
| 1396 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1397 std::string extension_domain_url(extensions::kExtensionScheme); | |
| 1398 extension_domain_url += "://"; | |
| 1399 extension_domain_url += extension->id(); | |
| 1400 extension_domain_url += "/hello.html"; | |
| 1401 params.url = GURL(extension_domain_url); | |
| 1402 Panel* panel = CreatePanelWithParams(params); | |
| 1403 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1404 | |
| 1405 // Create a panel with a non-extension host. | |
| 1406 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1407 params1.url = GURL(url::kAboutBlankURL); | |
| 1408 Panel* panel1 = CreatePanelWithParams(params1); | |
| 1409 EXPECT_EQ(2, panel_manager->num_panels()); | |
| 1410 | |
| 1411 // Create another extension and a panel from that extension. | |
| 1412 scoped_refptr<extensions::Extension> extension_other = | |
| 1413 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"), | |
| 1414 extensions::Manifest::INTERNAL, empty_value); | |
| 1415 std::string extension_app_name_other = | |
| 1416 web_app::GenerateApplicationNameFromExtensionId(extension_other->id()); | |
| 1417 Panel* panel_other = CreatePanel(extension_app_name_other); | |
| 1418 | |
| 1419 content::WindowedNotificationObserver signal( | |
| 1420 chrome::NOTIFICATION_PANEL_CLOSED, | |
| 1421 content::Source<Panel>(panel)); | |
| 1422 content::WindowedNotificationObserver signal1( | |
| 1423 chrome::NOTIFICATION_PANEL_CLOSED, | |
| 1424 content::Source<Panel>(panel1)); | |
| 1425 | |
| 1426 // Send unload notification on the first extension. | |
| 1427 extensions::ExtensionRegistry* registry = | |
| 1428 extensions::ExtensionRegistry::Get(browser()->profile()); | |
| 1429 registry->RemoveEnabled(extension->id()); | |
| 1430 registry->TriggerOnUnloaded( | |
| 1431 extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | |
| 1432 | |
| 1433 // Wait for the panels opened by the first extension to close. | |
| 1434 signal.Wait(); | |
| 1435 signal1.Wait(); | |
| 1436 | |
| 1437 // Verify that the panel that's left is the panel from the second extension. | |
| 1438 EXPECT_EQ(panel_other, panel_manager->panels()[0]); | |
| 1439 panel_other->Close(); | |
| 1440 } | |
| 1441 | |
| 1442 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { | |
| 1443 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 1444 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | |
| 1445 | |
| 1446 const base::string16 title_first_close = base::UTF8ToUTF16("TitleFirstClose"); | |
| 1447 const base::string16 title_second_close = | |
| 1448 base::UTF8ToUTF16("TitleSecondClose"); | |
| 1449 | |
| 1450 // Create a test panel with web contents loaded. | |
| 1451 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300), | |
| 1452 SHOW_AS_ACTIVE); | |
| 1453 params.url = ui_test_utils::GetTestUrl( | |
| 1454 base::FilePath(kTestDir), | |
| 1455 base::FilePath(FILE_PATH_LITERAL("onbeforeunload.html"))); | |
| 1456 Panel* panel = CreatePanelWithParams(params); | |
| 1457 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1458 | |
| 1459 // Close panel and verify it closes despite having a onbeforeunload handler. | |
| 1460 CloseWindowAndWait(panel); | |
| 1461 EXPECT_EQ(0, panel_manager->num_panels()); | |
| 1462 } | |
| 1463 | |
| 1464 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
| 1465 #if defined(OS_MACOSX) | |
| 1466 #define MAYBE_SizeClamping DISABLED_SizeClamping | |
| 1467 #else | |
| 1468 #define MAYBE_SizeClamping SizeClamping | |
| 1469 #endif | |
| 1470 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_SizeClamping) { | |
| 1471 // Using '0' sizes is equivalent of not providing sizes in API and causes | |
| 1472 // minimum sizes to be applied to facilitate auto-sizing. | |
| 1473 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1474 Panel* panel = CreatePanelWithParams(params); | |
| 1475 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width()); | |
| 1476 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height()); | |
| 1477 int reasonable_width = panel->min_size().width() + 10; | |
| 1478 int reasonable_height = panel->min_size().height() + 20; | |
| 1479 | |
| 1480 panel->Close(); | |
| 1481 | |
| 1482 // Using reasonable actual sizes should avoid clamping. | |
| 1483 CreatePanelParams params1("Panel1", | |
| 1484 gfx::Rect(0, 0, | |
| 1485 reasonable_width, reasonable_height), | |
| 1486 SHOW_AS_ACTIVE); | |
| 1487 panel = CreatePanelWithParams(params1); | |
| 1488 EXPECT_EQ(reasonable_width, panel->GetBounds().width()); | |
| 1489 EXPECT_EQ(reasonable_height, panel->GetBounds().height()); | |
| 1490 panel->Close(); | |
| 1491 | |
| 1492 // Using just one size should auto-compute some reasonable other size. | |
| 1493 int given_height = 200; | |
| 1494 CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height), | |
| 1495 SHOW_AS_ACTIVE); | |
| 1496 panel = CreatePanelWithParams(params2); | |
| 1497 EXPECT_GT(panel->GetBounds().width(), 0); | |
| 1498 EXPECT_EQ(given_height, panel->GetBounds().height()); | |
| 1499 panel->Close(); | |
| 1500 } | |
| 1501 | |
| 1502 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
| 1503 // http://crbug.com/179890; TightAutosizeAroundSingleLine broken on Windows by | |
| 1504 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1505 DISABLED_TightAutosizeAroundSingleLine) { | |
| 1506 PanelManager::GetInstance()->enable_auto_sizing(true); | |
| 1507 // Using 0 sizes triggers auto-sizing. | |
| 1508 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1509 params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>"); | |
| 1510 Panel* panel = CreatePanelWithParams(params); | |
| 1511 | |
| 1512 // Ensure panel has auto resized to original web content size. | |
| 1513 WaitForStableInitialSize initial_resize(panel); | |
| 1514 initial_resize.Wait(); | |
| 1515 | |
| 1516 int initial_width = panel->GetBounds().width(); | |
| 1517 int initial_height = panel->GetBounds().height(); | |
| 1518 | |
| 1519 // Inject some HTML content into the panel. | |
| 1520 WaitForAutoResizeWider enlarge(panel); | |
| 1521 EXPECT_TRUE(content::ExecuteScript( | |
| 1522 panel->GetWebContents(), | |
| 1523 "document.body.innerHTML =" | |
| 1524 " '<nobr>line of text and a <button>Button</button>';")); | |
| 1525 enlarge.Wait(); | |
| 1526 | |
| 1527 // The panel should have become larger in both dimensions (the minimums | |
| 1528 // has to be set to be smaller then a simple 1-line content, so the autosize | |
| 1529 // can work correctly. | |
| 1530 EXPECT_GT(panel->GetBounds().width(), initial_width); | |
| 1531 EXPECT_GT(panel->GetBounds().height(), initial_height); | |
| 1532 | |
| 1533 panel->Close(); | |
| 1534 } | |
| 1535 | |
| 1536 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
| 1537 #if defined(OS_MACOSX) | |
| 1538 #define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \ | |
| 1539 DISABLED_DefaultMaxSizeOnDisplaySettingsChange | |
| 1540 #else | |
| 1541 #define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \ | |
| 1542 DefaultMaxSizeOnDisplaySettingsChange | |
| 1543 #endif | |
| 1544 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1545 MAYBE_DefaultMaxSizeOnDisplaySettingsChange) { | |
| 1546 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); | |
| 1547 | |
| 1548 gfx::Size old_max_size = panel->max_size(); | |
| 1549 gfx::Size old_full_size = panel->full_size(); | |
| 1550 | |
| 1551 // Shrink the work area. Expect max size and full size become smaller. | |
| 1552 gfx::Rect smaller_work_area(0, 0, 500, 300); | |
| 1553 mock_display_settings_provider()->SetPrimaryDisplay( | |
| 1554 smaller_work_area, smaller_work_area); | |
| 1555 EXPECT_GT(old_max_size.width(), panel->max_size().width()); | |
| 1556 EXPECT_GT(old_max_size.height(), panel->max_size().height()); | |
| 1557 EXPECT_GT(smaller_work_area.width(), panel->max_size().width()); | |
| 1558 EXPECT_GT(smaller_work_area.height(), panel->max_size().height()); | |
| 1559 EXPECT_GT(old_full_size.width(), panel->full_size().width()); | |
| 1560 EXPECT_GT(old_full_size.height(), panel->full_size().height()); | |
| 1561 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); | |
| 1562 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); | |
| 1563 | |
| 1564 panel->Close(); | |
| 1565 } | |
| 1566 | |
| 1567 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
| 1568 #if defined(OS_MACOSX) | |
| 1569 #define MAYBE_CustomMaxSizeOnDisplaySettingsChange \ | |
| 1570 DISABLED_CustomMaxSizeOnDisplaySettingsChange | |
| 1571 #else | |
| 1572 #define MAYBE_CustomMaxSizeOnDisplaySettingsChange \ | |
| 1573 CustomMaxSizeOnDisplaySettingsChange | |
| 1574 #endif | |
| 1575 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1576 MAYBE_CustomMaxSizeOnDisplaySettingsChange) { | |
| 1577 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 1578 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); | |
| 1579 | |
| 1580 // Trigger custom max size by user resizing. | |
| 1581 gfx::Size bigger_size = gfx::Size(550, 400); | |
| 1582 gfx::Point mouse_location = panel->GetBounds().origin(); | |
| 1583 panel_manager->StartResizingByMouse(panel, | |
| 1584 mouse_location, | |
| 1585 HTTOPLEFT); | |
| 1586 mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(), | |
| 1587 panel->GetBounds().height() - bigger_size.height()); | |
| 1588 panel_manager->ResizeByMouse(mouse_location); | |
| 1589 panel_manager->EndResizingByMouse(false); | |
| 1590 | |
| 1591 gfx::Size old_max_size = panel->max_size(); | |
| 1592 EXPECT_EQ(bigger_size, old_max_size); | |
| 1593 gfx::Size old_full_size = panel->full_size(); | |
| 1594 EXPECT_EQ(bigger_size, old_full_size); | |
| 1595 | |
| 1596 // Shrink the work area. Expect max size and full size become smaller. | |
| 1597 gfx::Rect smaller_work_area(0, 0, 500, 300); | |
| 1598 mock_display_settings_provider()->SetPrimaryDisplay( | |
| 1599 smaller_work_area, smaller_work_area); | |
| 1600 EXPECT_GT(old_max_size.width(), panel->max_size().width()); | |
| 1601 EXPECT_GT(old_max_size.height(), panel->max_size().height()); | |
| 1602 EXPECT_GE(smaller_work_area.width(), panel->max_size().width()); | |
| 1603 EXPECT_EQ(smaller_work_area.height(), panel->max_size().height()); | |
| 1604 EXPECT_GT(old_full_size.width(), panel->full_size().width()); | |
| 1605 EXPECT_GT(old_full_size.height(), panel->full_size().height()); | |
| 1606 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); | |
| 1607 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); | |
| 1608 EXPECT_EQ(smaller_work_area.height(), panel->full_size().height()); | |
| 1609 | |
| 1610 panel->Close(); | |
| 1611 } | |
| 1612 | |
| 1613 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevTools) { | |
| 1614 // Create a test panel with web contents loaded. | |
| 1615 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE); | |
| 1616 GURL url(ui_test_utils::GetTestUrl( | |
| 1617 base::FilePath(kTestDir), | |
| 1618 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 1619 params.url = url; | |
| 1620 Panel* panel = CreatePanelWithParams(params); | |
| 1621 | |
| 1622 // Open devtools. | |
| 1623 size_t num_browsers = 1; | |
| 1624 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser()->profile())); | |
| 1625 content::WindowedNotificationObserver signal( | |
| 1626 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
| 1627 content::NotificationService::AllSources()); | |
| 1628 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS)); | |
| 1629 signal.Wait(); | |
| 1630 | |
| 1631 // Check that the new browser window that opened is dev tools window. | |
| 1632 ++num_browsers; | |
| 1633 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser()->profile())); | |
| 1634 for (auto* b : *BrowserList::GetInstance()) { | |
| 1635 if (b == browser()) | |
| 1636 continue; | |
| 1637 ASSERT_TRUE(b->is_devtools()); | |
| 1638 } | |
| 1639 | |
| 1640 panel->Close(); | |
| 1641 } | |
| 1642 | |
| 1643 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevToolsConsole) { | |
| 1644 // Create a test panel with web contents loaded. | |
| 1645 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE); | |
| 1646 GURL url(ui_test_utils::GetTestUrl( | |
| 1647 base::FilePath(kTestDir), | |
| 1648 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 1649 params.url = url; | |
| 1650 Panel* panel = CreatePanelWithParams(params); | |
| 1651 | |
| 1652 // Open devtools console. | |
| 1653 size_t num_browsers = 1; | |
| 1654 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser()->profile())); | |
| 1655 content::WindowedNotificationObserver signal( | |
| 1656 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
| 1657 content::NotificationService::AllSources()); | |
| 1658 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS_CONSOLE)); | |
| 1659 signal.Wait(); | |
| 1660 | |
| 1661 // Check that the new browser window that opened is dev tools window. | |
| 1662 ++num_browsers; | |
| 1663 EXPECT_EQ(num_browsers, chrome::GetBrowserCount(browser()->profile())); | |
| 1664 for (auto* b : *BrowserList::GetInstance()) { | |
| 1665 if (b == browser()) | |
| 1666 continue; | |
| 1667 ASSERT_TRUE(b->is_devtools()); | |
| 1668 } | |
| 1669 | |
| 1670 panel->Close(); | |
| 1671 } | |
| 1672 | |
| 1673 #if defined(OS_WIN) | |
| 1674 #define MAYBE_Accelerator Accelerator | |
| 1675 #else | |
| 1676 #define MAYBE_Accelerator DISABLED_Accelerator | |
| 1677 #endif | |
| 1678 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) { | |
| 1679 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 1680 | |
| 1681 // Create a test panel with web contents loaded. | |
| 1682 CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE); | |
| 1683 GURL url(ui_test_utils::GetTestUrl( | |
| 1684 base::FilePath(kTestDir), | |
| 1685 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); | |
| 1686 params.url = url; | |
| 1687 Panel* panel = CreatePanelWithParams(params); | |
| 1688 EXPECT_EQ(1, panel_manager->num_panels()); | |
| 1689 | |
| 1690 // Close the panel by accelerator. | |
| 1691 content::WindowedNotificationObserver signal( | |
| 1692 chrome::NOTIFICATION_PANEL_CLOSED, | |
| 1693 content::Source<Panel>(panel)); | |
| 1694 | |
| 1695 ui::KeyEvent ui_event(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::DomCode::US_W, | |
| 1696 ui::EF_CONTROL_DOWN); | |
| 1697 content::NativeWebKeyboardEvent key_event(ui_event); | |
| 1698 panel->HandleKeyboardEvent(key_event); | |
| 1699 signal.Wait(); | |
| 1700 EXPECT_EQ(0, panel_manager->num_panels()); | |
| 1701 } | |
| 1702 | |
| 1703 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1704 HideDockedPanelCreatedBeforeFullScreenMode) { | |
| 1705 // Create a docked panel. | |
| 1706 Panel* panel = CreatePanel("PanelTest"); | |
| 1707 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 1708 CreateNativePanelTesting(panel)); | |
| 1709 | |
| 1710 // Panel should be visible at first. | |
| 1711 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 1712 | |
| 1713 // Panel should become hidden when entering full-screen mode. | |
| 1714 mock_display_settings_provider()->EnableFullScreenMode(true); | |
| 1715 EXPECT_FALSE(panel_testing->IsWindowVisible()); | |
| 1716 | |
| 1717 // Panel should become visible when leaving full-screen mode. | |
| 1718 mock_display_settings_provider()->EnableFullScreenMode(false); | |
| 1719 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 1720 | |
| 1721 PanelManager::GetInstance()->CloseAll(); | |
| 1722 } | |
| 1723 | |
| 1724 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, | |
| 1725 HideDockedPanelCreatedOnFullScreenMode) { | |
| 1726 // Enable full-screen mode first. | |
| 1727 mock_display_settings_provider()->EnableFullScreenMode(true); | |
| 1728 | |
| 1729 // Create a docked panel without waiting for it to be shown since it is not | |
| 1730 // supposed to be shown on full-screen mode. | |
| 1731 CreatePanelParams params("1", gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE); | |
| 1732 params.wait_for_fully_created = false; | |
| 1733 Panel* panel = CreatePanelWithParams(params); | |
| 1734 std::unique_ptr<NativePanelTesting> panel_testing( | |
| 1735 CreateNativePanelTesting(panel)); | |
| 1736 | |
| 1737 // Panel should not be shown on full-screen mode. | |
| 1738 EXPECT_FALSE(panel_testing->IsWindowVisible()); | |
| 1739 | |
| 1740 // Panel should become visible when leaving full-screen mode. | |
| 1741 mock_display_settings_provider()->EnableFullScreenMode(false); | |
| 1742 EXPECT_TRUE(panel_testing->IsWindowVisible()); | |
| 1743 | |
| 1744 PanelManager::GetInstance()->CloseAll(); | |
| 1745 } | |
| 1746 | |
| 1747 class PanelExtensionApiTest : public ExtensionApiTest { | |
| 1748 protected: | |
| 1749 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 1750 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 1751 command_line->AppendSwitch(switches::kEnablePanels); | |
| 1752 } | |
| 1753 }; | |
| 1754 | |
| 1755 #if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \ | |
| 1756 defined(OS_MACOSX) | |
| 1757 // Focus test fails if there is no window manager on Linux. | |
| 1758 // Aura panels have different behavior that do not apply to this test. | |
| 1759 #define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize | |
| 1760 #else | |
| 1761 #define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize | |
| 1762 #endif | |
| 1763 IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest, | |
| 1764 MAYBE_FocusChangeEventOnMinimize) { | |
| 1765 // This is needed so the subsequently created panels can be activated. | |
| 1766 // On a Mac, it transforms background-only test process into foreground one. | |
| 1767 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1768 ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_; | |
| 1769 } | |
| OLD | NEW |