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 | 10 |
11 #if defined(USE_AURA) | 11 #if defined(USE_AURA) |
12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/aura_test_helper.h" | 14 #include "ui/aura/test/aura_test_helper.h" |
15 #include "ui/views/corewm/capture_controller.h" | 15 #include "ui/views/corewm/capture_controller.h" |
16 #include "ui/views/corewm/transient_window_stacking_client.h" | 16 #include "ui/views/corewm/wm_state.h" |
17 #endif | 17 #endif |
18 | 18 |
19 namespace views { | 19 namespace views { |
20 | 20 |
21 ViewsTestBase::ViewsTestBase() | 21 ViewsTestBase::ViewsTestBase() |
22 : setup_called_(false), | 22 : setup_called_(false), |
23 teardown_called_(false) { | 23 teardown_called_(false) { |
24 } | 24 } |
25 | 25 |
26 ViewsTestBase::~ViewsTestBase() { | 26 ViewsTestBase::~ViewsTestBase() { |
27 CHECK(setup_called_) | 27 CHECK(setup_called_) |
28 << "You have overridden SetUp but never called super class's SetUp"; | 28 << "You have overridden SetUp but never called super class's SetUp"; |
29 CHECK(teardown_called_) | 29 CHECK(teardown_called_) |
30 << "You have overrideen TearDown but never called super class's TearDown"; | 30 << "You have overrideen TearDown but never called super class's TearDown"; |
31 } | 31 } |
32 | 32 |
33 void ViewsTestBase::SetUp() { | 33 void ViewsTestBase::SetUp() { |
34 testing::Test::SetUp(); | 34 testing::Test::SetUp(); |
35 setup_called_ = true; | 35 setup_called_ = true; |
36 if (!views_delegate_.get()) | 36 if (!views_delegate_.get()) |
37 views_delegate_.reset(new TestViewsDelegate()); | 37 views_delegate_.reset(new TestViewsDelegate()); |
38 #if defined(USE_AURA) | 38 #if defined(USE_AURA) |
39 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 39 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
40 aura_test_helper_->SetUp(); | 40 aura_test_helper_->SetUp(); |
41 // SetWindowStackingClient() takes ownership of TransientWindowStackingClient. | 41 wm_state_.reset(new views::corewm::WMState); |
42 aura::client::SetWindowStackingClient( | |
43 new corewm::TransientWindowStackingClient); | |
44 #endif // USE_AURA | 42 #endif // USE_AURA |
45 ui::InitializeInputMethodForTesting(); | 43 ui::InitializeInputMethodForTesting(); |
46 } | 44 } |
47 | 45 |
48 void ViewsTestBase::TearDown() { | 46 void ViewsTestBase::TearDown() { |
49 ui::Clipboard::DestroyClipboardForCurrentThread(); | 47 ui::Clipboard::DestroyClipboardForCurrentThread(); |
50 | 48 |
51 // Flush the message loop because we have pending release tasks | 49 // Flush the message loop because we have pending release tasks |
52 // and these tasks if un-executed would upset Valgrind. | 50 // and these tasks if un-executed would upset Valgrind. |
53 RunPendingMessages(); | 51 RunPendingMessages(); |
54 teardown_called_ = true; | 52 teardown_called_ = true; |
55 views_delegate_.reset(); | 53 views_delegate_.reset(); |
56 testing::Test::TearDown(); | 54 testing::Test::TearDown(); |
57 ui::ShutdownInputMethodForTesting(); | 55 ui::ShutdownInputMethodForTesting(); |
58 #if defined(USE_AURA) | 56 #if defined(USE_AURA) |
59 aura_test_helper_->TearDown(); | 57 aura_test_helper_->TearDown(); |
60 aura::client::SetWindowStackingClient(NULL); | 58 wm_state_.reset(); |
61 CHECK(!corewm::ScopedCaptureClient::IsActive()); | 59 CHECK(!corewm::ScopedCaptureClient::IsActive()); |
62 #endif // USE_AURA | 60 #endif // USE_AURA |
63 } | 61 } |
64 | 62 |
65 void ViewsTestBase::RunPendingMessages() { | 63 void ViewsTestBase::RunPendingMessages() { |
66 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
67 #if defined(USE_AURA) | 65 #if defined(USE_AURA) |
68 run_loop.set_dispatcher(aura::Env::GetInstance()->GetDispatcher()); | 66 run_loop.set_dispatcher(aura::Env::GetInstance()->GetDispatcher()); |
69 #endif | 67 #endif |
70 run_loop.RunUntilIdle(); | 68 run_loop.RunUntilIdle(); |
(...skipping 10 matching lines...) Expand all Loading... |
81 | 79 |
82 gfx::NativeView ViewsTestBase::GetContext() { | 80 gfx::NativeView ViewsTestBase::GetContext() { |
83 #if defined(USE_AURA) | 81 #if defined(USE_AURA) |
84 return aura_test_helper_->root_window(); | 82 return aura_test_helper_->root_window(); |
85 #else | 83 #else |
86 return NULL; | 84 return NULL; |
87 #endif | 85 #endif |
88 } | 86 } |
89 | 87 |
90 } // namespace views | 88 } // namespace views |
OLD | NEW |