Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: athena/test/athena_test_helper.cc

Issue 480353006: Separate athena's startup process from AppShell's (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reformat Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "athena/test/athena_test_helper.h" 5 #include "athena/test/athena_test_helper.h"
6 6
7 #include "athena/env/public/athena_env.h"
7 #include "athena/extensions/public/extensions_delegate.h" 8 #include "athena/extensions/public/extensions_delegate.h"
8 #include "athena/main/athena_launcher.h" 9 #include "athena/main/athena_launcher.h"
9 #include "athena/screen/public/screen_manager.h"
10 #include "athena/test/sample_activity_factory.h" 10 #include "athena/test/sample_activity_factory.h"
11 #include "athena/test/test_app_model_builder.h" 11 #include "athena/test/test_app_model_builder.h"
12 #include "athena/test/test_screen_manager_delegate.h"
13 #include "base/command_line.h"
14 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 13 #include "base/run_loop.h"
16 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
17 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "ui/app_list/app_list_switches.h"
19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
21 #include "ui/aura/input_state_lookup.h" 17 #include "ui/aura/input_state_lookup.h"
22 #include "ui/aura/test/env_test_helper.h" 18 #include "ui/aura/test/env_test_helper.h"
23 #include "ui/aura/test/test_focus_client.h"
24 #include "ui/aura/test/test_screen.h"
25 #include "ui/aura/window_event_dispatcher.h"
26 #include "ui/base/ime/input_method_initializer.h" 19 #include "ui/base/ime/input_method_initializer.h"
27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 20 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
28 #include "ui/gfx/screen.h"
29 #include "ui/wm/core/focus_controller.h" 21 #include "ui/wm/core/focus_controller.h"
30 #include "ui/wm/core/input_method_event_filter.h" 22 #include "ui/wm/core/input_method_event_filter.h"
31 23
32 #if defined(USE_X11) 24 #if defined(USE_X11)
33 #include "ui/base/x/x11_util.h" 25 #include "ui/base/x/x11_util.h"
34 #endif 26 #endif
35 27
36 namespace athena { 28 namespace athena {
37 namespace test { 29 namespace test {
38 30
(...skipping 10 matching lines...) Expand all
49 CHECK(setup_called_) << "AthenaTestHelper::SetUp() never called."; 41 CHECK(setup_called_) << "AthenaTestHelper::SetUp() never called.";
50 CHECK(teardown_called_) << "AthenaTestHelper::TearDown() never called."; 42 CHECK(teardown_called_) << "AthenaTestHelper::TearDown() never called.";
51 } 43 }
52 44
53 void AthenaTestHelper::SetUp(ui::ContextFactory* context_factory) { 45 void AthenaTestHelper::SetUp(ui::ContextFactory* context_factory) {
54 setup_called_ = true; 46 setup_called_ = true;
55 file_thread_.reset(new base::Thread("FileThread")); 47 file_thread_.reset(new base::Thread("FileThread"));
56 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); 48 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
57 file_thread_->StartWithOptions(options); 49 file_thread_->StartWithOptions(options);
58 50
59 // Force showing in the experimental app-list view.
60 base::CommandLine::ForCurrentProcess()->AppendSwitch(
61 app_list::switches::kEnableExperimentalAppList);
62
63 chromeos::DBusThreadManager::InitializeWithStub(); 51 chromeos::DBusThreadManager::InitializeWithStub();
64 52 ui::InitializeInputMethodForTesting();
65 aura::Env::CreateInstance(true); 53 aura::Env::CreateInstance(true);
66 aura::Env::GetInstance()->set_context_factory(context_factory); 54 aura::Env::GetInstance()->set_context_factory(context_factory);
67 55
68 // Unit tests generally don't want to query the system, rather use the state 56 // Unit tests generally don't want to query the system, rather use the state
69 // from RootWindow. 57 // from RootWindow.
70 aura::test::EnvTestHelper(aura::Env::GetInstance()) 58 aura::test::EnvTestHelper(aura::Env::GetInstance())
71 .SetInputStateLookup(scoped_ptr<aura::InputStateLookup>()); 59 .SetInputStateLookup(scoped_ptr<aura::InputStateLookup>());
72 60
73 ui::InitializeInputMethodForTesting(); 61 athena::StartAthenaEnv(file_thread_->message_loop_proxy());
74
75 const gfx::Size host_size(800, 600);
76 test_screen_.reset(aura::TestScreen::Create(host_size));
77 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
78 host_.reset(test_screen_->CreateHostForPrimaryDisplay());
79 screen_manager_delegate_.reset(
80 new TestScreenManagerDelegate(test_screen_.get()));
81
82 input_method_filter_.reset(new ::wm::InputMethodEventFilter(
83 root_window()->GetHost()->GetAcceleratedWidget()));
84 input_method_filter_->SetInputMethodPropertyInRootWindow(
85 root_window());
86
87 wm::FocusController* focus_controller =
88 new wm::FocusController(ScreenManager::CreateFocusRules());
89 aura::client::SetFocusClient(root_window(), focus_controller);
90 root_window()->AddPreTargetHandler(focus_controller);
91 aura::client::SetActivationClient(root_window(), focus_controller);
92 focus_client_.reset(focus_controller);
93
94 root_window()->Show();
95 // Ensure width != height so tests won't confuse them.
96 host()->SetBounds(gfx::Rect(host_size));
97
98 athena::StartAthenaEnv(root_window(), screen_manager_delegate_.get(),
99 file_thread_->message_loop_proxy());
100 athena::ExtensionsDelegate::CreateExtensionsDelegateForTest(); 62 athena::ExtensionsDelegate::CreateExtensionsDelegateForTest();
101 athena::StartAthenaSession(new SampleActivityFactory(), 63 athena::StartAthenaSession(new SampleActivityFactory(),
102 new TestAppModelBuilder()); 64 new TestAppModelBuilder());
103 } 65 }
104 66
105 void AthenaTestHelper::TearDown() { 67 void AthenaTestHelper::TearDown() {
106 teardown_called_ = true; 68 teardown_called_ = true;
107 69
108 athena::ShutdownAthena(); 70 athena::ShutdownAthena();
109 71 aura::Env::DeleteInstance();
110 aura::client::SetFocusClient(root_window(), NULL);
111 focus_client_.reset();
112 input_method_filter_.reset();
113
114 host_.reset();
115 ui::GestureRecognizer::Reset();
116 test_screen_.reset();
117 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
118 72
119 #if defined(USE_X11) 73 #if defined(USE_X11)
120 ui::test::ResetXCursorCache(); 74 ui::test::ResetXCursorCache();
121 #endif 75 #endif
122 76
123 ui::ShutdownInputMethodForTesting(); 77 ui::ShutdownInputMethodForTesting();
78 chromeos::DBusThreadManager::Shutdown();
79 }
124 80
125 chromeos::DBusThreadManager::Shutdown(); 81 aura::Window* AthenaTestHelper::GetRootWindow() {
82 return GetHost()->window();
83 }
126 84
127 aura::Env::DeleteInstance(); 85 aura::WindowTreeHost* AthenaTestHelper::GetHost() {
86 return AthenaEnv::Get()->GetHost();
128 } 87 }
129 88
130 void AthenaTestHelper::RunAllPendingInMessageLoop() { 89 void AthenaTestHelper::RunAllPendingInMessageLoop() {
131 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them 90 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
132 // use run_loop.QuitClosure(). 91 // use run_loop.QuitClosure().
133 base::RunLoop run_loop; 92 base::RunLoop run_loop;
134 run_loop.RunUntilIdle(); 93 run_loop.RunUntilIdle();
135 } 94 }
136 95
137 } // namespace test 96 } // namespace test
138 } // namespace athena 97 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698