OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/test/views_test_base.h" | 5 #include "ui/views/test/views_test_base.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "ui/base/clipboard/clipboard.h" | 8 #include "ui/base/clipboard/clipboard.h" |
9 #include "ui/base/ime/input_method_initializer.h" | 9 #include "ui/base/ime/input_method_initializer.h" |
10 | |
11 #if defined(USE_AURA) | |
12 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
13 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/aura_test_helper.h" | 12 #include "ui/aura/test/aura_test_helper.h" |
15 #include "ui/views/corewm/capture_controller.h" | 13 #include "ui/views/corewm/capture_controller.h" |
16 #include "ui/views/corewm/wm_state.h" | 14 #include "ui/views/corewm/wm_state.h" |
17 #endif | |
18 | 15 |
19 namespace views { | 16 namespace views { |
20 | 17 |
21 ViewsTestBase::ViewsTestBase() | 18 ViewsTestBase::ViewsTestBase() |
22 : setup_called_(false), | 19 : setup_called_(false), |
23 teardown_called_(false) { | 20 teardown_called_(false) { |
24 } | 21 } |
25 | 22 |
26 ViewsTestBase::~ViewsTestBase() { | 23 ViewsTestBase::~ViewsTestBase() { |
27 CHECK(setup_called_) | 24 CHECK(setup_called_) |
28 << "You have overridden SetUp but never called super class's SetUp"; | 25 << "You have overridden SetUp but never called super class's SetUp"; |
29 CHECK(teardown_called_) | 26 CHECK(teardown_called_) |
30 << "You have overrideen TearDown but never called super class's TearDown"; | 27 << "You have overrideen TearDown but never called super class's TearDown"; |
31 } | 28 } |
32 | 29 |
33 void ViewsTestBase::SetUp() { | 30 void ViewsTestBase::SetUp() { |
34 testing::Test::SetUp(); | 31 testing::Test::SetUp(); |
35 setup_called_ = true; | 32 setup_called_ = true; |
36 if (!views_delegate_.get()) | 33 if (!views_delegate_.get()) |
37 views_delegate_.reset(new TestViewsDelegate()); | 34 views_delegate_.reset(new TestViewsDelegate()); |
38 #if defined(USE_AURA) | |
39 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 35 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
40 bool allow_test_contexts = true; | 36 bool allow_test_contexts = true; |
41 aura_test_helper_->SetUp(allow_test_contexts); | 37 aura_test_helper_->SetUp(allow_test_contexts); |
42 wm_state_.reset(new views::corewm::WMState); | 38 wm_state_.reset(new views::corewm::WMState); |
43 #endif // USE_AURA | |
44 ui::InitializeInputMethodForTesting(); | 39 ui::InitializeInputMethodForTesting(); |
45 } | 40 } |
46 | 41 |
47 void ViewsTestBase::TearDown() { | 42 void ViewsTestBase::TearDown() { |
48 ui::Clipboard::DestroyClipboardForCurrentThread(); | 43 ui::Clipboard::DestroyClipboardForCurrentThread(); |
49 | 44 |
50 // Flush the message loop because we have pending release tasks | 45 // Flush the message loop because we have pending release tasks |
51 // and these tasks if un-executed would upset Valgrind. | 46 // and these tasks if un-executed would upset Valgrind. |
52 RunPendingMessages(); | 47 RunPendingMessages(); |
53 teardown_called_ = true; | 48 teardown_called_ = true; |
54 views_delegate_.reset(); | 49 views_delegate_.reset(); |
55 testing::Test::TearDown(); | 50 testing::Test::TearDown(); |
56 ui::ShutdownInputMethodForTesting(); | 51 ui::ShutdownInputMethodForTesting(); |
57 #if defined(USE_AURA) | |
58 aura_test_helper_->TearDown(); | 52 aura_test_helper_->TearDown(); |
59 wm_state_.reset(); | 53 wm_state_.reset(); |
60 CHECK(!corewm::ScopedCaptureClient::IsActive()); | 54 CHECK(!corewm::ScopedCaptureClient::IsActive()); |
61 #endif // USE_AURA | |
62 } | 55 } |
63 | 56 |
64 void ViewsTestBase::RunPendingMessages() { | 57 void ViewsTestBase::RunPendingMessages() { |
65 base::RunLoop run_loop; | 58 base::RunLoop run_loop; |
66 #if defined(USE_AURA) | |
67 run_loop.set_dispatcher(aura::Env::GetInstance()->GetDispatcher()); | |
68 #endif | |
69 run_loop.RunUntilIdle(); | 59 run_loop.RunUntilIdle(); |
70 } | 60 } |
71 | 61 |
72 Widget::InitParams ViewsTestBase::CreateParams( | 62 Widget::InitParams ViewsTestBase::CreateParams( |
73 Widget::InitParams::Type type) { | 63 Widget::InitParams::Type type) { |
74 Widget::InitParams params(type); | 64 Widget::InitParams params(type); |
75 #if defined(USE_AURA) | |
76 params.context = aura_test_helper_->root_window(); | 65 params.context = aura_test_helper_->root_window(); |
77 #endif | |
78 return params; | 66 return params; |
79 } | 67 } |
80 | 68 |
81 gfx::NativeView ViewsTestBase::GetContext() { | 69 gfx::NativeView ViewsTestBase::GetContext() { |
82 #if defined(USE_AURA) | |
83 return aura_test_helper_->root_window(); | 70 return aura_test_helper_->root_window(); |
84 #else | |
85 return NULL; | |
86 #endif | |
87 } | 71 } |
88 | 72 |
89 } // namespace views | 73 } // namespace views |
OLD | NEW |