blob: 4c7ac848040e15357eba38dabf68ed1b6df30f06 [file] [log] [blame]
[email protected]09464c72013-04-26 07:31:281// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/test/ash_test_helper.h"
6
7#include "ash/ash_switches.h"
8#include "ash/shell.h"
9#include "ash/test/display_manager_test_api.h"
10#include "ash/test/shell_test_api.h"
11#include "ash/test/test_shell_delegate.h"
[email protected]09464c72013-04-26 07:31:2812#include "base/run_loop.h"
13#include "ui/aura/env.h"
[email protected]09464c72013-04-26 07:31:2814#include "ui/base/ime/text_input_test_support.h"
[email protected]09464c72013-04-26 07:31:2815#include "ui/compositor/scoped_animation_duration_scale_mode.h"
[email protected]09464c72013-04-26 07:31:2816#include "ui/message_center/message_center.h"
[email protected]09464c72013-04-26 07:31:2817
[email protected]6d8c8f02013-05-13 17:33:1218#if defined(OS_CHROMEOS)
19#include "chromeos/audio/cras_audio_handler.h"
[email protected]1d28ca02013-05-16 05:40:3820#include "chromeos/power/power_manager_handler.h"
[email protected]6d8c8f02013-05-13 17:33:1221#endif
22
[email protected]09464c72013-04-26 07:31:2823namespace ash {
24namespace test {
25
26AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
27 : message_loop_(message_loop),
28 test_shell_delegate_(NULL) {
29 CHECK(message_loop_);
30}
31
32AshTestHelper::~AshTestHelper() {
33}
34
35void AshTestHelper::SetUp() {
[email protected]09464c72013-04-26 07:31:2836 // Disable animations during tests.
37 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
38 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
39 ui::TextInputTestSupport::Initialize();
40
41 // Creates Shell and hook with Desktop.
42 test_shell_delegate_ = new TestShellDelegate;
43
[email protected]09464c72013-04-26 07:31:2844 // Creates MessageCenter since g_browser_process is not created in AshTestBase
45 // tests.
46 message_center::MessageCenter::Initialize();
[email protected]6d8c8f02013-05-13 17:33:1247
48#if defined(OS_CHROMEOS)
49 if (ash::switches::UseNewAudioHandler()) {
50 // Create CrasAuidoHandler for testing since g_browser_process is not
51 // created in AshTestBase tests.
52 chromeos::CrasAudioHandler::InitializeForTesting();
53 }
[email protected]1d28ca02013-05-16 05:40:3854 chromeos::PowerManagerHandler::Initialize();
[email protected]6d8c8f02013-05-13 17:33:1255#endif
56
[email protected]09464c72013-04-26 07:31:2857 ash::Shell::CreateInstance(test_shell_delegate_);
58 Shell* shell = Shell::GetInstance();
59 test::DisplayManagerTestApi(shell->display_manager()).
60 DisableChangeDisplayUponHostResize();
[email protected]09464c72013-04-26 07:31:2861 ShellTestApi(shell).DisableOutputConfiguratorAnimation();
62
[email protected]09464c72013-04-26 07:31:2863}
64
65void AshTestHelper::TearDown() {
[email protected]09464c72013-04-26 07:31:2866 // Tear down the shell.
67 Shell::DeleteInstance();
68
[email protected]09464c72013-04-26 07:31:2869 // Remove global message center state.
70 message_center::MessageCenter::Shutdown();
[email protected]09464c72013-04-26 07:31:2871
[email protected]6d8c8f02013-05-13 17:33:1272#if defined(OS_CHROMEOS)
73 if (ash::switches::UseNewAudioHandler())
74 chromeos::CrasAudioHandler::Shutdown();
[email protected]1d28ca02013-05-16 05:40:3875 chromeos::PowerManagerHandler::Shutdown();
[email protected]6d8c8f02013-05-13 17:33:1276#endif
77
[email protected]09464c72013-04-26 07:31:2878 aura::Env::DeleteInstance();
79 ui::TextInputTestSupport::Shutdown();
80
[email protected]09464c72013-04-26 07:31:2881 zero_duration_mode_.reset();
82}
83
84void AshTestHelper::RunAllPendingInMessageLoop() {
85#if !defined(OS_MACOSX)
86 DCHECK(MessageLoopForUI::current() == message_loop_);
87 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
88 run_loop.RunUntilIdle();
89#endif
90}
91
92aura::RootWindow* AshTestHelper::CurrentContext() {
93 aura::RootWindow* root_window = Shell::GetActiveRootWindow();
94 if (!root_window)
95 root_window = Shell::GetPrimaryRootWindow();
96 DCHECK(root_window);
97 return root_window;
98}
99
100} // namespace test
101} // namespace ash