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