| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | 5 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 Panel* panel, ActiveState expected_state) { | 246 Panel* panel, ActiveState expected_state) { |
| 247 DCHECK(expected_state == SHOW_AS_ACTIVE || | 247 DCHECK(expected_state == SHOW_AS_ACTIVE || |
| 248 expected_state == SHOW_AS_INACTIVE); | 248 expected_state == SHOW_AS_INACTIVE); |
| 249 PanelActiveStateObserver signal(panel, expected_state == SHOW_AS_ACTIVE); | 249 PanelActiveStateObserver signal(panel, expected_state == SHOW_AS_ACTIVE); |
| 250 signal.Wait(); | 250 signal.Wait(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void BasePanelBrowserTest::WaitForWindowSizeAvailable(Panel* panel) { | 253 void BasePanelBrowserTest::WaitForWindowSizeAvailable(Panel* panel) { |
| 254 scoped_ptr<NativePanelTesting> panel_testing( | 254 scoped_ptr<NativePanelTesting> panel_testing( |
| 255 CreateNativePanelTesting(panel)); | 255 CreateNativePanelTesting(panel)); |
| 256 ui_test_utils::WindowedNotificationObserver signal( | 256 content::WindowedNotificationObserver signal( |
| 257 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, | 257 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, |
| 258 content::Source<Panel>(panel)); | 258 content::Source<Panel>(panel)); |
| 259 if (panel_testing->IsWindowSizeKnown()) | 259 if (panel_testing->IsWindowSizeKnown()) |
| 260 return; | 260 return; |
| 261 signal.Wait(); | 261 signal.Wait(); |
| 262 EXPECT_TRUE(panel_testing->IsWindowSizeKnown()); | 262 EXPECT_TRUE(panel_testing->IsWindowSizeKnown()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void BasePanelBrowserTest::WaitForBoundsAnimationFinished(Panel* panel) { | 265 void BasePanelBrowserTest::WaitForBoundsAnimationFinished(Panel* panel) { |
| 266 scoped_ptr<NativePanelTesting> panel_testing( | 266 scoped_ptr<NativePanelTesting> panel_testing( |
| 267 CreateNativePanelTesting(panel)); | 267 CreateNativePanelTesting(panel)); |
| 268 ui_test_utils::WindowedNotificationObserver signal( | 268 content::WindowedNotificationObserver signal( |
| 269 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | 269 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 270 content::Source<Panel>(panel)); | 270 content::Source<Panel>(panel)); |
| 271 if (!panel_testing->IsAnimatingBounds()) | 271 if (!panel_testing->IsAnimatingBounds()) |
| 272 return; | 272 return; |
| 273 signal.Wait(); | 273 signal.Wait(); |
| 274 EXPECT_TRUE(!panel_testing->IsAnimatingBounds()); | 274 EXPECT_TRUE(!panel_testing->IsAnimatingBounds()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void BasePanelBrowserTest::WaitForExpansionStateChanged( | 277 void BasePanelBrowserTest::WaitForExpansionStateChanged( |
| 278 Panel* panel, Panel::ExpansionState expansion_state) { | 278 Panel* panel, Panel::ExpansionState expansion_state) { |
| 279 ui_test_utils::WindowedNotificationObserver signal( | 279 content::WindowedNotificationObserver signal( |
| 280 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 280 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
| 281 content::Source<Panel>(panel)); | 281 content::Source<Panel>(panel)); |
| 282 if (panel->expansion_state() == expansion_state) | 282 if (panel->expansion_state() == expansion_state) |
| 283 return; | 283 return; |
| 284 signal.Wait(); | 284 signal.Wait(); |
| 285 EXPECT_EQ(expansion_state, panel->expansion_state()); | 285 EXPECT_EQ(expansion_state, panel->expansion_state()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 Panel* BasePanelBrowserTest::CreatePanelWithParams( | 288 Panel* BasePanelBrowserTest::CreatePanelWithParams( |
| 289 const CreatePanelParams& params) { | 289 const CreatePanelParams& params) { |
| 290 #if defined(OS_MACOSX) | 290 #if defined(OS_MACOSX) |
| 291 // Opening panels on a Mac causes NSWindowController of the Panel window | 291 // Opening panels on a Mac causes NSWindowController of the Panel window |
| 292 // to be autoreleased. We need a pool drained after it's done so the test | 292 // to be autoreleased. We need a pool drained after it's done so the test |
| 293 // can close correctly. The NSWindowController of the Panel window controls | 293 // can close correctly. The NSWindowController of the Panel window controls |
| 294 // lifetime of the Browser object so we want to release it as soon as | 294 // lifetime of the Browser object so we want to release it as soon as |
| 295 // possible. In real Chrome, this is done by message pump. | 295 // possible. In real Chrome, this is done by message pump. |
| 296 // On non-Mac platform, this is an empty class. | 296 // On non-Mac platform, this is an empty class. |
| 297 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 297 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 298 #endif | 298 #endif |
| 299 | 299 |
| 300 ui_test_utils::WindowedNotificationObserver observer( | 300 content::WindowedNotificationObserver observer( |
| 301 content::NOTIFICATION_LOAD_STOP, | 301 content::NOTIFICATION_LOAD_STOP, |
| 302 content::NotificationService::AllSources()); | 302 content::NotificationService::AllSources()); |
| 303 | 303 |
| 304 PanelManager* manager = PanelManager::GetInstance(); | 304 PanelManager* manager = PanelManager::GetInstance(); |
| 305 Panel* panel = manager->CreatePanel(params.name, browser()->profile(), | 305 Panel* panel = manager->CreatePanel(params.name, browser()->profile(), |
| 306 params.url, params.bounds.size()); | 306 params.url, params.bounds.size()); |
| 307 | 307 |
| 308 if (!params.url.is_empty()) | 308 if (!params.url.is_empty()) |
| 309 observer.Wait(); | 309 observer.Wait(); |
| 310 | 310 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 mock_display_settings_provider_->SetPrimaryScreenArea(primary_screen_area); | 429 mock_display_settings_provider_->SetPrimaryScreenArea(primary_screen_area); |
| 430 mock_display_settings_provider_->SetWorkArea( | 430 mock_display_settings_provider_->SetWorkArea( |
| 431 work_area.IsEmpty() ? primary_screen_area : work_area); | 431 work_area.IsEmpty() ? primary_screen_area : work_area); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void BasePanelBrowserTest::CloseWindowAndWait(Panel* panel) { | 434 void BasePanelBrowserTest::CloseWindowAndWait(Panel* panel) { |
| 435 // Closing a panel may involve several async tasks. Need to use | 435 // Closing a panel may involve several async tasks. Need to use |
| 436 // message pump and wait for the notification. | 436 // message pump and wait for the notification. |
| 437 PanelManager* manager = PanelManager::GetInstance(); | 437 PanelManager* manager = PanelManager::GetInstance(); |
| 438 int panel_count = manager->num_panels(); | 438 int panel_count = manager->num_panels(); |
| 439 ui_test_utils::WindowedNotificationObserver signal( | 439 content::WindowedNotificationObserver signal( |
| 440 chrome::NOTIFICATION_PANEL_CLOSED, | 440 chrome::NOTIFICATION_PANEL_CLOSED, |
| 441 content::Source<Panel>(panel)); | 441 content::Source<Panel>(panel)); |
| 442 panel->Close(); | 442 panel->Close(); |
| 443 signal.Wait(); | 443 signal.Wait(); |
| 444 // Now we have one less panel. | 444 // Now we have one less panel. |
| 445 EXPECT_EQ(panel_count - 1, manager->num_panels()); | 445 EXPECT_EQ(panel_count - 1, manager->num_panels()); |
| 446 | 446 |
| 447 #if defined(OS_MACOSX) | 447 #if defined(OS_MACOSX) |
| 448 // Mac window controllers may be autoreleased, and in the non-test | 448 // Mac window controllers may be autoreleased, and in the non-test |
| 449 // environment, may actually depend on the autorelease pool being recycled | 449 // environment, may actually depend on the autorelease pool being recycled |
| 450 // with the run loop in order to perform important work. Replicate this in | 450 // with the run loop in order to perform important work. Replicate this in |
| 451 // the test environment. | 451 // the test environment. |
| 452 AutoreleasePool()->Recycle(); | 452 AutoreleasePool()->Recycle(); |
| 453 | 453 |
| 454 // Make sure that everything has a chance to run. | 454 // Make sure that everything has a chance to run. |
| 455 chrome::testing::NSRunLoopRunAllPending(); | 455 chrome::testing::NSRunLoopRunAllPending(); |
| 456 #endif // OS_MACOSX | 456 #endif // OS_MACOSX |
| 457 } | 457 } |
| 458 | 458 |
| 459 void BasePanelBrowserTest::MoveMouseAndWaitForExpansionStateChange( | 459 void BasePanelBrowserTest::MoveMouseAndWaitForExpansionStateChange( |
| 460 Panel* panel, | 460 Panel* panel, |
| 461 const gfx::Point& position) { | 461 const gfx::Point& position) { |
| 462 ui_test_utils::WindowedNotificationObserver signal( | 462 content::WindowedNotificationObserver signal( |
| 463 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | 463 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, |
| 464 content::Source<Panel>(panel)); | 464 content::Source<Panel>(panel)); |
| 465 MoveMouse(position); | 465 MoveMouse(position); |
| 466 signal.Wait(); | 466 signal.Wait(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void BasePanelBrowserTest::MoveMouse(const gfx::Point& position) { | 469 void BasePanelBrowserTest::MoveMouse(const gfx::Point& position) { |
| 470 PanelManager::GetInstance()->mouse_watcher()->NotifyMouseMovement(position); | 470 PanelManager::GetInstance()->mouse_watcher()->NotifyMouseMovement(position); |
| 471 } | 471 } |
| 472 | 472 |
| 473 std::string BasePanelBrowserTest::MakePanelName(int index) { | 473 std::string BasePanelBrowserTest::MakePanelName(int index) { |
| 474 std::string panel_name("Panel"); | 474 std::string panel_name("Panel"); |
| 475 return panel_name + base::IntToString(index); | 475 return panel_name + base::IntToString(index); |
| 476 } | 476 } |
| OLD | NEW |