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