panel_browsertest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 506#if defined(OS_LINUX) || defined(OS_WIN) 507// There is no animations on Linux, by design (http://crbug.com/144074). 508// And there are intermittent/flaky failures on windows try bots 509// (http://crbug.com/179069). 510#define MAYBE_AnimateBounds DISABLED_AnimateBounds 511#else 512#define MAYBE_AnimateBounds AnimateBounds 513#endif 514IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AnimateBounds) { 515 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100)); 516 scoped_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 544IN_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 601IN_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 609IN_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 618IN_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 628IN_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 681IN_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 scoped_ptr<NativePanelTesting> test_panel1( 691 CreateNativePanelTesting(panel1)); 692 scoped_ptr<NativePanelTesting> test_panel2( 693 CreateNativePanelTesting(panel2)); 694 scoped_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 841IN_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 884IN_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// http://crbug.com/143247 954#if !defined(OS_WIN) 955#define MAYBE_ActivatePanelOrTabbedWindow DISABLED_ActivatePanelOrTabbedWindow 956#else 957#define MAYBE_ActivatePanelOrTabbedWindow ActivatePanelOrTabbedWindow 958#endif 959IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) { 960 Panel* panel1 = CreatePanel("Panel1"); 961 Panel* panel2 = CreatePanel("Panel2"); 962 963 // Activate main tabbed window. 964 browser()->window()->Activate(); 965 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); 966 967 // Activate a panel. 968 panel2->Activate(); 969 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); 970 971 // Activate the main tabbed window back. 972 browser()->window()->Activate(); 973 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); 974 975 // Activate another panel. 976 panel1->Activate(); 977 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); 978 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); 979 980 // Switch focus between panels. 981 panel2->Activate(); 982 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); 983 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); 984 985 PanelManager::GetInstance()->CloseAll(); 986} 987 988// TODO(jianli): To be enabled for other platforms. 989#if defined(OS_WIN) 990#define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic 991#else 992#define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic 993#endif 994IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) { 995 // Create an active panel. 996 Panel* panel = CreatePanel("PanelTest"); 997 scoped_ptr<NativePanelTesting> native_panel_testing( 998 CreateNativePanelTesting(panel)); 999 1000 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state 1001 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); 1002 1003 // Deactivate the panel. 1004 panel->Deactivate(); 1005 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); 1006 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false)); 1007 1008 // This test does not reactivate the panel because the panel might not be 1009 // reactivated programmatically once it is deactivated. 1010} 1011 1012// http://crbug.com/143247 1013#if !defined(OS_WIN) 1014#define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple 1015#else 1016#define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple 1017#endif 1018IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) { 1019 BrowserWindow* tabbed_window = browser()->window(); 1020 1021 // Create 4 panels in the following screen layout: 1022 // P3 P2 P1 P0 1023 const int kNumPanels = 4; 1024 for (int i = 0; i < kNumPanels; ++i) 1025 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100)); 1026 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); 1027 1028 std::vector<bool> expected_active_states; 1029 std::vector<bool> last_active_states; 1030 1031 // The last created panel, P3, should be active. 1032 expected_active_states = ProduceExpectedActiveStates(3); 1033 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); 1034 EXPECT_FALSE(tabbed_window->IsActive()); 1035 1036 // Activating P1 should cause P3 to lose focus. 1037 panels[1]->Activate(); 1038 last_active_states = expected_active_states; 1039 expected_active_states = ProduceExpectedActiveStates(1); 1040 WaitForPanelActiveStates(last_active_states, expected_active_states); 1041 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); 1042 1043 // Minimizing inactive panel P2 should not affect other panels' active states. 1044 panels[2]->SetExpansionState(Panel::MINIMIZED); 1045 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); 1046 EXPECT_FALSE(tabbed_window->IsActive()); 1047} 1048 1049// http://crbug.com/143247 1050#if !defined(OS_WIN) 1051#define MAYBE_DrawAttentionBasic DISABLED_DrawAttentionBasic 1052#else 1053#define MAYBE_DrawAttentionBasic DrawAttentionBasic 1054#endif 1055IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DrawAttentionBasic) { 1056 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); 1057 Panel* panel = CreatePanelWithParams(params); 1058 scoped_ptr<NativePanelTesting> native_panel_testing( 1059 CreateNativePanelTesting(panel)); 1060 1061 // Test that the attention is drawn when the expanded panel is not in focus. 1062 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 1063 EXPECT_FALSE(panel->IsActive()); 1064 EXPECT_FALSE(panel->IsDrawingAttention()); 1065 panel->FlashFrame(true); 1066 EXPECT_TRUE(panel->IsDrawingAttention()); 1067 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); 1068 1069 // Stop drawing attention. 1070 panel->FlashFrame(false); 1071 EXPECT_FALSE(panel->IsDrawingAttention()); 1072 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1073 1074 // Draw attention, then minimize. Titlebar should remain visible. 1075 panel->FlashFrame(true); 1076 EXPECT_TRUE(panel->IsDrawingAttention()); 1077 1078 panel->Minimize(); 1079 EXPECT_TRUE(panel->IsDrawingAttention()); 1080 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 1081 1082 // Stop drawing attention. Titlebar should no longer be visible. 1083 panel->FlashFrame(false); 1084 EXPECT_FALSE(panel->IsDrawingAttention()); 1085 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); 1086 1087 panel->Close(); 1088} 1089 1090// http://crbug.com/143247 1091#if !defined(OS_WIN) 1092#define MAYBE_DrawAttentionWhileMinimized DISABLED_DrawAttentionWhileMinimized 1093#else 1094#define MAYBE_DrawAttentionWhileMinimized DrawAttentionWhileMinimized 1095#endif 1096IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DrawAttentionWhileMinimized) { 1097 // Create 3 panels so we end up with an inactive panel that can 1098 // be made to draw attention. 1099 Panel* panel = CreatePanel("test panel1"); 1100 Panel* panel2 = CreatePanel("test panel2"); 1101 Panel* panel3 = CreatePanel("test panel3"); 1102 1103 scoped_ptr<NativePanelTesting> native_panel_testing( 1104 CreateNativePanelTesting(panel)); 1105 1106 // Test that the attention is drawn and the title-bar is brought up when the 1107 // minimized panel is drawing attention. 1108 panel->Minimize(); 1109 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); 1110 panel->FlashFrame(true); 1111 EXPECT_TRUE(panel->IsDrawingAttention()); 1112 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 1113 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); 1114 1115 // Test that we cannot bring up other minimized panel if the mouse is over 1116 // the panel that draws attension. 1117 panel2->Minimize(); 1118 gfx::Point hover_point(panel->GetBounds().origin()); 1119 MoveMouse(hover_point); 1120 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 1121 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1122 1123 // Test that we cannot bring down the panel that is drawing the attention. 1124 hover_point.set_y(hover_point.y() - 200); 1125 MoveMouse(hover_point); 1126 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 1127 1128 // Test that the attention is cleared when activated. 1129 panel->Activate(); 1130 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); 1131 EXPECT_FALSE(panel->IsDrawingAttention()); 1132 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 1133 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1134 1135 panel->Close(); 1136 panel2->Close(); 1137 panel3->Close(); 1138} 1139 1140// http://crbug.com/175760; several panel tests failing regularly on mac. 1141#if defined(OS_MACOSX) || defined(OS_LINUX) 1142#define MAYBE_StopDrawingAttentionWhileMinimized \ 1143 DISABLED_StopDrawingAttentionWhileMinimized 1144#else 1145#define MAYBE_StopDrawingAttentionWhileMinimized \ 1146 StopDrawingAttentionWhileMinimized 1147#endif 1148// Verify that minimized state of a panel is correct after draw attention 1149// is stopped when there are other minimized panels. 1150IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1151 MAYBE_StopDrawingAttentionWhileMinimized) { 1152 Panel* panel1 = CreatePanel("panel1"); 1153 Panel* panel2 = CreatePanel("panel2"); 1154 1155 panel1->Minimize(); 1156 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1157 panel2->Minimize(); 1158 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1159 1160 // Verify panel returns to minimized state when no longer drawing attention. 1161 panel1->FlashFrame(true); 1162 EXPECT_TRUE(panel1->IsDrawingAttention()); 1163 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1164 1165 panel1->FlashFrame(false); 1166 EXPECT_FALSE(panel1->IsDrawingAttention()); 1167 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1168 1169 // Hover over other minimized panel to bring up titlebars. 1170 gfx::Point hover_point(panel2->GetBounds().origin()); 1171 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); 1172 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1173 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); 1174 1175 // Verify panel keeps titlebar visible when no longer drawing attention 1176 // if titlebars are up. 1177 panel1->FlashFrame(true); 1178 EXPECT_TRUE(panel1->IsDrawingAttention()); 1179 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1180 1181 panel1->FlashFrame(false); 1182 EXPECT_FALSE(panel1->IsDrawingAttention()); 1183 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1184 1185 // Move mouse away. All panels should return to minimized state. 1186 hover_point.set_y(hover_point.y() - 200); 1187 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); 1188 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1189 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1190 1191 // Verify minimized panel that is drawing attention stays in title-only mode 1192 // after attention is cleared if mouse is in the titlebar area. 1193 panel1->FlashFrame(true); 1194 EXPECT_TRUE(panel1->IsDrawingAttention()); 1195 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1196 1197 gfx::Point hover_point_in_panel(panel1->GetBounds().origin()); 1198 MoveMouse(hover_point_in_panel); 1199 1200 panel1->FlashFrame(false); 1201 EXPECT_FALSE(panel1->IsDrawingAttention()); 1202 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1203 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1204 1205 // Typical user scenario will detect the mouse in the panel 1206 // after attention is cleared, causing titles to pop up, so 1207 // we simulate that here. 1208 MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel); 1209 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 1210 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); 1211 1212 // Move mouse away and panels should go back to fully minimized state. 1213 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); 1214 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1215 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1216 1217 panel1->Close(); 1218 panel2->Close(); 1219} 1220 1221IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) { 1222 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE); 1223 Panel* panel = CreatePanelWithParams(params); 1224 scoped_ptr<NativePanelTesting> native_panel_testing( 1225 CreateNativePanelTesting(panel)); 1226 1227 // Test that the attention should not be drawn if the expanded panel is in 1228 // focus. 1229 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 1230 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state 1231 EXPECT_FALSE(panel->IsDrawingAttention()); 1232 panel->FlashFrame(true); 1233 EXPECT_FALSE(panel->IsDrawingAttention()); 1234 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1235 1236 panel->Close(); 1237} 1238 1239// http://crbug.com/143247 1240#if !defined(OS_WIN) 1241#define MAYBE_DrawAttentionResetOnActivate DISABLED_DrawAttentionResetOnActivate 1242#else 1243#define MAYBE_DrawAttentionResetOnActivate DrawAttentionResetOnActivate 1244#endif 1245IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DrawAttentionResetOnActivate) { 1246 // Create 2 panels so we end up with an inactive panel that can 1247 // be made to draw attention. 1248 Panel* panel = CreatePanel("test panel1"); 1249 Panel* panel2 = CreatePanel("test panel2"); 1250 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); 1251 1252 scoped_ptr<NativePanelTesting> native_panel_testing( 1253 CreateNativePanelTesting(panel)); 1254 1255 panel->FlashFrame(true); 1256 EXPECT_TRUE(panel->IsDrawingAttention()); 1257 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); 1258 1259 // Test that the attention is cleared when panel gets focus. 1260 panel->Activate(); 1261 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); 1262 EXPECT_FALSE(panel->IsDrawingAttention()); 1263 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1264 1265 panel->Close(); 1266 panel2->Close(); 1267} 1268 1269// http://crbug.com/143247 1270#if !defined(OS_WIN) 1271#define MAYBE_DrawAttentionMinimizedNotResetOnActivate DISABLED_DrawAttentionMinimizedNotResetOnActivate 1272#else 1273#define MAYBE_DrawAttentionMinimizedNotResetOnActivate DrawAttentionMinimizedNotResetOnActivate 1274#endif 1275IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1276 MAYBE_DrawAttentionMinimizedNotResetOnActivate) { 1277 // Create 2 panels so we end up with an inactive panel that can 1278 // be made to draw attention. 1279 Panel* panel1 = CreatePanel("test panel1"); 1280 Panel* panel2 = CreatePanel("test panel2"); 1281 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); 1282 1283 panel1->Minimize(); 1284 EXPECT_TRUE(panel1->IsMinimized()); 1285 panel1->FlashFrame(true); 1286 EXPECT_TRUE(panel1->IsDrawingAttention()); 1287 1288 // Simulate panel being activated while minimized. Cannot call 1289 // Activate() as that expands the panel. 1290 panel1->OnActiveStateChanged(true); 1291 EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged. 1292 1293 // Unminimize panel to show that attention would have been cleared 1294 // if panel had not been minimized. 1295 panel1->Restore(); 1296 EXPECT_FALSE(panel1->IsMinimized()); 1297 EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged. 1298 1299 panel1->OnActiveStateChanged(true); 1300 EXPECT_FALSE(panel1->IsDrawingAttention()); // Attention cleared. 1301 1302 panel1->Close(); 1303 panel2->Close(); 1304} 1305 1306// http://crbug.com/143247 1307#if !defined(OS_WIN) 1308#define MAYBE_DrawAttentionResetOnClick DISABLED_DrawAttentionResetOnClick 1309#else 1310#define MAYBE_DrawAttentionResetOnClick DrawAttentionResetOnClick 1311#endif 1312IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DrawAttentionResetOnClick) { 1313 // Create 2 panels so we end up with an inactive panel that can 1314 // be made to draw attention. 1315 Panel* panel = CreatePanel("test panel1"); 1316 Panel* panel2 = CreatePanel("test panel2"); 1317 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); 1318 1319 scoped_ptr<NativePanelTesting> native_panel_testing( 1320 CreateNativePanelTesting(panel)); 1321 1322 panel->FlashFrame(true); 1323 EXPECT_TRUE(panel->IsDrawingAttention()); 1324 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); 1325 1326 // Test that the attention is cleared when panel gets focus. 1327 native_panel_testing->PressLeftMouseButtonTitlebar( 1328 panel->GetBounds().origin()); 1329 native_panel_testing->ReleaseMouseButtonTitlebar(); 1330 1331 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); 1332 EXPECT_FALSE(panel->IsDrawingAttention()); 1333 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); 1334 1335 panel->Close(); 1336 panel2->Close(); 1337} 1338 1339// http://crbug.com/175760; several panel tests failing regularly on mac. 1340#if defined(OS_MACOSX) 1341#define MAYBE_MinimizeImmediatelyAfterRestore \ 1342 DISABLED_MinimizeImmediatelyAfterRestore 1343#else 1344#define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore 1345#endif 1346IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1347 MAYBE_MinimizeImmediatelyAfterRestore) { 1348 CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE); 1349 Panel* panel = CreatePanelWithParams(params); 1350 scoped_ptr<NativePanelTesting> native_panel_testing( 1351 CreateNativePanelTesting(panel)); 1352 1353 PanelActiveStateObserver signal(panel, false); 1354 panel->Minimize(); // this should deactivate. 1355 signal.Wait(); 1356 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); 1357 1358 panel->Restore(); 1359 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 1360 1361 // Verify that minimizing a panel right after expansion works. 1362 panel->Minimize(); 1363 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); 1364 1365 panel->Close(); 1366} 1367 1368IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) { 1369 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE); 1370 Panel* panel = CreatePanelWithParams(params); 1371 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 1372 1373 PanelActiveStateObserver signal(panel, false); 1374 panel->Minimize(); 1375 signal.Wait(); 1376 panel->Close(); 1377} 1378 1379// http://crbug.com/143247 1380#if !defined(OS_WIN) 1381#define MAYBE_CreateInactiveSwitchToActive DISABLED_CreateInactiveSwitchToActive 1382#else 1383#define MAYBE_CreateInactiveSwitchToActive CreateInactiveSwitchToActive 1384#endif 1385IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreateInactiveSwitchToActive) { 1386 // Compiz will not activate initially inactive window. 1387 if (SkipTestIfCompizWM()) 1388 return; 1389 1390 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); 1391 Panel* panel = CreatePanelWithParams(params); 1392 1393 panel->Activate(); 1394 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); 1395 1396 panel->Close(); 1397} 1398 1399// TODO(dimich): try/enable on other platforms. See bug 103253 for details on 1400// why this is disabled on windows. 1401#if defined(OS_MACOSX) 1402#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ 1403 MinimizeTwoPanelsWithoutTabbedWindow 1404#else 1405#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ 1406 DISABLED_MinimizeTwoPanelsWithoutTabbedWindow 1407#endif 1408 1409// When there are 2 panels and no chrome window, minimizing one panel does 1410// not expand/focuses another. 1411IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1412 MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) { 1413 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); 1414 Panel* panel1 = CreatePanelWithParams(params); 1415 Panel* panel2 = CreatePanelWithParams(params); 1416 1417 // Close main tabbed window. 1418 content::WindowedNotificationObserver signal( 1419 chrome::NOTIFICATION_BROWSER_CLOSED, 1420 content::Source<Browser>(browser())); 1421 chrome::CloseWindow(browser()); 1422 signal.Wait(); 1423 1424 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); 1425 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); 1426 panel1->Activate(); 1427 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); 1428 1429 panel1->SetExpansionState(Panel::MINIMIZED); 1430 base::MessageLoop::current()->RunUntilIdle(); 1431 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); 1432 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1433 1434 panel2->SetExpansionState(Panel::MINIMIZED); 1435 base::MessageLoop::current()->RunUntilIdle(); 1436 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); 1437 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); 1438 1439 // Verify that panel1 is still minimized and not active. 1440 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); 1441 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 1442 1443 // Another check for the same. 1444 EXPECT_FALSE(panel1->IsActive()); 1445 EXPECT_FALSE(panel2->IsActive()); 1446 1447 panel1->Close(); 1448 panel2->Close(); 1449} 1450 1451// http://crbug.com/143247 1452#if !defined(OS_WIN) 1453#define MAYBE_NonExtensionDomainPanelsCloseOnUninstall DISABLED_NonExtensionDomainPanelsCloseOnUninstall 1454#else 1455#define MAYBE_NonExtensionDomainPanelsCloseOnUninstall NonExtensionDomainPanelsCloseOnUninstall 1456#endif 1457IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1458 MAYBE_NonExtensionDomainPanelsCloseOnUninstall) { 1459 // Create a test extension. 1460 DictionaryValue empty_value; 1461 scoped_refptr<extensions::Extension> extension = 1462 CreateExtension(FILE_PATH_LITERAL("TestExtension"), 1463 extensions::Manifest::INTERNAL, empty_value); 1464 std::string extension_app_name = 1465 web_app::GenerateApplicationNameFromExtensionId(extension->id()); 1466 1467 PanelManager* panel_manager = PanelManager::GetInstance(); 1468 EXPECT_EQ(0, panel_manager->num_panels()); 1469 1470 // Create a panel with the extension as host. 1471 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); 1472 std::string extension_domain_url(extensions::kExtensionScheme); 1473 extension_domain_url += "://"; 1474 extension_domain_url += extension->id(); 1475 extension_domain_url += "/hello.html"; 1476 params.url = GURL(extension_domain_url); 1477 Panel* panel = CreatePanelWithParams(params); 1478 EXPECT_EQ(1, panel_manager->num_panels()); 1479 1480 // Create a panel with a non-extension host. 1481 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); 1482 params1.url = GURL(content::kAboutBlankURL); 1483 Panel* panel1 = CreatePanelWithParams(params1); 1484 EXPECT_EQ(2, panel_manager->num_panels()); 1485 1486 // Create another extension and a panel from that extension. 1487 scoped_refptr<extensions::Extension> extension_other = 1488 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"), 1489 extensions::Manifest::INTERNAL, empty_value); 1490 std::string extension_app_name_other = 1491 web_app::GenerateApplicationNameFromExtensionId(extension_other->id()); 1492 Panel* panel_other = CreatePanel(extension_app_name_other); 1493 1494 content::WindowedNotificationObserver signal( 1495 chrome::NOTIFICATION_PANEL_CLOSED, 1496 content::Source<Panel>(panel)); 1497 content::WindowedNotificationObserver signal1( 1498 chrome::NOTIFICATION_PANEL_CLOSED, 1499 content::Source<Panel>(panel1)); 1500 1501 // Send unload notification on the first extension. 1502 extensions::UnloadedExtensionInfo details( 1503 extension.get(), extension_misc::UNLOAD_REASON_UNINSTALL); 1504 content::NotificationService::current()->Notify( 1505 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1506 content::Source<Profile>(browser()->profile()), 1507 content::Details<extensions::UnloadedExtensionInfo>(&details)); 1508 1509 // Wait for the panels opened by the first extension to close. 1510 signal.Wait(); 1511 signal1.Wait(); 1512 1513 // Verify that the panel that's left is the panel from the second extension. 1514 EXPECT_EQ(panel_other, panel_manager->panels()[0]); 1515 panel_other->Close(); 1516} 1517 1518IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { 1519 PanelManager* panel_manager = PanelManager::GetInstance(); 1520 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. 1521 1522 const string16 title_first_close = UTF8ToUTF16("TitleFirstClose"); 1523 const string16 title_second_close = UTF8ToUTF16("TitleSecondClose"); 1524 1525 // Create a test panel with web contents loaded. 1526 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300), 1527 SHOW_AS_ACTIVE); 1528 params.url = ui_test_utils::GetTestUrl( 1529 base::FilePath(kTestDir), 1530 base::FilePath(FILE_PATH_LITERAL("onbeforeunload.html"))); 1531 Panel* panel = CreatePanelWithParams(params); 1532 EXPECT_EQ(1, panel_manager->num_panels()); 1533 1534 // Close panel and verify it closes despite having a onbeforeunload handler. 1535 CloseWindowAndWait(panel); 1536 EXPECT_EQ(0, panel_manager->num_panels()); 1537} 1538 1539// http://crbug.com/175760; several panel tests failing regularly on mac. 1540#if defined(OS_MACOSX) 1541#define MAYBE_SizeClamping DISABLED_SizeClamping 1542#else 1543#define MAYBE_SizeClamping SizeClamping 1544#endif 1545IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_SizeClamping) { 1546 // Using '0' sizes is equivalent of not providing sizes in API and causes 1547 // minimum sizes to be applied to facilitate auto-sizing. 1548 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); 1549 Panel* panel = CreatePanelWithParams(params); 1550 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width()); 1551 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height()); 1552 int reasonable_width = panel->min_size().width() + 10; 1553 int reasonable_height = panel->min_size().height() + 20; 1554 1555 panel->Close(); 1556 1557 // Using reasonable actual sizes should avoid clamping. 1558 CreatePanelParams params1("Panel1", 1559 gfx::Rect(0, 0, 1560 reasonable_width, reasonable_height), 1561 SHOW_AS_ACTIVE); 1562 panel = CreatePanelWithParams(params1); 1563 EXPECT_EQ(reasonable_width, panel->GetBounds().width()); 1564 EXPECT_EQ(reasonable_height, panel->GetBounds().height()); 1565 panel->Close(); 1566 1567 // Using just one size should auto-compute some reasonable other size. 1568 int given_height = 200; 1569 CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height), 1570 SHOW_AS_ACTIVE); 1571 panel = CreatePanelWithParams(params2); 1572 EXPECT_GT(panel->GetBounds().width(), 0); 1573 EXPECT_EQ(given_height, panel->GetBounds().height()); 1574 panel->Close(); 1575} 1576 1577// http://crbug.com/175760; several panel tests failing regularly on mac. 1578// http://crbug.com/179890; TightAutosizeAroundSingleLine broken on Windows by 1579IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1580 DISABLED_TightAutosizeAroundSingleLine) { 1581 PanelManager::GetInstance()->enable_auto_sizing(true); 1582 // Using 0 sizes triggers auto-sizing. 1583 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); 1584 params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>"); 1585 Panel* panel = CreatePanelWithParams(params); 1586 1587 // Ensure panel has auto resized to original web content size. 1588 WaitForStableInitialSize initial_resize(panel); 1589 initial_resize.Wait(); 1590 1591 int initial_width = panel->GetBounds().width(); 1592 int initial_height = panel->GetBounds().height(); 1593 1594 // Inject some HTML content into the panel. 1595 WaitForAutoResizeWider enlarge(panel); 1596 EXPECT_TRUE(content::ExecuteScript( 1597 panel->GetWebContents(), 1598 "document.body.innerHTML =" 1599 " '<nobr>line of text and a <button>Button</button>';")); 1600 enlarge.Wait(); 1601 1602 // The panel should have become larger in both dimensions (the minimums 1603 // has to be set to be smaller then a simple 1-line content, so the autosize 1604 // can work correctly. 1605 EXPECT_GT(panel->GetBounds().width(), initial_width); 1606 EXPECT_GT(panel->GetBounds().height(), initial_height); 1607 1608 panel->Close(); 1609} 1610 1611// http://crbug.com/175760; several panel tests failing regularly on mac. 1612#if defined(OS_MACOSX) 1613#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \ 1614 DISABLED_DefaultMaxSizeOnDisplaySettingsChange 1615#else 1616#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \ 1617 DefaultMaxSizeOnDisplaySettingsChange 1618#endif 1619IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1620 MAYBE_DefaultMaxSizeOnDisplaySettingsChange) { 1621 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); 1622 1623 gfx::Size old_max_size = panel->max_size(); 1624 gfx::Size old_full_size = panel->full_size(); 1625 1626 // Shrink the work area. Expect max size and full size become smaller. 1627 gfx::Rect smaller_work_area(0, 0, 500, 300); 1628 mock_display_settings_provider()->SetPrimaryDisplay( 1629 smaller_work_area, smaller_work_area); 1630 EXPECT_GT(old_max_size.width(), panel->max_size().width()); 1631 EXPECT_GT(old_max_size.height(), panel->max_size().height()); 1632 EXPECT_GT(smaller_work_area.width(), panel->max_size().width()); 1633 EXPECT_GT(smaller_work_area.height(), panel->max_size().height()); 1634 EXPECT_GT(old_full_size.width(), panel->full_size().width()); 1635 EXPECT_GT(old_full_size.height(), panel->full_size().height()); 1636 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); 1637 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); 1638 1639 panel->Close(); 1640} 1641 1642// http://crbug.com/175760; several panel tests failing regularly on mac. 1643#if defined(OS_MACOSX) 1644#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \ 1645 DISABLED_CustomMaxSizeOnDisplaySettingsChange 1646#else 1647#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \ 1648 CustomMaxSizeOnDisplaySettingsChange 1649#endif 1650IN_PROC_BROWSER_TEST_F(PanelBrowserTest, 1651 MAYBE_CustomMaxSizeOnDisplaySettingsChange) { 1652 PanelManager* panel_manager = PanelManager::GetInstance(); 1653 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); 1654 1655 // Trigger custom max size by user resizing. 1656 gfx::Size bigger_size = gfx::Size(550, 400); 1657 gfx::Point mouse_location = panel->GetBounds().origin(); 1658 panel_manager->StartResizingByMouse(panel, 1659 mouse_location, 1660 panel::RESIZE_TOP_LEFT); 1661 mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(), 1662 panel->GetBounds().height() - bigger_size.height()); 1663 panel_manager->ResizeByMouse(mouse_location); 1664 panel_manager->EndResizingByMouse(false); 1665 1666 gfx::Size old_max_size = panel->max_size(); 1667 EXPECT_EQ(bigger_size, old_max_size); 1668 gfx::Size old_full_size = panel->full_size(); 1669 EXPECT_EQ(bigger_size, old_full_size); 1670 1671 // Shrink the work area. Expect max size and full size become smaller. 1672 gfx::Rect smaller_work_area(0, 0, 500, 300); 1673 mock_display_settings_provider()->SetPrimaryDisplay( 1674 smaller_work_area, smaller_work_area); 1675 EXPECT_GT(old_max_size.width(), panel->max_size().width()); 1676 EXPECT_GT(old_max_size.height(), panel->max_size().height()); 1677 EXPECT_GE(smaller_work_area.width(), panel->max_size().width()); 1678 EXPECT_EQ(smaller_work_area.height(), panel->max_size().height()); 1679 EXPECT_GT(old_full_size.width(), panel->full_size().width()); 1680 EXPECT_GT(old_full_size.height(), panel->full_size().height()); 1681 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); 1682 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); 1683 EXPECT_EQ(smaller_work_area.height(), panel->full_size().height()); 1684 1685 panel->Close(); 1686} 1687 1688// http://crbug.com/175760; several panel tests failing regularly on mac. 1689#if defined(OS_MACOSX) 1690#define MAYBE_DevTools DISABLED_DevTools 1691#else 1692#define MAYBE_DevTools DevTools 1693#endif 1694IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevTools) { 1695 // Create a test panel with web contents loaded. 1696 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE); 1697 GURL url(ui_test_utils::GetTestUrl( 1698 base::FilePath(kTestDir), 1699 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); 1700 params.url = url; 1701 Panel* panel = CreatePanelWithParams(params); 1702 1703 // Open devtools. 1704 size_t num_browsers = 1; 1705 EXPECT_EQ(num_browsers, chrome::GetBrowserCount( 1706 browser()->profile(), 1707 browser()->host_desktop_type())); 1708 content::WindowedNotificationObserver signal( 1709 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 1710 content::NotificationService::AllSources()); 1711 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS)); 1712 signal.Wait(); 1713 1714 // Check that the new browser window that opened is dev tools window. 1715 ++num_browsers; 1716 EXPECT_EQ(num_browsers, chrome::GetBrowserCount( 1717 browser()->profile(), 1718 browser()->host_desktop_type())); 1719 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { 1720 if (*iter == browser()) 1721 continue; 1722 ASSERT_TRUE((*iter)->is_devtools()); 1723 } 1724 1725 panel->Close(); 1726} 1727 1728// http://crbug.com/175760; several panel tests failing regularly on mac. 1729#if defined(OS_MACOSX) 1730#define MAYBE_DevToolsConsole DISABLED_DevToolsConsole 1731#else 1732#define MAYBE_DevToolsConsole DevToolsConsole 1733#endif 1734IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevToolsConsole) { 1735 // Create a test panel with web contents loaded. 1736 CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE); 1737 GURL url(ui_test_utils::GetTestUrl( 1738 base::FilePath(kTestDir), 1739 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); 1740 params.url = url; 1741 Panel* panel = CreatePanelWithParams(params); 1742 1743 // Open devtools console. 1744 size_t num_browsers = 1; 1745 EXPECT_EQ(num_browsers, chrome::GetBrowserCount( 1746 browser()->profile(), 1747 browser()->host_desktop_type())); 1748 content::WindowedNotificationObserver signal( 1749 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 1750 content::NotificationService::AllSources()); 1751 EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS_CONSOLE)); 1752 signal.Wait(); 1753 1754 // Check that the new browser window that opened is dev tools window. 1755 ++num_browsers; 1756 EXPECT_EQ(num_browsers, chrome::GetBrowserCount( 1757 browser()->profile(), 1758 browser()->host_desktop_type())); 1759 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { 1760 if (*iter == browser()) 1761 continue; 1762 ASSERT_TRUE((*iter)->is_devtools()); 1763 } 1764 1765 panel->Close(); 1766} 1767 1768#if defined(OS_WIN) 1769#define MAYBE_Accelerator Accelerator 1770#else 1771#define MAYBE_Accelerator DISABLED_Accelerator 1772#endif 1773IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) { 1774 PanelManager* panel_manager = PanelManager::GetInstance(); 1775 1776 // Create a test panel with web contents loaded. 1777 CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE); 1778 GURL url(ui_test_utils::GetTestUrl( 1779 base::FilePath(kTestDir), 1780 base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); 1781 params.url = url; 1782 Panel* panel = CreatePanelWithParams(params); 1783 EXPECT_EQ(1, panel_manager->num_panels()); 1784 1785 // Close the panel by acclerator. 1786 content::WindowedNotificationObserver signal( 1787 chrome::NOTIFICATION_PANEL_CLOSED, 1788 content::Source<Panel>(panel)); 1789#if defined(USE_AURA) 1790 double now = ui::EventTimeForNow().InSecondsF(); 1791 content::NativeWebKeyboardEvent key_event( 1792 ui::ET_KEY_PRESSED, 1793 false, 1794 ui::VKEY_W, 1795 ui::EF_CONTROL_DOWN, 1796 now); 1797#elif defined(OS_WIN) 1798 ::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 }; 1799 content::NativeWebKeyboardEvent key_event(key_msg); 1800 key_event.modifiers = content::NativeWebKeyboardEvent::ControlKey; 1801#else 1802 content::NativeWebKeyboardEvent key_event; 1803#endif 1804 panel->HandleKeyboardEvent(key_event); 1805 signal.Wait(); 1806 EXPECT_EQ(0, panel_manager->num_panels()); 1807} 1808 1809class PanelExtensionApiTest : public ExtensionApiTest { 1810 protected: 1811 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 1812 ExtensionApiTest::SetUpCommandLine(command_line); 1813 command_line->AppendSwitch(switches::kEnablePanels); 1814 } 1815}; 1816 1817#if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \ 1818 defined(OS_MACOSX) 1819// Focus test fails if there is no window manager on Linux. 1820// Aura panels have different behavior that do not apply to this test. 1821#define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize 1822#else 1823#define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize 1824#endif 1825IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest, 1826 MAYBE_FocusChangeEventOnMinimize) { 1827 // This is needed so the subsequently created panels can be activated. 1828 // On a Mac, it transforms background-only test process into foreground one. 1829 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 1830 ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_; 1831} 1832