OLD | NEW |
---|---|
(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_window_manager.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/run_loop.h" | |
10 #include "ui/aura/client/focus_client.h" | |
11 #include "ui/aura/test/aura_test_base.h" | |
12 #include "ui/aura/test/test_window_delegate.h" | |
13 #include "ui/aura/test/ui_controls_factory_aura.h" | |
14 #include "ui/aura/window.h" | |
15 | |
16 namespace chromecast { | |
17 namespace test { | |
18 | |
19 using CastWindowManagerAuraTest = aura::test::AuraTestBase; | |
20 | |
21 class CastTestWindowDelegate : public aura::test::TestWindowDelegate { | |
22 public: | |
23 CastTestWindowDelegate() : key_code_(ui::VKEY_UNKNOWN) {} | |
24 ~CastTestWindowDelegate() override {} | |
25 | |
26 // Overridden from TestWindowDelegate: | |
27 void OnKeyEvent(ui::KeyEvent* event) override { | |
28 key_code_ = event->key_code(); | |
29 } | |
30 | |
31 ui::KeyboardCode key_code() { return key_code_; } | |
32 | |
33 private: | |
34 ui::KeyboardCode key_code_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(CastTestWindowDelegate); | |
37 }; | |
38 | |
39 TEST_F(CastWindowManagerAuraTest, WindowInput) { | |
40 std::unique_ptr<CastWindowManager> window_manager( | |
41 CastWindowManager::Create(true /* enable input */)); | |
42 | |
43 CastTestWindowDelegate* window_delegate = new CastTestWindowDelegate(); | |
44 std::unique_ptr<aura::Window> window(new aura::Window(window_delegate)); | |
45 window->Init(ui::LAYER_NOT_DRAWN); | |
46 window->SetName("event window"); | |
47 window_manager->AddWindow(window.get()); | |
48 window->SetBounds(gfx::Rect(0, 0, 1280, 720)); | |
49 window->Show(); | |
50 EXPECT_FALSE(window->IsRootWindow()); | |
51 EXPECT_TRUE(window->GetHost()); | |
52 | |
53 // Confirm that the Aura focus client tracks window focus correctly. | |
54 aura::client::FocusClient* focus_client = | |
55 aura::client::GetFocusClient(window.get()); | |
56 EXPECT_TRUE(focus_client); | |
57 EXPECT_FALSE(focus_client->GetFocusedWindow()); | |
58 window->Focus(); | |
59 EXPECT_EQ(window.get(), focus_client->GetFocusedWindow()); | |
60 | |
61 // Confirm that a keyboard event is delivered to the window. | |
62 std::unique_ptr<ui_controls::UIControlsAura> event_generator( | |
63 aura::test::CreateUIControlsAura(window->GetHost())); | |
64 EXPECT_TRUE(event_generator->SendKeyPress(nullptr, ui::VKEY_0, false, false, | |
65 false, false)); | |
66 base::RunLoop().RunUntilIdle(); | |
sadrul
2017/01/26 01:50:10
Do you need to spin the message-loop here?
Joshua LeVasseur
2017/01/26 02:51:01
The event-dispatch logic posts tasks, so this is n
sadrul
2017/01/27 00:30:56
Ohh, you are using UIControlsAura. That's why.
Pl
Joshua LeVasseur
2017/01/27 04:53:44
Thanks! Done.
| |
67 EXPECT_EQ(ui::VKEY_0, window_delegate->key_code()); | |
68 | |
69 event_generator.reset(); | |
70 window.reset(); | |
71 window_manager.reset(); | |
72 } | |
73 | |
74 TEST_F(CastWindowManagerAuraTest, WindowInputDisabled) { | |
75 std::unique_ptr<CastWindowManager> window_manager( | |
76 CastWindowManager::Create(false /* enable input */)); | |
77 | |
78 CastTestWindowDelegate* window_delegate = new CastTestWindowDelegate(); | |
79 std::unique_ptr<aura::Window> window(new aura::Window(window_delegate)); | |
80 window->Init(ui::LAYER_NOT_DRAWN); | |
81 window->SetName("event window"); | |
82 window_manager->AddWindow(window.get()); | |
83 window->SetBounds(gfx::Rect(0, 0, 1280, 720)); | |
84 window->Show(); | |
85 EXPECT_FALSE(window->IsRootWindow()); | |
86 EXPECT_TRUE(window->GetHost()); | |
87 | |
88 // Confirm that the Aura focus client tracks window focus correctly. | |
89 aura::client::FocusClient* focus_client = | |
90 aura::client::GetFocusClient(window.get()); | |
91 EXPECT_TRUE(focus_client); | |
92 EXPECT_FALSE(focus_client->GetFocusedWindow()); | |
93 window->Focus(); | |
94 EXPECT_EQ(window.get(), focus_client->GetFocusedWindow()); | |
95 | |
96 // Confirm that a key event is *not* delivered to the window when input is | |
97 // disabled. | |
98 std::unique_ptr<ui_controls::UIControlsAura> event_generator( | |
99 aura::test::CreateUIControlsAura(window->GetHost())); | |
100 EXPECT_TRUE(event_generator->SendKeyPress(nullptr, ui::VKEY_0, false, false, | |
101 false, false)); | |
102 base::RunLoop().RunUntilIdle(); | |
sadrul
2017/01/26 01:50:10
ditto
Joshua LeVasseur
2017/01/26 02:51:01
Acknowledged.
| |
103 EXPECT_EQ(ui::VKEY_UNKNOWN, window_delegate->key_code()); | |
104 | |
105 event_generator.reset(); | |
106 window.reset(); | |
107 window_manager.reset(); | |
108 } | |
109 | |
110 } // namespace test | |
111 } // namespace chromecast | |
OLD | NEW |