1 // Copyright 2014 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.
5 #include "athena/test/athena_test_helper.h"
7 #include "athena/env/public/athena_env.h"
8 #include "athena/extensions/public/extensions_delegate.h"
9 #include "athena/main/athena_launcher.h"
10 #include "athena/test/sample_activity_factory.h"
11 #include "athena/test/test_app_model_builder.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/threading/thread.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "ui/aura/env.h"
17 #include "ui/aura/input_state_lookup.h"
18 #include "ui/aura/test/env_test_helper.h"
19 #include "ui/base/ime/input_method_initializer.h"
20 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
21 #include "ui/wm/core/focus_controller.h"
22 #include "ui/wm/core/input_method_event_filter.h"
25 #include "ui/base/x/x11_util.h"
31 AthenaTestHelper::AthenaTestHelper(base::MessageLoopForUI
* message_loop
)
32 : setup_called_(false), teardown_called_(false) {
34 message_loop_
= message_loop
;
35 // Disable animations during tests.
36 zero_duration_mode_
.reset(new ui::ScopedAnimationDurationScaleMode(
37 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION
));
40 AthenaTestHelper::~AthenaTestHelper() {
41 CHECK(setup_called_
) << "AthenaTestHelper::SetUp() never called.";
42 CHECK(teardown_called_
) << "AthenaTestHelper::TearDown() never called.";
45 void AthenaTestHelper::SetUp(ui::ContextFactory
* context_factory
) {
47 file_thread_
.reset(new base::Thread("FileThread"));
48 base::Thread::Options
options(base::MessageLoop::TYPE_IO
, 0);
49 file_thread_
->StartWithOptions(options
);
51 chromeos::DBusThreadManager::Initialize();
52 ui::InitializeInputMethodForTesting();
53 aura::Env::CreateInstance(true);
54 aura::Env::GetInstance()->set_context_factory(context_factory
);
56 // Unit tests generally don't want to query the system, rather use the state
58 aura::test::EnvTestHelper(aura::Env::GetInstance())
59 .SetInputStateLookup(scoped_ptr
<aura::InputStateLookup
>());
61 athena::StartAthenaEnv(file_thread_
->message_loop_proxy());
62 athena::ExtensionsDelegate::CreateExtensionsDelegateForTest();
63 athena::StartAthenaSession(new SampleActivityFactory(),
64 new TestAppModelBuilder());
67 void AthenaTestHelper::TearDown() {
68 teardown_called_
= true;
70 athena::ShutdownAthena();
71 aura::Env::DeleteInstance();
74 ui::test::ResetXCursorCache();
77 ui::ShutdownInputMethodForTesting();
78 chromeos::DBusThreadManager::Shutdown();
81 aura::Window
* AthenaTestHelper::GetRootWindow() {
82 return GetHost()->window();
85 aura::WindowTreeHost
* AthenaTestHelper::GetHost() {
86 return AthenaEnv::Get()->GetHost();
89 void AthenaTestHelper::RunAllPendingInMessageLoop() {
90 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
91 // use run_loop.QuitClosure().
92 base::RunLoop run_loop
;
93 run_loop
.RunUntilIdle();