ash_test_base.cc revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.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"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/coordinate_conversion.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/web_contents_tester.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/aura_constants.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/screen_position_client.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/test/event_generator.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"
287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/ime/input_method_initializer.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/point.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/test/test_metro_viewer_process_host.h"
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/test/test_process_killer_win.h"
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/win/metro.h"
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/win/windows_version.h"
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/remote_root_window_host_win.h"
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/root_window_host_win.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "win8/test/test_registrar_constants.h"
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test {
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AshEventGeneratorDelegate : public aura::test::EventGeneratorDelegate {
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AshEventGeneratorDelegate() {}
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~AshEventGeneratorDelegate() {}
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // aura::test::EventGeneratorDelegate overrides:
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual aura::RootWindow* GetRootWindowAt(
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Point& point_in_screen) const OVERRIDE {
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Screen* screen = Shell::GetScreen();
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen);
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return Shell::GetInstance()->display_controller()->
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        GetRootWindowForDisplayId(display.id());
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual aura::client::ScreenPositionClient* GetScreenPositionClient(
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const aura::Window* window) const OVERRIDE {
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return aura::client::GetScreenPositionClient(window->GetRootWindow());
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AshEventGeneratorDelegate);
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)content::WebContents* AshTestViewsDelegate::CreateWebContents(
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::BrowserContext* browser_context,
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    content::SiteInstance* site_instance) {
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return content::WebContentsTester::CreateTestWebContents(browser_context,
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                           site_instance);
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/////////////////////////////////////////////////////////////////////////////
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AshTestBase::AshTestBase()
82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : setup_called_(false),
83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      teardown_called_(false) {
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Must initialize |ash_test_helper_| here because some tests rely on
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // AshTestBase methods before they call AshTestBase::SetUp().
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_.reset(new AshTestHelper(&message_loop_));
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AshTestBase::~AshTestBase() {
90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CHECK(setup_called_)
91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      << "You have overridden SetUp but never called AshTestBase::SetUp";
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CHECK(teardown_called_)
93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      << "You have overridden TearDown but never called AshTestBase::TearDown";
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::SetUp() {
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  setup_called_ = true;
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(jamescook): Can we do this without changing command line?
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Use the origin (1,1) so that it doesn't over
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // lap with the native mouse cursor.
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      switches::kAshHostWindowBounds, "1+1-800x600");
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::test::SetUsePopupAsRootWindowForTest(true);
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ui::InitializeInputMethodForTesting();
107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->SetUp();
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Shell::GetPrimaryRootWindow()->Show();
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetPrimaryRootWindow()->ShowRootWindow();
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Move the mouse cursor to far away so that native events doesn't
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // interfere test expectations.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Shell::GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(-1000, -1000));
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash::Shell::GetInstance()->cursor_manager()->EnableMouseEvents();
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      !CommandLine::ForCurrentProcess()->HasSwitch(
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          ash::switches::kForceAshToDesktop)) {
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    ipc_thread_.reset(new base::Thread("test_metro_viewer_ipc_thread"));
12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    base::Thread::Options options;
12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    options.message_loop_type = base::MessageLoop::TYPE_IO;
12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    ipc_thread_->StartWithOptions(options);
12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    metro_viewer_host_.reset(
12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        new TestMetroViewerProcessHost("viewer",
12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                       ipc_thread_->message_loop_proxy()));
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    CHECK(metro_viewer_host_->LaunchViewerAndWaitForConnection(
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        win8::test::kDefaultTestAppUserModelId));
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::RemoteRootWindowHostWin* root_window_host =
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        aura::RemoteRootWindowHostWin::Instance();
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    CHECK(root_window_host != NULL);
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::TearDown() {
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  teardown_called_ = true;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flush the message loop to finish pending release tasks.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      !CommandLine::ForCurrentProcess()->HasSwitch(
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          ash::switches::kForceAshToDesktop)) {
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Check that our viewer connection is still established.
148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    CHECK(!metro_viewer_host_->closed_unexpectedly());
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->TearDown();
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ui::ShutdownInputMethodForTesting();
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::test::SetUsePopupAsRootWindowForTest(false);
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Kill the viewer process if we spun one up.
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  metro_viewer_host_.reset();
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Clean up any dangling viewer processes as the metro APIs sometimes leave
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // zombies behind. A default browser process in metro will have the
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // following command line arg so use that to avoid killing all processes named
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // win8::test::kDefaultTestExePath.
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const wchar_t kViewerProcessArgument[] = L"DefaultBrowserServer";
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::KillAllNamedProcessesWithArgument(win8::test::kDefaultTestExePath,
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          kViewerProcessArgument);
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  event_generator_.reset();
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Some tests set an internal display id,
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // reset it here, so other tests will continue in a clean environment.
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::test::EventGenerator& AshTestBase::GetEventGenerator() {
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!event_generator_) {
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event_generator_.reset(
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        new aura::test::EventGenerator(new AshEventGeneratorDelegate()));
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return *event_generator_.get();
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static
1847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool AshTestBase::SupportsMultipleDisplays() {
1857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(OS_WIN)
1867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return base::win::GetVersion() < base::win::VERSION_WIN8;
1877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#else
1887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return true;
1897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif
1907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
1917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::UpdateDisplay(const std::string& display_specs) {
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayManagerTestApi display_manager_test_api(
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Shell::GetInstance()->display_manager());
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager_test_api.UpdateDisplay(display_specs);
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::RootWindow* AshTestBase::CurrentContext() {
199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return ash_test_helper_->CurrentContext();
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithId(int id) {
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(NULL, id, gfx::Rect());
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithBounds(
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(NULL, 0, bounds);
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShell(SkColor color,
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   int id,
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                   const gfx::Rect& bounds) {
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegate(
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      new aura::test::ColorTestWindowDelegate(color), id, bounds);
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegate(
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::WindowDelegate* delegate,
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int id,
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return CreateTestWindowInShellWithDelegateAndType(
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      delegate,
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      aura::client::WINDOW_TYPE_NORMAL,
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      id,
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bounds);
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* AshTestBase::CreateTestWindowInShellWithDelegateAndType(
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::WindowDelegate* delegate,
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::client::WindowType type,
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int id,
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Rect& bounds) {
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  aura::Window* window = new aura::Window(delegate);
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->set_id(id);
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetType(type);
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->Init(ui::LAYER_TEXTURED);
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->Show();
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (bounds.IsEmpty()) {
2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    SetDefaultParentByPrimaryRootWindow(window);
2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Display display =
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ash::Shell::GetInstance()->display_manager()->GetDisplayMatching(bounds);
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::RootWindow* root = ash::Shell::GetInstance()->display_controller()->
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        GetRootWindowForDisplayId(display.id());
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Point origin = bounds.origin();
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    wm::ConvertPointFromScreen(root, &origin);
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    window->SetBounds(gfx::Rect(origin, bounds.size()));
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    window->SetDefaultParentByRootWindow(root, bounds);
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetProperty(aura::client::kCanMaximizeKey, true);
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return window;
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetDefaultParentByPrimaryRootWindow(aura::Window* window) {
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  window->SetDefaultParentByRootWindow(
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Shell::GetPrimaryRootWindow(), gfx::Rect());
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AshTestBase::RunAllPendingInMessageLoop() {
262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->RunAllPendingInMessageLoop();
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetSessionStarted(bool session_started) {
266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
267c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetActiveUserSessionStarted(session_started);
2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetUserLoggedIn(bool user_logged_in) {
271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetHasActiveUser(user_logged_in);
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void AshTestBase::SetCanLockScreen(bool can_lock_screen) {
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ash_test_helper_->test_shell_delegate()->test_session_state_delegate()->
277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetCanLockScreen(can_lock_screen);
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace test
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
282