ash_test_base.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/ash_switches.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/display_controller.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shell/toplevel_window.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/test/ash_test_helper.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/test/display_manager_test_api.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/test/test_session_state_delegate.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/test_shell_delegate.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/test/test_system_tray_delegate.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/wm/window_positioner.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/aura_constants.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/screen_position_client.h" 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/client/window_tree_client.h" 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/aura/test/event_generator_delegate_aura.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/test/test_window_delegate.h" 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/window.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window_delegate.h" 2823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/aura/window_tree_host.h" 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/ime/input_method_initializer.h" 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/gestures/gesture_configuration.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h" 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/point.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h" 346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/wm/core/coordinate_conversion.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_CHROMEOS) 37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/system/chromeos/tray_display.h" 38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif 39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/test/test_metro_viewer_process_host.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/test/test_process_killer_win.h" 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/win/metro.h" 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/win/windows_version.h" 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/remote_window_tree_host_win.h" 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/window_tree_host_win.h" 475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/platform_window/win/win_window.h" 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "win8/test/test_registrar_constants.h" 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#if defined(USE_X11) 52a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/x/x11_connection.h" 5323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#endif 5423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test { 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass AshEventGeneratorDelegate 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch : public aura::test::EventGeneratorDelegateAura { 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AshEventGeneratorDelegate() {} 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~AshEventGeneratorDelegate() {} 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // aura::test::EventGeneratorDelegateAura overrides: 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual aura::WindowTreeHost* GetHostAt( 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Point& point_in_screen) const OVERRIDE { 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Screen* screen = Shell::GetScreen(); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return Shell::GetInstance()->display_controller()-> 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetRootWindowForDisplayId(display.id())->GetHost(); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual aura::client::ScreenPositionClient* GetScreenPositionClient( 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const aura::Window* window) const OVERRIDE { 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return aura::client::GetScreenPositionClient(window->GetRootWindow()); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate); 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////// 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AshTestBase::AshTestBase() 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) : setup_called_(false), 89bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch teardown_called_(false), 90bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch start_session_(true) { 9123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#if defined(USE_X11) 9223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // This is needed for tests which use this base class but are run in browser 9323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // test binaries so don't get the default initialization in the unit test 9423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // suite. 95a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::InitializeThreadedX11(); 9623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#endif 9723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 9823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) thread_bundle_.reset(new content::TestBrowserThreadBundle); 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Must initialize |ash_test_helper_| here because some tests rely on 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // AshTestBase methods before they call AshTestBase::SetUp(). 101a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch ash_test_helper_.reset(new AshTestHelper(base::MessageLoopForUI::current())); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AshTestBase::~AshTestBase() { 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CHECK(setup_called_) 106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) << "You have overridden SetUp but never called AshTestBase::SetUp"; 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CHECK(teardown_called_) 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) << "You have overridden TearDown but never called AshTestBase::TearDown"; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::SetUp() { 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) setup_called_ = true; 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Clears the saved state so that test doesn't use on the wrong 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // default state. 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shell::ToplevelWindow::ClearSavedStateForTest(); 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // TODO(jamescook): Can we do this without changing command line? 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Use the origin (1,1) so that it doesn't over 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // lap with the native mouse cursor. 12168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) CommandLine* command_line = CommandLine::ForCurrentProcess(); 12268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!command_line->HasSwitch(switches::kAshHostWindowBounds)) { 12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) command_line->AppendSwitchASCII( 12468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) switches::kAshHostWindowBounds, "1+1-800x600"); 12568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) } 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 1275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::SetUsePopupAsRootWindowForTest(true); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 129bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch ash_test_helper_->SetUp(start_session_); 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetPrimaryRootWindow()->Show(); 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Shell::GetPrimaryRootWindow()->GetHost()->Show(); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Move the mouse cursor to far away so that native events doesn't 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // interfere test expectations. 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000)); 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash::Shell::GetInstance()->cursor_manager()->EnableMouseEvents(); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Changing GestureConfiguration shouldn't make tests fail. 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(5); 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!command_line->HasSwitch(ash::switches::kForceAshToDesktop)) { 143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ipc_thread_.reset(new base::Thread("test_metro_viewer_ipc_thread")); 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::Thread::Options options; 146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) options.message_loop_type = base::MessageLoop::TYPE_IO; 147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ipc_thread_->StartWithOptions(options); 148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) metro_viewer_host_.reset( 149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) new TestMetroViewerProcessHost(ipc_thread_->message_loop_proxy())); 150f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CHECK(metro_viewer_host_->LaunchViewerAndWaitForConnection( 151a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) win8::test::kDefaultTestAppUserModelId)); 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::RemoteWindowTreeHostWin* window_tree_host = 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) aura::RemoteWindowTreeHostWin::Instance(); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CHECK(window_tree_host != NULL); 155f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 156f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ash::WindowPositioner::SetMaximizeFirstWindow(true); 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::TearDown() { 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) teardown_called_ = true; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Flush the message loop to finish pending release tasks. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RunAllPendingInMessageLoop(); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (base::win::GetVersion() >= base::win::VERSION_WIN8 && 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !CommandLine::ForCurrentProcess()->HasSwitch( 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ash::switches::kForceAshToDesktop)) { 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Check that our viewer connection is still established. 171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CHECK(!metro_viewer_host_->closed_unexpectedly()); 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash_test_helper_->TearDown(); 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ui::test::SetUsePopupAsRootWindowForTest(false); 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Kill the viewer process if we spun one up. 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) metro_viewer_host_.reset(); 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Clean up any dangling viewer processes as the metro APIs sometimes leave 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // zombies behind. A default browser process in metro will have the 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // following command line arg so use that to avoid killing all processes named 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // win8::test::kDefaultTestExePath. 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const wchar_t kViewerProcessArgument[] = L"DefaultBrowserServer"; 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::KillAllNamedProcessesWithArgument(win8::test::kDefaultTestExePath, 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kViewerProcessArgument); 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event_generator_.reset(); 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Some tests set an internal display id, 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // reset it here, so other tests will continue in a clean environment. 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 196116680a4aac90f2aa7413d9095a592090648e557Ben Murdochui::test::EventGenerator& AshTestBase::GetEventGenerator() { 197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!event_generator_) { 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event_generator_.reset( 199116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch new ui::test::EventGenerator(new AshEventGeneratorDelegate())); 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return *event_generator_.get(); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool AshTestBase::SupportsMultipleDisplays() { 205c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return AshTestHelper::SupportsMultipleDisplays(); 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool AshTestBase::SupportsHostWindowResize() { 209c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return AshTestHelper::SupportsHostWindowResize(); 2107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::UpdateDisplay(const std::string& display_specs) { 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DisplayManagerTestApi display_manager_test_api( 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell::GetInstance()->display_manager()); 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) display_manager_test_api.UpdateDisplay(display_specs); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)aura::Window* AshTestBase::CurrentContext() { 219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return ash_test_helper_->CurrentContext(); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) { 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect()); 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithBounds( 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds) { 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return CreateTestWindowInShellWithDelegate(NULL, 0, bounds); 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShell(SkColor color, 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds) { 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return CreateTestWindowInShellWithDelegate( 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new aura::test::ColorTestWindowDelegate(color), id, bounds); 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegate( 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds) { 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return CreateTestWindowInShellWithDelegateAndType( 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate, ui::wm::WINDOW_TYPE_NORMAL, id, bounds); 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegateAndType( 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::WindowDelegate* delegate, 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::wm::WindowType type, 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int id, 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds) { 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* window = new aura::Window(delegate); 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->set_id(id); 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->SetType(type); 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window->Init(aura::WINDOW_LAYER_TEXTURED); 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->Show(); 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (bounds.IsEmpty()) { 2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ParentWindowInPrimaryRootWindow(window); 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Display display = 2617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch Shell::GetScreen()->GetDisplayMatching(bounds); 2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root = ash::Shell::GetInstance()->display_controller()-> 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetRootWindowForDisplayId(display.id()); 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point origin = bounds.origin(); 2656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ::wm::ConvertPointFromScreen(root, &origin); 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->SetBounds(gfx::Rect(origin, bounds.size())); 2671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::ParentWindowWithContext(window, root, bounds); 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->SetProperty(aura::client::kCanMaximizeKey, true); 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return window; 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AshTestBase::ParentWindowInPrimaryRootWindow(aura::Window* window) { 2741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::ParentWindowWithContext( 2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window, Shell::GetPrimaryRootWindow(), gfx::Rect()); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::RunAllPendingInMessageLoop() { 279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash_test_helper_->RunAllPendingInMessageLoop(); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TestScreenshotDelegate* AshTestBase::GetScreenshotDelegate() { 2834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return ash_test_helper_->test_screenshot_delegate(); 2844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TestSystemTrayDelegate* AshTestBase::GetSystemTrayDelegate() { 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return static_cast<TestSystemTrayDelegate*>( 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Shell::GetInstance()->system_tray_delegate()); 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetSessionStarted(bool session_started) { 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash_test_helper_->test_shell_delegate()->test_session_state_delegate()-> 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetActiveUserSessionStarted(session_started); 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetUserLoggedIn(bool user_logged_in) { 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash_test_helper_->test_shell_delegate()->test_session_state_delegate()-> 298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetHasActiveUser(user_logged_in); 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetCanLockScreen(bool can_lock_screen) { 302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ash_test_helper_->test_shell_delegate()->test_session_state_delegate()-> 303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetCanLockScreen(can_lock_screen); 3041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 3051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AshTestBase::SetShouldLockScreenBeforeSuspending(bool should_lock) { 3071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ash_test_helper_->test_shell_delegate()->test_session_state_delegate()-> 3081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetShouldLockScreenBeforeSuspending(should_lock); 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 311bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::SetUserAddingScreenRunning(bool user_adding_screen_running) { 312bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ash_test_helper_->test_shell_delegate()->test_session_state_delegate()-> 313bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetUserAddingScreenRunning(user_adding_screen_running); 314bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 315bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 316bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::BlockUserSession(UserSessionBlockReason block_reason) { 317bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch switch (block_reason) { 318bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch case BLOCKED_BY_LOCK_SCREEN: 319bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetSessionStarted(true); 320bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetUserAddingScreenRunning(false); 321bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch Shell::GetInstance()->session_state_delegate()->LockScreen(); 322bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch break; 323bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch case BLOCKED_BY_LOGIN_SCREEN: 324bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetUserAddingScreenRunning(false); 325bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetSessionStarted(false); 326bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch break; 327bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch case BLOCKED_BY_USER_ADDING_SCREEN: 328bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetUserAddingScreenRunning(true); 329bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetSessionStarted(true); 330bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch break; 331bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch default: 332bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch NOTREACHED(); 333bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch break; 334bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch } 335bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 336bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 337bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::UnblockUserSession() { 338bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch Shell::GetInstance()->session_state_delegate()->UnlockScreen(); 339bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetSessionStarted(true); 340bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch SetUserAddingScreenRunning(false); 341bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 342bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 343bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace test 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 346