| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/scoped_views_test_helper.h" | 5 #include "ui/views/test/scoped_views_test_helper.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "ui/base/clipboard/clipboard.h" | 10 #include "ui/base/clipboard/clipboard.h" |
| 12 #include "ui/base/ime/input_method_initializer.h" | 11 #include "ui/base/ime/input_method_initializer.h" |
| 13 #include "ui/base/test/test_clipboard.h" | 12 #include "ui/base/test/test_clipboard.h" |
| 14 #include "ui/views/test/platform_test_helper.h" | 13 #include "ui/views/test/platform_test_helper.h" |
| 15 #include "ui/views/test/test_views_delegate.h" | 14 #include "ui/views/test/test_views_delegate.h" |
| 16 #include "ui/views/test/views_test_helper.h" | 15 #include "ui/views/test/views_test_helper.h" |
| 17 | 16 |
| 18 namespace views { | 17 namespace views { |
| 19 | 18 |
| 20 ScopedViewsTestHelper::ScopedViewsTestHelper() | 19 ScopedViewsTestHelper::ScopedViewsTestHelper() |
| 21 : ScopedViewsTestHelper(base::WrapUnique(new TestViewsDelegate)) {} | 20 : ScopedViewsTestHelper(base::WrapUnique(new TestViewsDelegate)) {} |
| 22 | 21 |
| 23 ScopedViewsTestHelper::ScopedViewsTestHelper( | 22 ScopedViewsTestHelper::ScopedViewsTestHelper( |
| 24 std::unique_ptr<TestViewsDelegate> views_delegate) | 23 std::unique_ptr<TestViewsDelegate> views_delegate) |
| 25 : test_views_delegate_(std::move(views_delegate)), | 24 : test_views_delegate_(std::move(views_delegate)), |
| 26 platform_test_helper_(PlatformTestHelper::Create()) { | 25 platform_test_helper_(PlatformTestHelper::Create()) { |
| 27 // The ContextFactory must exist before any Compositors are created. | 26 // The ContextFactory must exist before any Compositors are created. |
| 28 ui::ContextFactory* context_factory = nullptr; | 27 ui::ContextFactory* context_factory = nullptr; |
| 29 ui::ContextFactoryPrivate* context_factory_private = nullptr; | 28 ui::ContextFactoryPrivate* context_factory_private = nullptr; |
| 30 platform_test_helper_->InitializeContextFactory(&context_factory, | 29 platform_test_helper_->InitializeContextFactory(&context_factory, |
| 31 &context_factory_private); | 30 &context_factory_private); |
| 32 | 31 |
| 33 test_views_delegate_->set_context_factory(context_factory); | 32 test_views_delegate_->set_context_factory(context_factory); |
| 34 test_views_delegate_->set_context_factory_private(context_factory_private); | 33 test_views_delegate_->set_context_factory_private(context_factory_private); |
| 35 | 34 |
| 36 test_helper_.reset(ViewsTestHelper::Create(base::MessageLoopForUI::current(), | 35 test_helper_.reset( |
| 37 context_factory, | 36 ViewsTestHelper::Create(context_factory, context_factory_private)); |
| 38 context_factory_private)); | |
| 39 platform_test_helper_->OnTestHelperCreated(test_helper_.get()); | 37 platform_test_helper_->OnTestHelperCreated(test_helper_.get()); |
| 40 test_helper_->SetUp(); | 38 test_helper_->SetUp(); |
| 41 | 39 |
| 42 ui::InitializeInputMethodForTesting(); | 40 ui::InitializeInputMethodForTesting(); |
| 43 ui::TestClipboard::CreateForCurrentThread(); | 41 ui::TestClipboard::CreateForCurrentThread(); |
| 44 } | 42 } |
| 45 | 43 |
| 46 ScopedViewsTestHelper::~ScopedViewsTestHelper() { | 44 ScopedViewsTestHelper::~ScopedViewsTestHelper() { |
| 47 ui::Clipboard::DestroyClipboardForCurrentThread(); | 45 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 48 ui::ShutdownInputMethodForTesting(); | 46 ui::ShutdownInputMethodForTesting(); |
| 49 test_helper_->TearDown(); | 47 test_helper_->TearDown(); |
| 50 test_helper_.reset(); | 48 test_helper_.reset(); |
| 51 | 49 |
| 52 test_views_delegate_.reset(); | 50 test_views_delegate_.reset(); |
| 53 | 51 |
| 54 // The Mus PlatformTestHelper has state that is deleted by | 52 // The Mus PlatformTestHelper has state that is deleted by |
| 55 // ui::TerminateContextFactoryForTests(). | 53 // ui::TerminateContextFactoryForTests(). |
| 56 platform_test_helper_.reset(); | 54 platform_test_helper_.reset(); |
| 57 } | 55 } |
| 58 | 56 |
| 59 gfx::NativeWindow ScopedViewsTestHelper::GetContext() { | 57 gfx::NativeWindow ScopedViewsTestHelper::GetContext() { |
| 60 return test_helper_->GetContext(); | 58 return test_helper_->GetContext(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 } // namespace views | 61 } // namespace views |
| OLD | NEW |