| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/views_test_helper_aura.h" | 5 #include "ui/views/test/views_test_helper_aura.h" |
| 6 | 6 |
| 7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
| 8 #include "ui/aura/test/aura_test_helper.h" | 8 #include "ui/aura/test/aura_test_helper.h" |
| 9 #include "ui/wm/core/capture_controller.h" | 9 #include "ui/wm/core/capture_controller.h" |
| 10 #include "ui/wm/core/default_activation_client.h" | 10 #include "ui/wm/core/default_activation_client.h" |
| 11 #include "ui/wm/core/default_screen_position_client.h" | 11 #include "ui/wm/core/default_screen_position_client.h" |
| 12 #include "ui/wm/core/wm_state.h" | |
| 13 | 12 |
| 14 namespace views { | 13 namespace views { |
| 15 | 14 |
| 16 // static | 15 // static |
| 17 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop, | 16 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop, |
| 18 ui::ContextFactory* context_factory) { | 17 ui::ContextFactory* context_factory) { |
| 19 return new ViewsTestHelperAura(message_loop, context_factory); | 18 return new ViewsTestHelperAura(message_loop, context_factory); |
| 20 } | 19 } |
| 21 | 20 |
| 22 ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop, | 21 ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop, |
| 23 ui::ContextFactory* context_factory) | 22 ui::ContextFactory* context_factory) |
| 24 : context_factory_(context_factory) { | 23 : context_factory_(context_factory) { |
| 25 aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop)); | 24 aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop)); |
| 26 } | 25 } |
| 27 | 26 |
| 28 ViewsTestHelperAura::~ViewsTestHelperAura() { | 27 ViewsTestHelperAura::~ViewsTestHelperAura() { |
| 29 } | 28 } |
| 30 | 29 |
| 31 void ViewsTestHelperAura::SetUp() { | 30 void ViewsTestHelperAura::SetUp() { |
| 32 aura_test_helper_->SetUp(context_factory_); | 31 aura_test_helper_->SetUp(context_factory_); |
| 33 gfx::NativeWindow root_window = GetContext(); | 32 gfx::NativeWindow root_window = GetContext(); |
| 34 new wm::DefaultActivationClient(root_window); | 33 new wm::DefaultActivationClient(root_window); |
| 35 wm_state_.reset(new wm::WMState); | |
| 36 | 34 |
| 37 if (!aura::client::GetScreenPositionClient(root_window)) { | 35 if (!aura::client::GetScreenPositionClient(root_window)) { |
| 38 screen_position_client_.reset(new wm::DefaultScreenPositionClient); | 36 screen_position_client_.reset(new wm::DefaultScreenPositionClient); |
| 39 aura::client::SetScreenPositionClient(root_window, | 37 aura::client::SetScreenPositionClient(root_window, |
| 40 screen_position_client_.get()); | 38 screen_position_client_.get()); |
| 41 } | 39 } |
| 42 } | 40 } |
| 43 | 41 |
| 44 void ViewsTestHelperAura::TearDown() { | 42 void ViewsTestHelperAura::TearDown() { |
| 45 // Ensure all Widgets (and windows) are closed in unit tests. This is done | 43 // Ensure all Widgets (and windows) are closed in unit tests. This is done |
| 46 // automatically when the RootWindow is torn down, but is an error on | 44 // automatically when the RootWindow is torn down, but is an error on |
| 47 // platforms that must ensure no Compositors are alive when the ContextFactory | 45 // platforms that must ensure no Compositors are alive when the ContextFactory |
| 48 // is torn down. | 46 // is torn down. |
| 49 // So, although it's optional, check the root window to detect failures before | 47 // So, although it's optional, check the root window to detect failures before |
| 50 // they hit the CQ on other platforms. | 48 // they hit the CQ on other platforms. |
| 51 DCHECK(aura_test_helper_->root_window()->children().empty()) | 49 DCHECK(aura_test_helper_->root_window()->children().empty()) |
| 52 << "Not all windows were closed."; | 50 << "Not all windows were closed."; |
| 53 | 51 |
| 54 if (screen_position_client_.get() == | 52 if (screen_position_client_.get() == |
| 55 aura::client::GetScreenPositionClient(GetContext())) | 53 aura::client::GetScreenPositionClient(GetContext())) |
| 56 aura::client::SetScreenPositionClient(GetContext(), nullptr); | 54 aura::client::SetScreenPositionClient(GetContext(), nullptr); |
| 57 | 55 |
| 58 aura_test_helper_->TearDown(); | 56 aura_test_helper_->TearDown(); |
| 59 wm_state_.reset(); | |
| 60 CHECK(!wm::ScopedCaptureClient::IsActive()); | 57 CHECK(!wm::ScopedCaptureClient::IsActive()); |
| 61 } | 58 } |
| 62 | 59 |
| 63 gfx::NativeWindow ViewsTestHelperAura::GetContext() { | 60 gfx::NativeWindow ViewsTestHelperAura::GetContext() { |
| 64 return aura_test_helper_->root_window(); | 61 return aura_test_helper_->root_window(); |
| 65 } | 62 } |
| 66 | 63 |
| 67 } // namespace views | 64 } // namespace views |
| OLD | NEW |