Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: ui/views/test/views_test_helper_aura.cc

Issue 2488393003: Changes views_aura_mus_unittests to create DesktopNativeWidgetAura (Closed)
Patch Set: remove this and fix mac Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/test/views_test_base.cc ('k') | ui/views/test/widget_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/test/platform_test_helper.h"
9 #include "ui/wm/core/capture_controller.h" 10 #include "ui/wm/core/capture_controller.h"
10 #include "ui/wm/core/default_activation_client.h" 11 #include "ui/wm/core/default_activation_client.h"
11 #include "ui/wm/core/default_screen_position_client.h" 12 #include "ui/wm/core/default_screen_position_client.h"
12 13
13 namespace views { 14 namespace views {
14 15
15 // static 16 // static
16 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop, 17 ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
17 ui::ContextFactory* context_factory) { 18 ui::ContextFactory* context_factory) {
18 return new ViewsTestHelperAura(message_loop, context_factory); 19 return new ViewsTestHelperAura(message_loop, context_factory);
19 } 20 }
20 21
21 ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop, 22 ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
22 ui::ContextFactory* context_factory) 23 ui::ContextFactory* context_factory)
23 : context_factory_(context_factory) { 24 : context_factory_(context_factory) {
24 aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop)); 25 aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop));
25 } 26 }
26 27
27 ViewsTestHelperAura::~ViewsTestHelperAura() { 28 ViewsTestHelperAura::~ViewsTestHelperAura() {
28 } 29 }
29 30
30 void ViewsTestHelperAura::EnableMusWithWindowTreeClient( 31 void ViewsTestHelperAura::EnableMusWithWindowTreeClient(
31 aura::WindowTreeClient* window_tree_client) { 32 aura::WindowTreeClient* window_tree_client) {
32 aura_test_helper_->EnableMusWithWindowTreeClient(window_tree_client); 33 aura_test_helper_->EnableMusWithWindowTreeClient(window_tree_client);
33 } 34 }
34 35
35 void ViewsTestHelperAura::SetUp() { 36 void ViewsTestHelperAura::SetUp() {
36 aura_test_helper_->SetUp(context_factory_); 37 aura_test_helper_->SetUp(context_factory_);
38
39 // GetContext() may return null. See comment in GetContext().
37 gfx::NativeWindow root_window = GetContext(); 40 gfx::NativeWindow root_window = GetContext();
41 if (!root_window)
42 return;
43
38 new wm::DefaultActivationClient(root_window); 44 new wm::DefaultActivationClient(root_window);
39 45
40 if (!aura::client::GetScreenPositionClient(root_window)) { 46 if (!aura::client::GetScreenPositionClient(root_window)) {
41 screen_position_client_.reset(new wm::DefaultScreenPositionClient); 47 screen_position_client_.reset(new wm::DefaultScreenPositionClient);
42 aura::client::SetScreenPositionClient(root_window, 48 aura::client::SetScreenPositionClient(root_window,
43 screen_position_client_.get()); 49 screen_position_client_.get());
44 } 50 }
45 } 51 }
46 52
47 void ViewsTestHelperAura::TearDown() { 53 void ViewsTestHelperAura::TearDown() {
48 // Ensure all Widgets (and windows) are closed in unit tests. This is done 54 // GetContext() may return null. See comment in GetContext().
49 // automatically when the RootWindow is torn down, but is an error on 55 if (GetContext()) {
50 // platforms that must ensure no Compositors are alive when the ContextFactory 56 // Ensure all Widgets (and windows) are closed in unit tests. This is done
51 // is torn down. 57 // automatically when the RootWindow is torn down, but is an error on
52 // So, although it's optional, check the root window to detect failures before 58 // platforms that must ensure no Compositors are alive when the
53 // they hit the CQ on other platforms. 59 // ContextFactory is torn down.
54 DCHECK(aura_test_helper_->root_window()->children().empty()) 60 // So, although it's optional, check the root window to detect failures
55 << "Not all windows were closed."; 61 // before they hit the CQ on other platforms.
62 DCHECK(aura_test_helper_->root_window()->children().empty())
63 << "Not all windows were closed.";
56 64
57 if (screen_position_client_.get() == 65 if (screen_position_client_.get() ==
58 aura::client::GetScreenPositionClient(GetContext())) 66 aura::client::GetScreenPositionClient(GetContext()))
59 aura::client::SetScreenPositionClient(GetContext(), nullptr); 67 aura::client::SetScreenPositionClient(GetContext(), nullptr);
68 }
60 69
61 aura_test_helper_->TearDown(); 70 aura_test_helper_->TearDown();
62 CHECK(!wm::CaptureController::Get() || 71 CHECK(!wm::CaptureController::Get() ||
63 !wm::CaptureController::Get()->is_active()); 72 !wm::CaptureController::Get()->is_active());
64 } 73 }
65 74
66 gfx::NativeWindow ViewsTestHelperAura::GetContext() { 75 gfx::NativeWindow ViewsTestHelperAura::GetContext() {
76 if (PlatformTestHelper::IsAuraMusClient()) {
77 // GetContext() returns the root of a WindowTreeHost associated with a
78 // single display that is intended for an ash like environment. Such a
79 // configuration doesn't make sense for aura-mus-client, where it's testing
80 // DesktopNativeWidgetAura.
81 return nullptr;
82 }
83
67 return aura_test_helper_->root_window(); 84 return aura_test_helper_->root_window();
68 } 85 }
69 86
70 } // namespace views 87 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/test/views_test_base.cc ('k') | ui/views/test/widget_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698