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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 : ScopedViewsTestHelper(base::WrapUnique(new TestViewsDelegate)) {} | 26 : ScopedViewsTestHelper(base::WrapUnique(new TestViewsDelegate)) {} |
27 | 27 |
28 ScopedViewsTestHelper::ScopedViewsTestHelper( | 28 ScopedViewsTestHelper::ScopedViewsTestHelper( |
29 std::unique_ptr<TestViewsDelegate> views_delegate) | 29 std::unique_ptr<TestViewsDelegate> views_delegate) |
30 : views_delegate_(std::move(views_delegate)), | 30 : views_delegate_(std::move(views_delegate)), |
31 platform_test_helper_(PlatformTestHelper::Create()) { | 31 platform_test_helper_(PlatformTestHelper::Create()) { |
32 // The ContextFactory must exist before any Compositors are created. | 32 // The ContextFactory must exist before any Compositors are created. |
33 bool enable_pixel_output = false; | 33 bool enable_pixel_output = false; |
34 #if defined(USE_AURA) | 34 #if defined(USE_AURA) |
35 ui::ContextFactory* old_context_factory = nullptr; | 35 ui::ContextFactory* old_context_factory = nullptr; |
| 36 ui::ContextFactoryPrivate* old_context_factory_private = nullptr; |
36 if (PlatformTestHelper::IsMus()) { | 37 if (PlatformTestHelper::IsMus()) { |
37 old_context_factory = aura::Env::GetInstance()->context_factory(); | 38 old_context_factory = aura::Env::GetInstance()->context_factory(); |
38 DCHECK(old_context_factory); | 39 DCHECK(old_context_factory); |
| 40 old_context_factory_private = |
| 41 aura::Env::GetInstance()->context_factory_private(); |
39 } | 42 } |
40 #endif | 43 #endif |
41 ui::ContextFactory* context_factory = | 44 ui::ContextFactory* context_factory = nullptr; |
42 ui::InitializeContextFactoryForTests(enable_pixel_output); | 45 ui::ContextFactoryPrivate* context_factory_private = nullptr; |
| 46 ui::InitializeContextFactoryForTests(enable_pixel_output, &context_factory, |
| 47 &context_factory_private); |
| 48 |
43 views_delegate_->set_context_factory(context_factory); | 49 views_delegate_->set_context_factory(context_factory); |
| 50 views_delegate_->set_context_factory_private(context_factory_private); |
44 | 51 |
45 test_helper_.reset(ViewsTestHelper::Create(base::MessageLoopForUI::current(), | 52 test_helper_.reset(ViewsTestHelper::Create(base::MessageLoopForUI::current(), |
46 context_factory)); | 53 context_factory, |
| 54 context_factory_private)); |
47 platform_test_helper_->OnTestHelperCreated(test_helper_.get()); | 55 platform_test_helper_->OnTestHelperCreated(test_helper_.get()); |
48 test_helper_->SetUp(); | 56 test_helper_->SetUp(); |
49 | 57 |
50 #if defined(USE_AURA) | 58 #if defined(USE_AURA) |
51 // When running inside mus, the context-factory from | 59 // When running inside mus, the context-factory from |
52 // ui::InitializeContextFactoryForTests() is only needed for the default | 60 // ui::InitializeContextFactoryForTests() is only needed for the default |
53 // WindowTreeHost instance created by TestScreen. After that, the | 61 // WindowTreeHost instance created by TestScreen. After that, the |
54 // context-factory is used when creating Widgets (to set-up the compositor for | 62 // context-factory is used when creating Widgets (to set-up the compositor for |
55 // the corresponding ui::Windows). So restore the context-factory (which | 63 // the corresponding ui::Windows). So restore the context-factory (which |
56 // WindowManagerConnection would have set up), so that NativeWidgetMus | 64 // WindowManagerConnection would have set up), so that NativeWidgetMus |
57 // installs the correct context-factory that can talk to mus. | 65 // installs the correct context-factory that can talk to mus. |
58 if (PlatformTestHelper::IsMus()) | 66 if (PlatformTestHelper::IsMus()) { |
59 aura::Env::GetInstance()->set_context_factory(old_context_factory); | 67 aura::Env::GetInstance()->set_context_factory(old_context_factory); |
| 68 aura::Env::GetInstance()->set_context_factory_private( |
| 69 old_context_factory_private); |
| 70 } |
60 #endif | 71 #endif |
61 | 72 |
62 ui::InitializeInputMethodForTesting(); | 73 ui::InitializeInputMethodForTesting(); |
63 ui::TestClipboard::CreateForCurrentThread(); | 74 ui::TestClipboard::CreateForCurrentThread(); |
64 } | 75 } |
65 | 76 |
66 ScopedViewsTestHelper::~ScopedViewsTestHelper() { | 77 ScopedViewsTestHelper::~ScopedViewsTestHelper() { |
67 ui::Clipboard::DestroyClipboardForCurrentThread(); | 78 ui::Clipboard::DestroyClipboardForCurrentThread(); |
68 ui::ShutdownInputMethodForTesting(); | 79 ui::ShutdownInputMethodForTesting(); |
69 test_helper_->TearDown(); | 80 test_helper_->TearDown(); |
70 test_helper_.reset(); | 81 test_helper_.reset(); |
71 | 82 |
72 views_delegate_.reset(); | 83 views_delegate_.reset(); |
73 | 84 |
74 // The Mus PlatformTestHelper has state that is deleted by | 85 // The Mus PlatformTestHelper has state that is deleted by |
75 // ui::TerminateContextFactoryForTests(). | 86 // ui::TerminateContextFactoryForTests(). |
76 platform_test_helper_.reset(); | 87 platform_test_helper_.reset(); |
77 | 88 |
78 ui::TerminateContextFactoryForTests(); | 89 ui::TerminateContextFactoryForTests(); |
79 } | 90 } |
80 | 91 |
81 gfx::NativeWindow ScopedViewsTestHelper::GetContext() { | 92 gfx::NativeWindow ScopedViewsTestHelper::GetContext() { |
82 return test_helper_->GetContext(); | 93 return test_helper_->GetContext(); |
83 } | 94 } |
84 | 95 |
85 } // namespace views | 96 } // namespace views |
OLD | NEW |