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

Side by Side Diff: chromecast/graphics/cast_focus_client_aura_test.cc

Issue 2636303002: [Chromecast] Add support for z-order and window focus. (Closed)
Patch Set: reviewer feedback Created 3 years, 10 months 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
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #include "chromecast/graphics/cast_focus_client_aura.h"
6
7 #include <memory>
8
9 #include "ui/aura/test/aura_test_base.h"
10 #include "ui/aura/test/test_window_delegate.h"
11 #include "ui/aura/window.h"
12
13 namespace chromecast {
14 namespace test {
15
16 using CastFocusClientAuraTest = aura::test::AuraTestBase;
17
18 class TestWindow {
19 public:
20 TestWindow()
21 : delegate_(new aura::test::TestWindowDelegate()),
22 window_(new aura::Window(delegate_)) {
23 window_->Init(ui::LAYER_NOT_DRAWN);
24 window_->Show();
25 }
26
27 virtual ~TestWindow() {}
28
29 aura::test::TestWindowDelegate* delegate() const { return delegate_; }
30 aura::Window* window() const { return window_.get(); }
31
32 private:
33 aura::test::TestWindowDelegate* const delegate_;
34 std::unique_ptr<aura::Window> const window_;
35
36 DISALLOW_COPY_AND_ASSIGN(TestWindow);
37 };
38
39 TEST_F(CastFocusClientAuraTest, FocusableWindows) {
40 std::unique_ptr<aura::WindowTreeHost> window_tree_host(
41 aura::WindowTreeHost::Create(gfx::Rect(0, 0, 1280, 720)));
42 window_tree_host->InitHost();
43 window_tree_host->Show();
44
45 CastFocusClientAura focus_client;
46
47 std::unique_ptr<TestWindow> test_window(new TestWindow);
48 window_tree_host->window()->AddChild(test_window->window());
49
50 // Confirm that we can't add an un-focusable window.
51 test_window->delegate()->set_can_focus(false);
52 focus_client.FocusWindow(test_window->window());
53 EXPECT_FALSE(focus_client.GetFocusedWindow());
54
55 // Confirm that we can add a focusable window.
56 test_window->delegate()->set_can_focus(true);
57 focus_client.FocusWindow(test_window->window());
58 EXPECT_EQ(test_window->window(), focus_client.GetFocusedWindow());
59
60 // Confirm that the focused window loses focus when losing visibility.
61 test_window->window()->Hide();
62 EXPECT_FALSE(focus_client.GetFocusedWindow());
63
64 // Confirm that we find a focusable window when it becomes visible.
65 test_window->window()->Show();
66 EXPECT_EQ(test_window->window(), focus_client.GetFocusedWindow());
67
68 // Confirm that the focused window loses focus when it is destroyed.
69 test_window.reset();
70 EXPECT_FALSE(focus_client.GetFocusedWindow());
71 }
72
73 TEST_F(CastFocusClientAuraTest, ChildFocus) {
74 std::unique_ptr<aura::WindowTreeHost> window_tree_host(
75 aura::WindowTreeHost::Create(gfx::Rect(0, 0, 1280, 720)));
76 window_tree_host->InitHost();
77 window_tree_host->Show();
78
79 CastFocusClientAura focus_client;
80
81 std::unique_ptr<TestWindow> parent(new TestWindow);
82 parent->delegate()->set_can_focus(true);
83 window_tree_host->window()->AddChild(parent->window());
84
85 std::unique_ptr<TestWindow> child(new TestWindow);
86 child->delegate()->set_can_focus(true);
87 parent->window()->AddChild(child->window());
88
89 // Confirm that the child window has the focus, not its top-level parent
90 // window.
91 focus_client.FocusWindow(child->window());
92 EXPECT_EQ(child->window(), focus_client.GetFocusedWindow());
93
94 // Confirm that removing the child window doesn't focus the parent window
95 // (since we've never requested focus for the parent window).
96 parent->window()->RemoveChild(child->window());
97 EXPECT_FALSE(focus_client.GetFocusedWindow());
98
99 // Confirm that we still have no focused window after re-adding the child
100 // window, because we haven't requested focus.
101 parent->window()->AddChild(child->window());
102 EXPECT_FALSE(focus_client.GetFocusedWindow());
103
104 // Request focus and confirm that the child is focused.
105 focus_client.FocusWindow(child->window());
106 EXPECT_EQ(child->window(), focus_client.GetFocusedWindow());
107 }
108
109 TEST_F(CastFocusClientAuraTest, ZOrder) {
110 std::unique_ptr<aura::WindowTreeHost> window_tree_host(
111 aura::WindowTreeHost::Create(gfx::Rect(0, 0, 1280, 720)));
112 window_tree_host->InitHost();
113 window_tree_host->Show();
114
115 CastFocusClientAura focus_client;
116
117 // Add the window with the lowest z-order.
118 std::unique_ptr<TestWindow> low(new TestWindow);
119 low->delegate()->set_can_focus(true);
120 low->window()->set_id(1);
121 window_tree_host->window()->AddChild(low->window());
122 focus_client.FocusWindow(low->window());
123 EXPECT_EQ(low->window(), focus_client.GetFocusedWindow());
124
125 // Add the window with the highest z-order, and confirm that it gets focus.
126 std::unique_ptr<TestWindow> high(new TestWindow);
127 high->delegate()->set_can_focus(true);
128 high->window()->set_id(3);
129 window_tree_host->window()->AddChild(high->window());
130 focus_client.FocusWindow(high->window());
131 EXPECT_EQ(high->window(), focus_client.GetFocusedWindow());
132
133 // Add the window with the middle z-order, and confirm that focus remains with
134 // the highest z-order window.
135 std::unique_ptr<TestWindow> middle(new TestWindow);
136 middle->delegate()->set_can_focus(true);
137 middle->window()->set_id(2);
138 window_tree_host->window()->AddChild(middle->window());
139 focus_client.FocusWindow(middle->window());
140 EXPECT_EQ(high->window(), focus_client.GetFocusedWindow());
141
142 // Confirm that requesting focus on the lower z-order windows leaves focus on
143 // the highest z-order window.
144 focus_client.FocusWindow(low->window());
145 EXPECT_EQ(high->window(), focus_client.GetFocusedWindow());
146 focus_client.FocusWindow(middle->window());
147 EXPECT_EQ(high->window(), focus_client.GetFocusedWindow());
148
149 // Confirm that focus moves to next highest window.
150 high.reset();
151 EXPECT_EQ(middle->window(), focus_client.GetFocusedWindow());
152
153 // Confirm that focus moves to next highest window.
154 middle.reset();
155 EXPECT_EQ(low->window(), focus_client.GetFocusedWindow());
156
157 // Confirm that there is no focused window.
158 low.reset();
159 EXPECT_FALSE(focus_client.GetFocusedWindow());
160 }
161
162 } // namespace test
163 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/graphics/cast_focus_client_aura.cc ('k') | chromecast/graphics/cast_window_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698