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

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

Issue 301593004: Athena unittests framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix deps Created 6 years, 6 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 (c) 2012 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 "ui/aura/test/aura_test_helper.h" 5 #include "athena/test/athena_test_helper.h"
6 6
7 #include "athena/main/athena_launcher.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/default_capture_client.h"
11 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
13 #include "ui/aura/input_state_lookup.h" 12 #include "ui/aura/input_state_lookup.h"
14 #include "ui/aura/test/env_test_helper.h" 13 #include "ui/aura/test/env_test_helper.h"
15 #include "ui/aura/test/test_focus_client.h" 14 #include "ui/aura/test/test_focus_client.h"
16 #include "ui/aura/test/test_screen.h" 15 #include "ui/aura/test/test_screen.h"
17 #include "ui/aura/test/test_window_tree_client.h"
18 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
19 #include "ui/base/ime/dummy_input_method.h"
20 #include "ui/base/ime/input_method_initializer.h" 17 #include "ui/base/ime/input_method_initializer.h"
21 #include "ui/compositor/compositor.h"
22 #include "ui/compositor/layer_animator.h"
23 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
24 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 #include "ui/wm/core/default_activation_client.h"
21 #include "ui/wm/core/input_method_event_filter.h"
25 22
26 #if defined(USE_X11) 23 #if defined(USE_X11)
27 #include "ui/aura/window_tree_host_x11.h" 24 #include "ui/aura/window_tree_host_x11.h"
28 #include "ui/base/x/x11_util.h" 25 #include "ui/base/x/x11_util.h"
29 #endif 26 #endif
30 27
31 namespace aura { 28 namespace athena {
32 namespace test { 29 namespace test {
33 30
34 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop) 31 AthenaTestHelper::AthenaTestHelper(base::MessageLoopForUI* message_loop)
35 : setup_called_(false), 32 : setup_called_(false), teardown_called_(false) {
36 teardown_called_(false),
37 owns_host_(false) {
38 DCHECK(message_loop); 33 DCHECK(message_loop);
39 message_loop_ = message_loop; 34 message_loop_ = message_loop;
40 // Disable animations during tests. 35 // Disable animations during tests.
41 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 36 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
42 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 37 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
43 #if defined(USE_X11) 38 #if defined(USE_X11)
44 test::SetUseOverrideRedirectWindowByDefault(true); 39 aura::test::SetUseOverrideRedirectWindowByDefault(true);
45 #endif 40 #endif
46 } 41 }
47 42
48 AuraTestHelper::~AuraTestHelper() { 43 AthenaTestHelper::~AthenaTestHelper() {
49 CHECK(setup_called_) 44 CHECK(setup_called_) << "AthenaTestHelper::SetUp() never called.";
50 << "AuraTestHelper::SetUp() never called."; 45 CHECK(teardown_called_) << "AthenaTestHelper::TearDown() never called.";
51 CHECK(teardown_called_)
52 << "AuraTestHelper::TearDown() never called.";
53 } 46 }
54 47
55 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { 48 void AthenaTestHelper::SetUp(ui::ContextFactory* context_factory) {
56 setup_called_ = true; 49 setup_called_ = true;
57 50
58 Env::CreateInstance(true); 51 aura::Env::CreateInstance(true);
59 Env::GetInstance()->set_context_factory(context_factory); 52 aura::Env::GetInstance()->set_context_factory(context_factory);
53
60 // Unit tests generally don't want to query the system, rather use the state 54 // Unit tests generally don't want to query the system, rather use the state
61 // from RootWindow. 55 // from RootWindow.
62 EnvTestHelper(Env::GetInstance()).SetInputStateLookup( 56 aura::test::EnvTestHelper(aura::Env::GetInstance())
63 scoped_ptr<InputStateLookup>()); 57 .SetInputStateLookup(scoped_ptr<aura::InputStateLookup>());
64 58
65 ui::InitializeInputMethodForTesting(); 59 ui::InitializeInputMethodForTesting();
66 60
67 test_screen_.reset(TestScreen::Create()); 61 test_screen_.reset(aura::TestScreen::Create());
68 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); 62 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
69 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); 63 host_.reset(test_screen_->CreateHostForPrimaryDisplay());
70 64
71 focus_client_.reset(new TestFocusClient); 65 input_method_filter_.reset(new ::wm::InputMethodEventFilter(
72 client::SetFocusClient(root_window(), focus_client_.get()); 66 root_window()->GetHost()->GetAcceleratedWidget()));
73 stacking_client_.reset(new TestWindowTreeClient(root_window())); 67 input_method_filter_->SetInputMethodPropertyInRootWindow(
74 capture_client_.reset(new client::DefaultCaptureClient(root_window())); 68 root_window());
75 test_input_method_.reset(new ui::DummyInputMethod); 69
76 root_window()->SetProperty( 70 // TODO(oshima): Switch to athena implementation.
77 client::kRootWindowInputMethodKey, 71 focus_client_.reset(new aura::test::TestFocusClient);
78 test_input_method_.get()); 72 aura::client::SetFocusClient(root_window(),
73 focus_client_.get());
74 new ::wm::DefaultActivationClient(root_window());
79 75
80 root_window()->Show(); 76 root_window()->Show();
81 // Ensure width != height so tests won't confuse them. 77 // Ensure width != height so tests won't confuse them.
82 host()->SetBounds(gfx::Rect(800, 600)); 78 host()->SetBounds(gfx::Rect(800, 600));
79
80 athena::StartAthena(root_window());
83 } 81 }
84 82
85 void AuraTestHelper::TearDown() { 83 void AthenaTestHelper::TearDown() {
86 teardown_called_ = true; 84 teardown_called_ = true;
87 test_input_method_.reset(); 85
88 stacking_client_.reset(); 86 aura::client::SetFocusClient(root_window(), NULL);
89 capture_client_.reset();
90 focus_client_.reset(); 87 focus_client_.reset();
91 client::SetFocusClient(root_window(), NULL); 88 input_method_filter_.reset();
89
90 athena::ShutdownAthena();
92 host_.reset(); 91 host_.reset();
93 ui::GestureRecognizer::Reset(); 92 ui::GestureRecognizer::Reset();
94 test_screen_.reset(); 93 test_screen_.reset();
95 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); 94 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
96 95
97 #if defined(USE_X11) 96 #if defined(USE_X11)
98 ui::test::ResetXCursorCache(); 97 ui::test::ResetXCursorCache();
99 #endif 98 #endif
100 99
101 ui::ShutdownInputMethodForTesting(); 100 ui::ShutdownInputMethodForTesting();
102 101
103 Env::DeleteInstance(); 102 aura::Env::DeleteInstance();
104 } 103 }
105 104
106 void AuraTestHelper::RunAllPendingInMessageLoop() { 105 void AthenaTestHelper::RunAllPendingInMessageLoop() {
107 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them 106 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
108 // use run_loop.QuitClosure(). 107 // use run_loop.QuitClosure().
109 base::RunLoop run_loop; 108 base::RunLoop run_loop;
110 run_loop.RunUntilIdle(); 109 run_loop.RunUntilIdle();
111 } 110 }
112 111
113 } // namespace test 112 } // namespace test
114 } // namespace aura 113 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698