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 #include "ui/compositor/test/context_factories_for_test.h" | 10 #include "ui/compositor/test/context_factories_for_test.h" |
11 #include "ui/views/test/views_test_helper.h" | 11 #include "ui/views/test/views_test_helper.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 | 14 |
15 ViewsTestBase::ViewsTestBase() | 15 ViewsTestBase::ViewsTestBase() |
16 : setup_called_(false), | 16 : setup_called_(false), |
17 teardown_called_(false) { | 17 teardown_called_(false) { |
18 } | 18 } |
19 | 19 |
20 ViewsTestBase::~ViewsTestBase() { | 20 ViewsTestBase::~ViewsTestBase() { |
21 CHECK(setup_called_) | 21 CHECK(setup_called_) |
22 << "You have overridden SetUp but never called super class's SetUp"; | 22 << "You have overridden SetUp but never called super class's SetUp"; |
23 CHECK(teardown_called_) | 23 CHECK(teardown_called_) |
24 << "You have overridden TearDown but never called super class's TearDown"; | 24 << "You have overridden TearDown but never called super class's TearDown"; |
25 } | 25 } |
26 | 26 |
27 void ViewsTestBase::SetUp() { | 27 void ViewsTestBase::SetUp() { |
28 testing::Test::SetUp(); | 28 testing::Test::SetUp(); |
29 setup_called_ = true; | 29 setup_called_ = true; |
30 if (!views_delegate_.get()) | 30 if (!views_delegate_) |
31 views_delegate_.reset(new TestViewsDelegate()); | 31 views_delegate_.reset(new TestViewsDelegate()); |
32 | 32 |
33 // The ContextFactory must exist before any Compositors are created. | 33 // The ContextFactory must exist before any Compositors are created. |
34 bool enable_pixel_output = false; | 34 bool enable_pixel_output = false; |
35 ui::ContextFactory* context_factory = | 35 ui::ContextFactory* context_factory = |
36 ui::InitializeContextFactoryForTests(enable_pixel_output); | 36 ui::InitializeContextFactoryForTests(enable_pixel_output); |
37 views_delegate_->set_context_factory(context_factory); | 37 views_delegate_->set_context_factory(context_factory); |
38 | 38 |
39 test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory)); | 39 test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory)); |
40 test_helper_->SetUp(); | 40 test_helper_->SetUp(); |
41 ui::InitializeInputMethodForTesting(); | 41 ui::InitializeInputMethodForTesting(); |
42 } | 42 } |
43 | 43 |
44 void ViewsTestBase::TearDown() { | 44 void ViewsTestBase::TearDown() { |
45 ui::Clipboard::DestroyClipboardForCurrentThread(); | 45 ui::Clipboard::DestroyClipboardForCurrentThread(); |
46 | 46 |
47 // Flush the message loop because we have pending release tasks | 47 // Flush the message loop because we have pending release tasks |
48 // and these tasks if un-executed would upset Valgrind. | 48 // and these tasks if un-executed would upset Valgrind. |
49 RunPendingMessages(); | 49 RunPendingMessages(); |
50 teardown_called_ = true; | 50 teardown_called_ = true; |
51 views_delegate_.reset(); | 51 views_delegate_.reset(); |
52 testing::Test::TearDown(); | 52 testing::Test::TearDown(); |
53 ui::ShutdownInputMethodForTesting(); | 53 ui::ShutdownInputMethodForTesting(); |
54 test_helper_->TearDown(); | 54 test_helper_->TearDown(); |
55 ui::TerminateContextFactoryForTests(); | 55 ui::TerminateContextFactoryForTests(); |
| 56 |
| 57 views_delegate_.reset(); |
56 } | 58 } |
57 | 59 |
58 void ViewsTestBase::RunPendingMessages() { | 60 void ViewsTestBase::RunPendingMessages() { |
59 base::RunLoop run_loop; | 61 base::RunLoop run_loop; |
60 run_loop.RunUntilIdle(); | 62 run_loop.RunUntilIdle(); |
61 } | 63 } |
62 | 64 |
63 Widget::InitParams ViewsTestBase::CreateParams( | 65 Widget::InitParams ViewsTestBase::CreateParams( |
64 Widget::InitParams::Type type) { | 66 Widget::InitParams::Type type) { |
65 Widget::InitParams params(type); | 67 Widget::InitParams params(type); |
66 params.context = GetContext(); | 68 params.context = GetContext(); |
67 return params; | 69 return params; |
68 } | 70 } |
69 | 71 |
70 gfx::NativeWindow ViewsTestBase::GetContext() { | 72 gfx::NativeWindow ViewsTestBase::GetContext() { |
71 return test_helper_->GetContext(); | 73 return test_helper_->GetContext(); |
72 } | 74 } |
73 | 75 |
74 } // namespace views | 76 } // namespace views |
OLD | NEW |