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