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"
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/win/metro.h"
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/win/windows_version.h"
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/remote_window_tree_host_win.h"
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/aura/window_tree_host_win.h"
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/platform_window/win/win_window.h"
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "win8/test/test_registrar_constants.h"
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#if defined(USE_X11)
51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/gfx/x/x11_connection.h"
5223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#endif
5323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test {
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
58116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass AshEventGeneratorDelegate
59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    : public aura::test::EventGeneratorDelegateAura {
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AshEventGeneratorDelegate() {}
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~AshEventGeneratorDelegate() {}
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // aura::test::EventGeneratorDelegateAura overrides:
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual aura::WindowTreeHost* GetHostAt(
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Point& point_in_screen) const OVERRIDE {
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Screen* screen = Shell::GetScreen();
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen);
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return Shell::GetInstance()->display_controller()->
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        GetRootWindowForDisplayId(display.id())->GetHost();
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual aura::client::ScreenPositionClient* GetScreenPositionClient(
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const aura::Window* window) const OVERRIDE {
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return aura::client::GetScreenPositionClient(window->GetRootWindow());
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate);
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/////////////////////////////////////////////////////////////////////////////
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AshTestBase::AshTestBase()
87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : setup_called_(false),
88bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch      teardown_called_(false),
89bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch      start_session_(true) {
9023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#if defined(USE_X11)
9123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // This is needed for tests which use this base class but are run in browser
9223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // test binaries so don't get the default initialization in the unit test
9323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // suite.
94a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  gfx::InitializeThreadedX11();
9523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#endif
9623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
9723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  thread_bundle_.reset(new content::TestBrowserThreadBundle);
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Must initialize |ash_test_helper_| here because some tests rely on
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // AshTestBase methods before they call AshTestBase::SetUp().
100a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  ash_test_helper_.reset(new AshTestHelper(base::MessageLoopForUI::current()));
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AshTestBase::~AshTestBase() {
104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CHECK(setup_called_)
105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      << "You have overridden SetUp but never called AshTestBase::SetUp";
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CHECK(teardown_called_)
107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      << "You have overridden TearDown but never called AshTestBase::TearDown";
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::SetUp() {
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  setup_called_ = true;
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Clears the saved state so that test doesn't use on the wrong
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // default state.
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  shell::ToplevelWindow::ClearSavedStateForTest();
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(jamescook): Can we do this without changing command line?
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Use the origin (1,1) so that it doesn't over
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // lap with the native mouse cursor.
12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  CommandLine* command_line = CommandLine::ForCurrentProcess();
12168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (!command_line->HasSwitch(switches::kAshHostWindowBounds)) {
12268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    command_line->AppendSwitchASCII(
12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)        switches::kAshHostWindowBounds, "1+1-800x600");
12468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  }
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::SetUsePopupAsRootWindowForTest(true);
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
128bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  ash_test_helper_->SetUp(start_session_);
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Shell::GetPrimaryRootWindow()->Show();
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetPrimaryRootWindow()->GetHost()->Show();
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Move the mouse cursor to far away so that native events doesn't
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // interfere test expectations.
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000));
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash::Shell::GetInstance()->cursor_manager()->EnableMouseEvents();
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Changing GestureConfiguration shouldn't make tests fail.
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(5);
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!command_line->HasSwitch(ash::switches::kForceAshToDesktop)) {
142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ipc_thread_.reset(new base::Thread("test_metro_viewer_ipc_thread"));
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      base::Thread::Options options;
145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      options.message_loop_type = base::MessageLoop::TYPE_IO;
146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ipc_thread_->StartWithOptions(options);
147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      metro_viewer_host_.reset(
148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          new TestMetroViewerProcessHost(ipc_thread_->message_loop_proxy()));
149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CHECK(metro_viewer_host_->LaunchViewerAndWaitForConnection(
150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          win8::test::kDefaultTestAppUserModelId));
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      aura::RemoteWindowTreeHostWin* window_tree_host =
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          aura::RemoteWindowTreeHostWin::Instance();
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CHECK(window_tree_host != NULL);
154f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
155f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ash::WindowPositioner::SetMaximizeFirstWindow(true);
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::TearDown() {
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  teardown_called_ = true;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flush the message loop to finish pending release tasks.
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      !CommandLine::ForCurrentProcess()->HasSwitch(
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          ash::switches::kForceAshToDesktop)) {
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Check that our viewer connection is still established.
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    CHECK(!metro_viewer_host_->closed_unexpectedly());
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->TearDown();
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::SetUsePopupAsRootWindowForTest(false);
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Kill the viewer process if we spun one up.
1781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (metro_viewer_host_) {
1791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    metro_viewer_host_->TerminateViewer();
1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    metro_viewer_host_.reset();
1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event_generator_.reset();
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Some tests set an internal display id,
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // reset it here, so other tests will continue in a clean environment.
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
190116680a4aac90f2aa7413d9095a592090648e557Ben Murdochui::test::EventGenerator& AshTestBase::GetEventGenerator() {
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!event_generator_) {
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event_generator_.reset(
193116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        new ui::test::EventGenerator(new AshEventGeneratorDelegate()));
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return *event_generator_.get();
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool AshTestBase::SupportsMultipleDisplays() {
199c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return AshTestHelper::SupportsMultipleDisplays();
200eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
201eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
202eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool AshTestBase::SupportsHostWindowResize() {
203c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  return AshTestHelper::SupportsHostWindowResize();
2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
2057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::UpdateDisplay(const std::string& display_specs) {
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayManagerTestApi display_manager_test_api(
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Shell::GetInstance()->display_manager());
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager_test_api.UpdateDisplay(display_specs);
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)aura::Window* AshTestBase::CurrentContext() {
213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return ash_test_helper_->CurrentContext();
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithBounds(
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(NULL, 0, bounds);
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShell(SkColor color,
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   int id,
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   const gfx::Rect& bounds) {
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      new aura::test::ColorTestWindowDelegate(color), id, bounds);
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegate(
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::WindowDelegate* delegate,
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int id,
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegateAndType(
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      delegate, ui::wm::WINDOW_TYPE_NORMAL, id, bounds);
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegateAndType(
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::WindowDelegate* delegate,
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ui::wm::WindowType type,
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int id,
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* window = new aura::Window(delegate);
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->set_id(id);
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetType(type);
2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window->Init(aura::WINDOW_LAYER_TEXTURED);
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->Show();
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (bounds.IsEmpty()) {
2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    ParentWindowInPrimaryRootWindow(window);
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Display display =
2557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        Shell::GetScreen()->GetDisplayMatching(bounds);
2561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::Window* root = ash::Shell::GetInstance()->display_controller()->
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        GetRootWindowForDisplayId(display.id());
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Point origin = bounds.origin();
2596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ::wm::ConvertPointFromScreen(root, &origin);
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    window->SetBounds(gfx::Rect(origin, bounds.size()));
2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    aura::client::ParentWindowWithContext(window, root, bounds);
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetProperty(aura::client::kCanMaximizeKey, true);
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return window;
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AshTestBase::ParentWindowInPrimaryRootWindow(aura::Window* window) {
2681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::client::ParentWindowWithContext(
2691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      window, Shell::GetPrimaryRootWindow(), gfx::Rect());
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::RunAllPendingInMessageLoop() {
273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->RunAllPendingInMessageLoop();
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TestScreenshotDelegate* AshTestBase::GetScreenshotDelegate() {
2774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return ash_test_helper_->test_screenshot_delegate();
2784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
2794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TestSystemTrayDelegate* AshTestBase::GetSystemTrayDelegate() {
2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return static_cast<TestSystemTrayDelegate*>(
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shell::GetInstance()->system_tray_delegate());
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetSessionStarted(bool session_started) {
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetActiveUserSessionStarted(session_started);
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetUserLoggedIn(bool user_logged_in) {
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetHasActiveUser(user_logged_in);
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetCanLockScreen(bool can_lock_screen) {
296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetCanLockScreen(can_lock_screen);
2981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void AshTestBase::SetShouldLockScreenBeforeSuspending(bool should_lock) {
3011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
3021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SetShouldLockScreenBeforeSuspending(should_lock);
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
305bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::SetUserAddingScreenRunning(bool user_adding_screen_running) {
306bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
307bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetUserAddingScreenRunning(user_adding_screen_running);
308bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch}
309bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
310bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::BlockUserSession(UserSessionBlockReason block_reason) {
311bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  switch (block_reason) {
312bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch    case BLOCKED_BY_LOCK_SCREEN:
313bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetSessionStarted(true);
314bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetUserAddingScreenRunning(false);
315bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      Shell::GetInstance()->session_state_delegate()->LockScreen();
316bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      break;
317bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch    case BLOCKED_BY_LOGIN_SCREEN:
318bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetUserAddingScreenRunning(false);
319bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetSessionStarted(false);
320bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      break;
321bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch    case BLOCKED_BY_USER_ADDING_SCREEN:
322bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetUserAddingScreenRunning(true);
323bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      SetSessionStarted(true);
324bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      break;
325bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch    default:
326bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      NOTREACHED();
327bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      break;
328bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  }
329bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch}
330bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
331bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid AshTestBase::UnblockUserSession() {
332bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  Shell::GetInstance()->session_state_delegate()->UnlockScreen();
333bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  SetSessionStarted(true);
334bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  SetUserAddingScreenRunning(false);
335bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch}
336bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
337bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace test
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
340