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