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