| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/panels/old_base_panel_browser_test.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/browser_list.h" | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/message_loop.h" | |
| 13 #include "base/path_service.h" | |
| 14 #include "base/string_number_conversions.h" | |
| 15 #include "chrome/browser/extensions/extension_service.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/ui/browser.h" | |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 19 #include "chrome/browser/ui/panels/native_panel.h" | |
| 20 #include "chrome/browser/ui/panels/panel_browser_window.h" | |
| 21 #include "chrome/browser/ui/panels/panel_manager.h" | |
| 22 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | |
| 23 #include "chrome/browser/ui/panels/test_panel_active_state_observer.h" | |
| 24 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" | |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 26 #include "chrome/common/chrome_notification_types.h" | |
| 27 #include "chrome/common/chrome_paths.h" | |
| 28 #include "chrome/common/chrome_switches.h" | |
| 29 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 30 #include "chrome/test/base/ui_test_utils.h" | |
| 31 #include "content/public/browser/notification_service.h" | |
| 32 #include "content/public/common/url_constants.h" | |
| 33 #include "content/public/test/web_contents_tester.h" | |
| 34 #include "sync/api/string_ordinal.h" | |
| 35 | |
| 36 #if defined(OS_LINUX) | |
| 37 #include "ui/base/x/x11_util.h" | |
| 38 #endif | |
| 39 | |
| 40 #if defined(OS_MACOSX) | |
| 41 #include "base/mac/scoped_nsautorelease_pool.h" | |
| 42 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | |
| 43 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | |
| 44 #endif | |
| 45 | |
| 46 using content::WebContentsTester; | |
| 47 using extensions::Extension; | |
| 48 | |
| 49 namespace { | |
| 50 | |
| 51 const gfx::Rect kTestingPrimaryScreenArea = gfx::Rect(0, 0, 800, 600); | |
| 52 const gfx::Rect kTestingWorkArea = gfx::Rect(0, 0, 800, 580); | |
| 53 | |
| 54 struct MockDesktopBar { | |
| 55 bool auto_hiding_enabled; | |
| 56 DisplaySettingsProvider::DesktopBarVisibility visibility; | |
| 57 int thickness; | |
| 58 }; | |
| 59 | |
| 60 class MockDisplaySettingsProviderImpl : | |
| 61 public OldBasePanelBrowserTest::MockDisplaySettingsProvider { | |
| 62 public: | |
| 63 explicit MockDisplaySettingsProviderImpl(PanelManager* panel_manager); | |
| 64 virtual ~MockDisplaySettingsProviderImpl() { } | |
| 65 | |
| 66 // Overridden from DisplaySettingsProvider: | |
| 67 virtual gfx::Rect GetPrimaryScreenArea() const OVERRIDE; | |
| 68 virtual gfx::Rect GetWorkArea() const OVERRIDE; | |
| 69 virtual bool IsAutoHidingDesktopBarEnabled( | |
| 70 DesktopBarAlignment alignment) OVERRIDE; | |
| 71 virtual int GetDesktopBarThickness( | |
| 72 DesktopBarAlignment alignment) const OVERRIDE; | |
| 73 virtual DesktopBarVisibility GetDesktopBarVisibility( | |
| 74 DesktopBarAlignment alignment) const OVERRIDE; | |
| 75 | |
| 76 // Overridden from MockDisplaySettingsProvider: | |
| 77 virtual void SetPrimaryScreenArea( | |
| 78 const gfx::Rect& primary_screen_area) OVERRIDE; | |
| 79 virtual void SetWorkArea(const gfx::Rect& work_area) OVERRIDE; | |
| 80 virtual void EnableAutoHidingDesktopBar(DesktopBarAlignment alignment, | |
| 81 bool enabled, | |
| 82 int thickness) OVERRIDE; | |
| 83 virtual void SetDesktopBarVisibility( | |
| 84 DesktopBarAlignment alignment, DesktopBarVisibility visibility) OVERRIDE; | |
| 85 virtual void SetDesktopBarThickness(DesktopBarAlignment alignment, | |
| 86 int thickness) OVERRIDE; | |
| 87 | |
| 88 private: | |
| 89 gfx::Rect testing_primary_screen_area_; | |
| 90 gfx::Rect testing_work_area_; | |
| 91 MockDesktopBar mock_desktop_bars[3]; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(MockDisplaySettingsProviderImpl); | |
| 94 }; | |
| 95 | |
| 96 | |
| 97 MockDisplaySettingsProviderImpl::MockDisplaySettingsProviderImpl( | |
| 98 PanelManager* panel_manager) { | |
| 99 DisplaySettingsProvider* old_provider = | |
| 100 panel_manager->display_settings_provider(); | |
| 101 | |
| 102 ObserverListBase<DisplaySettingsProvider::DisplayAreaObserver>::Iterator | |
| 103 display_area_observers_iter(old_provider->display_area_observers()); | |
| 104 AddDisplayAreaObserver(display_area_observers_iter.GetNext()); | |
| 105 DCHECK(!display_area_observers_iter.GetNext()); | |
| 106 | |
| 107 ObserverListBase<DisplaySettingsProvider::DesktopBarObserver>::Iterator | |
| 108 desktop_bar_observer_iter(old_provider->desktop_bar_observers()); | |
| 109 AddDesktopBarObserver(desktop_bar_observer_iter.GetNext()); | |
| 110 DCHECK(!desktop_bar_observer_iter.GetNext()); | |
| 111 | |
| 112 ObserverListBase<DisplaySettingsProvider::FullScreenObserver>::Iterator | |
| 113 full_screen_observer_iter(old_provider->full_screen_observers()); | |
| 114 AddFullScreenObserver(full_screen_observer_iter.GetNext()); | |
| 115 DCHECK(!full_screen_observer_iter.GetNext()); | |
| 116 | |
| 117 panel_manager->set_display_settings_provider(this); | |
| 118 | |
| 119 memset(mock_desktop_bars, 0, sizeof(mock_desktop_bars)); | |
| 120 } | |
| 121 | |
| 122 gfx::Rect MockDisplaySettingsProviderImpl::GetPrimaryScreenArea() const { | |
| 123 return testing_primary_screen_area_; | |
| 124 } | |
| 125 | |
| 126 gfx::Rect MockDisplaySettingsProviderImpl::GetWorkArea() const { | |
| 127 return testing_work_area_; | |
| 128 } | |
| 129 | |
| 130 bool MockDisplaySettingsProviderImpl::IsAutoHidingDesktopBarEnabled( | |
| 131 DesktopBarAlignment alignment) { | |
| 132 return mock_desktop_bars[static_cast<int>(alignment)].auto_hiding_enabled; | |
| 133 } | |
| 134 | |
| 135 int MockDisplaySettingsProviderImpl::GetDesktopBarThickness( | |
| 136 DesktopBarAlignment alignment) const { | |
| 137 return mock_desktop_bars[static_cast<int>(alignment)].thickness; | |
| 138 } | |
| 139 | |
| 140 DisplaySettingsProvider::DesktopBarVisibility | |
| 141 MockDisplaySettingsProviderImpl::GetDesktopBarVisibility( | |
| 142 DesktopBarAlignment alignment) const { | |
| 143 return mock_desktop_bars[static_cast<int>(alignment)].visibility; | |
| 144 } | |
| 145 | |
| 146 void MockDisplaySettingsProviderImpl::EnableAutoHidingDesktopBar( | |
| 147 DesktopBarAlignment alignment, bool enabled, int thickness) { | |
| 148 MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); | |
| 149 bar->auto_hiding_enabled = enabled; | |
| 150 bar->thickness = thickness; | |
| 151 OnAutoHidingDesktopBarChanged(); | |
| 152 } | |
| 153 | |
| 154 void MockDisplaySettingsProviderImpl::SetPrimaryScreenArea( | |
| 155 const gfx::Rect& primary_screen_area) { | |
| 156 testing_primary_screen_area_ = primary_screen_area; | |
| 157 } | |
| 158 | |
| 159 void MockDisplaySettingsProviderImpl::SetWorkArea(const gfx::Rect& work_area) { | |
| 160 testing_work_area_ = work_area; | |
| 161 OnDisplaySettingsChanged(); | |
| 162 } | |
| 163 | |
| 164 void MockDisplaySettingsProviderImpl::SetDesktopBarVisibility( | |
| 165 DesktopBarAlignment alignment, DesktopBarVisibility visibility) { | |
| 166 MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); | |
| 167 if (!bar->auto_hiding_enabled) | |
| 168 return; | |
| 169 if (visibility == bar->visibility) | |
| 170 return; | |
| 171 bar->visibility = visibility; | |
| 172 OnAutoHidingDesktopBarChanged(); | |
| 173 } | |
| 174 | |
| 175 void MockDisplaySettingsProviderImpl::SetDesktopBarThickness( | |
| 176 DesktopBarAlignment alignment, int thickness) { | |
| 177 MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); | |
| 178 if (!bar->auto_hiding_enabled) | |
| 179 return; | |
| 180 if (thickness == bar->thickness) | |
| 181 return; | |
| 182 bar->thickness = thickness; | |
| 183 OnAutoHidingDesktopBarChanged(); | |
| 184 } | |
| 185 | |
| 186 bool ExistsPanel(Panel* panel) { | |
| 187 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 188 return std::find(panels.begin(), panels.end(), panel) != panels.end(); | |
| 189 } | |
| 190 | |
| 191 } // namespace | |
| 192 | |
| 193 const FilePath::CharType* OldBasePanelBrowserTest::kTestDir = | |
| 194 FILE_PATH_LITERAL("panels"); | |
| 195 | |
| 196 OldBasePanelBrowserTest::OldBasePanelBrowserTest() | |
| 197 : InProcessBrowserTest(), | |
| 198 mock_display_settings_enabled_(true) { | |
| 199 #if defined(OS_MACOSX) | |
| 200 FindBarBridge::disable_animations_during_testing_ = true; | |
| 201 #endif | |
| 202 } | |
| 203 | |
| 204 OldBasePanelBrowserTest::~OldBasePanelBrowserTest() { | |
| 205 } | |
| 206 | |
| 207 bool OldBasePanelBrowserTest::SkipTestIfIceWM() { | |
| 208 #if defined(OS_LINUX) | |
| 209 return ui::GuessWindowManager() == ui::WM_ICE_WM; | |
| 210 #else | |
| 211 return false; | |
| 212 #endif | |
| 213 } | |
| 214 | |
| 215 bool OldBasePanelBrowserTest::SkipTestIfCompizWM() { | |
| 216 #if defined(OS_LINUX) | |
| 217 return ui::GuessWindowManager() == ui::WM_COMPIZ; | |
| 218 #else | |
| 219 return false; | |
| 220 #endif | |
| 221 } | |
| 222 | |
| 223 void OldBasePanelBrowserTest::SetUpCommandLine(CommandLine* command_line) { | |
| 224 command_line->AppendSwitch(switches::kEnablePanels); | |
| 225 } | |
| 226 | |
| 227 void OldBasePanelBrowserTest::SetUpOnMainThread() { | |
| 228 InProcessBrowserTest::SetUpOnMainThread(); | |
| 229 | |
| 230 // Setup the work area and desktop bar so that we have consistent testing | |
| 231 // environment for all panel related tests. | |
| 232 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 233 if (mock_display_settings_enabled_) { | |
| 234 mock_display_settings_provider_ = | |
| 235 new MockDisplaySettingsProviderImpl(panel_manager); | |
| 236 SetTestingAreas(kTestingPrimaryScreenArea, kTestingWorkArea); | |
| 237 } | |
| 238 | |
| 239 panel_manager->enable_auto_sizing(false); | |
| 240 | |
| 241 PanelManager::shorten_time_intervals_for_testing(); | |
| 242 | |
| 243 // Simulate the mouse movement so that tests are not affected by actual mouse | |
| 244 // events. | |
| 245 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); | |
| 246 panel_manager->SetMouseWatcherForTesting(mouse_watcher); | |
| 247 | |
| 248 // This is needed so the subsequently created panels can be activated. | |
| 249 // On a Mac, it transforms background-only test process into foreground one. | |
| 250 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 251 } | |
| 252 | |
| 253 void OldBasePanelBrowserTest::WaitForPanelActiveState( | |
| 254 Panel* panel, ActiveState expected_state) { | |
| 255 DCHECK(expected_state == SHOW_AS_ACTIVE || | |
| 256 expected_state == SHOW_AS_INACTIVE); | |
| 257 PanelActiveStateObserver signal(panel, expected_state == SHOW_AS_ACTIVE); | |
| 258 signal.Wait(); | |
| 259 } | |
| 260 | |
| 261 void OldBasePanelBrowserTest::WaitForWindowSizeAvailable(Panel* panel) { | |
| 262 scoped_ptr<NativePanelTesting> panel_testing( | |
| 263 CreateNativePanelTesting(panel)); | |
| 264 content::WindowedNotificationObserver signal( | |
| 265 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, | |
| 266 content::Source<Panel>(panel)); | |
| 267 if (panel_testing->IsWindowSizeKnown()) | |
| 268 return; | |
| 269 signal.Wait(); | |
| 270 EXPECT_TRUE(panel_testing->IsWindowSizeKnown()); | |
| 271 } | |
| 272 | |
| 273 void OldBasePanelBrowserTest::WaitForBoundsAnimationFinished(Panel* panel) { | |
| 274 scoped_ptr<NativePanelTesting> panel_testing( | |
| 275 CreateNativePanelTesting(panel)); | |
| 276 content::WindowedNotificationObserver signal( | |
| 277 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | |
| 278 content::Source<Panel>(panel)); | |
| 279 if (!panel_testing->IsAnimatingBounds()) | |
| 280 return; | |
| 281 signal.Wait(); | |
| 282 EXPECT_TRUE(!panel_testing->IsAnimatingBounds()); | |
| 283 } | |
| 284 | |
| 285 void OldBasePanelBrowserTest::WaitForExpansionStateChanged( | |
| 286 Panel* panel, Panel::ExpansionState expansion_state) { | |
| 287 content::WindowedNotificationObserver signal( | |
| 288 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | |
| 289 content::Source<Panel>(panel)); | |
| 290 if (panel->expansion_state() == expansion_state) | |
| 291 return; | |
| 292 signal.Wait(); | |
| 293 EXPECT_EQ(expansion_state, panel->expansion_state()); | |
| 294 } | |
| 295 | |
| 296 OldBasePanelBrowserTest::CreatePanelParams::CreatePanelParams( | |
| 297 const std::string& name, | |
| 298 const gfx::Rect& bounds, | |
| 299 ActiveState show_flag) | |
| 300 : name(name), | |
| 301 bounds(bounds), | |
| 302 show_flag(show_flag), | |
| 303 wait_for_fully_created(true), | |
| 304 expected_active_state(show_flag) { | |
| 305 } | |
| 306 | |
| 307 Panel* OldBasePanelBrowserTest::CreatePanelWithParams( | |
| 308 const CreatePanelParams& params) { | |
| 309 #if defined(OS_MACOSX) | |
| 310 // Opening panels on a Mac causes NSWindowController of the Panel window | |
| 311 // to be autoreleased. We need a pool drained after it's done so the test | |
| 312 // can close correctly. The NSWindowController of the Panel window controls | |
| 313 // lifetime of the Browser object so we want to release it as soon as | |
| 314 // possible. In real Chrome, this is done by message pump. | |
| 315 // On non-Mac platform, this is an empty class. | |
| 316 base::mac::ScopedNSAutoreleasePool autorelease_pool; | |
| 317 #endif | |
| 318 | |
| 319 Browser* panel_browser = new Browser( | |
| 320 Browser::CreateParams::CreateForApp( | |
| 321 Browser::TYPE_PANEL, params.name, params.bounds, | |
| 322 browser()->profile())); | |
| 323 EXPECT_TRUE(panel_browser->is_type_panel()); | |
| 324 | |
| 325 if (!params.url.is_empty()) { | |
| 326 content::WindowedNotificationObserver observer( | |
| 327 content::NOTIFICATION_LOAD_STOP, | |
| 328 content::NotificationService::AllSources()); | |
| 329 chrome::AddSelectedTabWithURL(panel_browser, params.url, | |
| 330 content::PAGE_TRANSITION_AUTO_TOPLEVEL); | |
| 331 observer.Wait(); | |
| 332 } | |
| 333 | |
| 334 PanelBrowserWindow* panel_browser_window = | |
| 335 static_cast<PanelBrowserWindow*>(panel_browser->window()); | |
| 336 Panel* panel = panel_browser_window->panel(); | |
| 337 | |
| 338 if (!PanelManager::GetInstance()->auto_sizing_enabled() || | |
| 339 params.bounds.width() || params.bounds.height()) { | |
| 340 EXPECT_FALSE(panel->auto_resizable()); | |
| 341 } else { | |
| 342 EXPECT_TRUE(panel->auto_resizable()); | |
| 343 } | |
| 344 | |
| 345 if (params.show_flag == SHOW_AS_ACTIVE) { | |
| 346 panel->Show(); | |
| 347 } else { | |
| 348 panel->ShowInactive(); | |
| 349 } | |
| 350 | |
| 351 if (params.wait_for_fully_created) { | |
| 352 MessageLoopForUI::current()->RunAllPending(); | |
| 353 | |
| 354 #if defined(OS_LINUX) | |
| 355 // On bots, we might have a simple window manager which always activates new | |
| 356 // windows, and can't always deactivate them. Re-activate the main tabbed | |
| 357 // browser to "deactivate" the newly created panel. | |
| 358 if (params.expected_active_state == SHOW_AS_INACTIVE && | |
| 359 ui::GuessWindowManager() == ui::WM_ICE_WM) { | |
| 360 // Wait for new panel to become active before deactivating to ensure | |
| 361 // the activated notification is consumed before we wait for the panel | |
| 362 // to become inactive. | |
| 363 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); | |
| 364 browser()->window()->Activate(); | |
| 365 } | |
| 366 #endif | |
| 367 // More waiting, because gaining or losing focus may require inter-process | |
| 368 // asynchronous communication, and it is not enough to just run the local | |
| 369 // message loop to make sure this activity has completed. | |
| 370 WaitForPanelActiveState(panel, params.expected_active_state); | |
| 371 | |
| 372 // On Linux, window size is not available right away and we should wait | |
| 373 // before moving forward with the test. | |
| 374 WaitForWindowSizeAvailable(panel); | |
| 375 | |
| 376 // Wait for the bounds animations on creation to finish. | |
| 377 WaitForBoundsAnimationFinished(panel); | |
| 378 } | |
| 379 | |
| 380 return panel; | |
| 381 } | |
| 382 | |
| 383 Panel* OldBasePanelBrowserTest::CreatePanelWithBounds( | |
| 384 const std::string& panel_name, const gfx::Rect& bounds) { | |
| 385 CreatePanelParams params(panel_name, bounds, SHOW_AS_ACTIVE); | |
| 386 return CreatePanelWithParams(params); | |
| 387 } | |
| 388 | |
| 389 Panel* OldBasePanelBrowserTest::CreatePanel(const std::string& panel_name) { | |
| 390 CreatePanelParams params(panel_name, gfx::Rect(), SHOW_AS_ACTIVE); | |
| 391 return CreatePanelWithParams(params); | |
| 392 } | |
| 393 | |
| 394 Panel* OldBasePanelBrowserTest::CreateDockedPanel(const std::string& name, | |
| 395 const gfx::Rect& bounds) { | |
| 396 Panel* panel = CreatePanelWithBounds(name, bounds); | |
| 397 EXPECT_EQ(PanelStrip::DOCKED, panel->panel_strip()->type()); | |
| 398 return panel; | |
| 399 } | |
| 400 | |
| 401 Panel* OldBasePanelBrowserTest::CreateDetachedPanel(const std::string& name, | |
| 402 const gfx::Rect& bounds) { | |
| 403 Panel* panel = CreatePanelWithBounds(name, bounds); | |
| 404 panel->manager()->MovePanelToStrip(panel, | |
| 405 PanelStrip::DETACHED, | |
| 406 PanelStrip::DEFAULT_POSITION); | |
| 407 EXPECT_EQ(PanelStrip::DETACHED, panel->panel_strip()->type()); | |
| 408 // The panel is first created as docked panel, which ignores the specified | |
| 409 // origin in |bounds|. We need to reposition the panel after it becomes | |
| 410 // detached. | |
| 411 panel->SetPanelBounds(bounds); | |
| 412 WaitForBoundsAnimationFinished(panel); | |
| 413 return panel; | |
| 414 } | |
| 415 | |
| 416 // static | |
| 417 NativePanelTesting* OldBasePanelBrowserTest::CreateNativePanelTesting( | |
| 418 Panel* panel) { | |
| 419 return panel->native_panel()->CreateNativePanelTesting(); | |
| 420 } | |
| 421 | |
| 422 void OldBasePanelBrowserTest::CreateTestTabContents(Browser* browser) { | |
| 423 TabContents* tab_contents = TabContents::Factory::CreateTabContents( | |
| 424 WebContentsTester::CreateTestWebContents(browser->profile(), NULL)); | |
| 425 chrome::AddTab(browser, tab_contents, content::PAGE_TRANSITION_LINK); | |
| 426 } | |
| 427 | |
| 428 scoped_refptr<Extension> OldBasePanelBrowserTest::CreateExtension( | |
| 429 const FilePath::StringType& path, | |
| 430 Extension::Location location, | |
| 431 const DictionaryValue& extra_value) { | |
| 432 #if defined(OS_WIN) | |
| 433 FilePath full_path(FILE_PATH_LITERAL("c:\\")); | |
| 434 #else | |
| 435 FilePath full_path(FILE_PATH_LITERAL("/")); | |
| 436 #endif | |
| 437 full_path = full_path.Append(path); | |
| 438 | |
| 439 scoped_ptr<DictionaryValue> input_value(extra_value.DeepCopy()); | |
| 440 input_value->SetString(extension_manifest_keys::kVersion, "1.0.0.0"); | |
| 441 input_value->SetString(extension_manifest_keys::kName, "Sample Extension"); | |
| 442 | |
| 443 std::string error; | |
| 444 scoped_refptr<Extension> extension = Extension::Create( | |
| 445 full_path, location, *input_value, Extension::NO_FLAGS, &error); | |
| 446 EXPECT_TRUE(extension.get()); | |
| 447 EXPECT_STREQ("", error.c_str()); | |
| 448 browser()->profile()->GetExtensionService()-> | |
| 449 OnExtensionInstalled(extension.get(), false, syncer::StringOrdinal()); | |
| 450 return extension; | |
| 451 } | |
| 452 | |
| 453 void OldBasePanelBrowserTest::SetTestingAreas( | |
| 454 const gfx::Rect& primary_screen_area, | |
| 455 const gfx::Rect& work_area) { | |
| 456 DCHECK(primary_screen_area.Contains(work_area)); | |
| 457 mock_display_settings_provider_->SetPrimaryScreenArea(primary_screen_area); | |
| 458 mock_display_settings_provider_->SetWorkArea( | |
| 459 work_area.IsEmpty() ? primary_screen_area : work_area); | |
| 460 } | |
| 461 | |
| 462 void OldBasePanelBrowserTest::CloseWindowAndWait(Panel* panel) { | |
| 463 // Closing a panel may involve several async tasks. Need to use | |
| 464 // message pump and wait for the notification. | |
| 465 PanelManager* manager = PanelManager::GetInstance(); | |
| 466 int panel_count = manager->num_panels(); | |
| 467 content::WindowedNotificationObserver signal( | |
| 468 chrome::NOTIFICATION_PANEL_CLOSED, | |
| 469 content::Source<Panel>(panel)); | |
| 470 panel->Close(); | |
| 471 signal.Wait(); | |
| 472 // Now we have one less panel. | |
| 473 EXPECT_EQ(panel_count - 1, manager->num_panels()); | |
| 474 | |
| 475 #if defined(OS_MACOSX) | |
| 476 // Mac window controllers may be autoreleased, and in the non-test | |
| 477 // environment, may actually depend on the autorelease pool being recycled | |
| 478 // with the run loop in order to perform important work. Replicate this in | |
| 479 // the test environment. | |
| 480 AutoreleasePool()->Recycle(); | |
| 481 | |
| 482 // Make sure that everything has a chance to run. | |
| 483 chrome::testing::NSRunLoopRunAllPending(); | |
| 484 #endif // OS_MACOSX | |
| 485 } | |
| 486 | |
| 487 void OldBasePanelBrowserTest::MoveMouseAndWaitForExpansionStateChange( | |
| 488 Panel* panel, | |
| 489 const gfx::Point& position) { | |
| 490 content::WindowedNotificationObserver signal( | |
| 491 chrome::NOTIFICATION_PANEL_CHANGED_EXPANSION_STATE, | |
| 492 content::Source<Panel>(panel)); | |
| 493 MoveMouse(position); | |
| 494 signal.Wait(); | |
| 495 } | |
| 496 | |
| 497 void OldBasePanelBrowserTest::MoveMouse(const gfx::Point& position) { | |
| 498 PanelManager::GetInstance()->mouse_watcher()->NotifyMouseMovement(position); | |
| 499 } | |
| 500 | |
| 501 std::string OldBasePanelBrowserTest::MakePanelName(int index) { | |
| 502 std::string panel_name("Panel"); | |
| 503 return panel_name + base::IntToString(index); | |
| 504 } | |
| OLD | NEW |