1 // Copyright 2014 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/views_test_helper_aura.h"
7 #include "ui/aura/client/screen_position_client.h"
8 #include "ui/aura/test/aura_test_helper.h"
9 #include "ui/wm/core/capture_controller.h"
10 #include "ui/wm/core/default_activation_client.h"
11 #include "ui/wm/core/default_screen_position_client.h"
12 #include "ui/wm/core/wm_state.h"
17 ViewsTestHelper
* ViewsTestHelper::Create(base::MessageLoopForUI
* message_loop
,
18 ui::ContextFactory
* context_factory
) {
19 return new ViewsTestHelperAura(message_loop
, context_factory
);
22 ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI
* message_loop
,
23 ui::ContextFactory
* context_factory
)
24 : context_factory_(context_factory
) {
25 aura_test_helper_
.reset(new aura::test::AuraTestHelper(message_loop
));
28 ViewsTestHelperAura::~ViewsTestHelperAura() {
31 void ViewsTestHelperAura::SetUp() {
32 aura_test_helper_
->SetUp(context_factory_
);
33 gfx::NativeWindow root_window
= GetContext();
34 new wm::DefaultActivationClient(root_window
);
35 wm_state_
.reset(new wm::WMState
);
37 if (!aura::client::GetScreenPositionClient(root_window
)) {
38 screen_position_client_
.reset(new wm::DefaultScreenPositionClient
);
39 aura::client::SetScreenPositionClient(root_window
,
40 screen_position_client_
.get());
44 void ViewsTestHelperAura::TearDown() {
45 if (screen_position_client_
.get() ==
46 aura::client::GetScreenPositionClient(GetContext()))
47 aura::client::SetScreenPositionClient(GetContext(), nullptr);
49 aura_test_helper_
->TearDown();
51 CHECK(!wm::ScopedCaptureClient::IsActive());
54 gfx::NativeWindow
ViewsTestHelperAura::GetContext() {
55 return aura_test_helper_
->root_window();