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
3 // found in the LICENSE file.
5 #include "ui/views/test/scoped_views_test_helper.h"
7 #include "base/message_loop/message_loop.h"
8 #include "ui/base/ime/input_method_initializer.h"
9 #include "ui/compositor/test/context_factories_for_test.h"
10 #include "ui/views/test/test_views_delegate.h"
11 #include "ui/views/test/views_test_helper.h"
15 ScopedViewsTestHelper::ScopedViewsTestHelper()
16 : ScopedViewsTestHelper(make_scoped_ptr(new TestViewsDelegate
)) {
19 ScopedViewsTestHelper::ScopedViewsTestHelper(
20 scoped_ptr
<TestViewsDelegate
> views_delegate
)
21 : views_delegate_(views_delegate
.Pass()) {
22 // The ContextFactory must exist before any Compositors are created.
23 bool enable_pixel_output
= false;
24 ui::ContextFactory
* context_factory
=
25 ui::InitializeContextFactoryForTests(enable_pixel_output
);
26 views_delegate_
->set_context_factory(context_factory
);
28 test_helper_
.reset(ViewsTestHelper::Create(base::MessageLoopForUI::current(),
30 test_helper_
->SetUp();
32 ui::InitializeInputMethodForTesting();
35 ScopedViewsTestHelper::~ScopedViewsTestHelper() {
36 ui::ShutdownInputMethodForTesting();
37 test_helper_
->TearDown();
40 ui::TerminateContextFactoryForTests();
41 views_delegate_
.reset();
44 gfx::NativeWindow
ScopedViewsTestHelper::GetContext() {
45 return test_helper_
->GetContext();