OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/test/ash_test_helper.h" | 5 #include "ash/test/ash_test_helper.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/test/display_manager_test_api.h" | 9 #include "ash/test/display_manager_test_api.h" |
10 #include "ash/test/shell_test_api.h" | 10 #include "ash/test/shell_test_api.h" |
11 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/base/ime/text_input_test_support.h" | 14 #include "ui/base/ime/text_input_test_support.h" |
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
16 | |
17 #if defined(ENABLE_MESSAGE_CENTER) | |
18 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
19 #endif | |
20 | 17 |
21 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
22 #include "chromeos/audio/cras_audio_handler.h" | 19 #include "chromeos/audio/cras_audio_handler.h" |
23 #endif | 20 #endif |
24 | 21 |
25 namespace ash { | 22 namespace ash { |
26 namespace test { | 23 namespace test { |
27 | 24 |
28 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) | 25 AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop) |
29 : message_loop_(message_loop), | 26 : message_loop_(message_loop), |
30 test_shell_delegate_(NULL) { | 27 test_shell_delegate_(NULL) { |
31 CHECK(message_loop_); | 28 CHECK(message_loop_); |
32 } | 29 } |
33 | 30 |
34 AshTestHelper::~AshTestHelper() { | 31 AshTestHelper::~AshTestHelper() { |
35 } | 32 } |
36 | 33 |
37 void AshTestHelper::SetUp() { | 34 void AshTestHelper::SetUp() { |
38 // Disable animations during tests. | 35 // Disable animations during tests. |
39 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( | 36 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
40 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 37 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); |
41 ui::TextInputTestSupport::Initialize(); | 38 ui::TextInputTestSupport::Initialize(); |
42 | 39 |
43 // Creates Shell and hook with Desktop. | 40 // Creates Shell and hook with Desktop. |
44 test_shell_delegate_ = new TestShellDelegate; | 41 test_shell_delegate_ = new TestShellDelegate; |
45 | 42 |
46 #if defined(ENABLE_MESSAGE_CENTER) | |
47 // Creates MessageCenter since g_browser_process is not created in AshTestBase | 43 // Creates MessageCenter since g_browser_process is not created in AshTestBase |
48 // tests. | 44 // tests. |
49 message_center::MessageCenter::Initialize(); | 45 message_center::MessageCenter::Initialize(); |
50 #endif | |
51 | 46 |
52 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
53 if (ash::switches::UseNewAudioHandler()) { | 48 if (ash::switches::UseNewAudioHandler()) { |
54 // Create CrasAuidoHandler for testing since g_browser_process is not | 49 // Create CrasAuidoHandler for testing since g_browser_process is not |
55 // created in AshTestBase tests. | 50 // created in AshTestBase tests. |
56 chromeos::CrasAudioHandler::InitializeForTesting(); | 51 chromeos::CrasAudioHandler::InitializeForTesting(); |
57 } | 52 } |
58 #endif | 53 #endif |
59 | 54 |
60 ash::Shell::CreateInstance(test_shell_delegate_); | 55 ash::Shell::CreateInstance(test_shell_delegate_); |
61 Shell* shell = Shell::GetInstance(); | 56 Shell* shell = Shell::GetInstance(); |
62 test::DisplayManagerTestApi(shell->display_manager()). | 57 test::DisplayManagerTestApi(shell->display_manager()). |
63 DisableChangeDisplayUponHostResize(); | 58 DisableChangeDisplayUponHostResize(); |
64 ShellTestApi(shell).DisableOutputConfiguratorAnimation(); | 59 ShellTestApi(shell).DisableOutputConfiguratorAnimation(); |
65 | 60 |
66 } | 61 } |
67 | 62 |
68 void AshTestHelper::TearDown() { | 63 void AshTestHelper::TearDown() { |
69 // Tear down the shell. | 64 // Tear down the shell. |
70 Shell::DeleteInstance(); | 65 Shell::DeleteInstance(); |
71 | 66 |
72 #if defined(ENABLE_MESSAGE_CENTER) | |
73 // Remove global message center state. | 67 // Remove global message center state. |
74 message_center::MessageCenter::Shutdown(); | 68 message_center::MessageCenter::Shutdown(); |
75 #endif | |
76 | 69 |
77 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
78 if (ash::switches::UseNewAudioHandler()) | 71 if (ash::switches::UseNewAudioHandler()) |
79 chromeos::CrasAudioHandler::Shutdown(); | 72 chromeos::CrasAudioHandler::Shutdown(); |
80 #endif | 73 #endif |
81 | 74 |
82 aura::Env::DeleteInstance(); | 75 aura::Env::DeleteInstance(); |
83 ui::TextInputTestSupport::Shutdown(); | 76 ui::TextInputTestSupport::Shutdown(); |
84 | 77 |
85 zero_duration_mode_.reset(); | 78 zero_duration_mode_.reset(); |
(...skipping 10 matching lines...) Expand all Loading... |
96 aura::RootWindow* AshTestHelper::CurrentContext() { | 89 aura::RootWindow* AshTestHelper::CurrentContext() { |
97 aura::RootWindow* root_window = Shell::GetActiveRootWindow(); | 90 aura::RootWindow* root_window = Shell::GetActiveRootWindow(); |
98 if (!root_window) | 91 if (!root_window) |
99 root_window = Shell::GetPrimaryRootWindow(); | 92 root_window = Shell::GetPrimaryRootWindow(); |
100 DCHECK(root_window); | 93 DCHECK(root_window); |
101 return root_window; | 94 return root_window; |
102 } | 95 } |
103 | 96 |
104 } // namespace test | 97 } // namespace test |
105 } // namespace ash | 98 } // namespace ash |
OLD | NEW |