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 "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/test/aura_test_base.h" |
| 11 #include "ui/aura/test/test_window_delegate.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/events/test/event_generator.h" |
| 14 |
| 15 namespace chromecast { |
| 16 namespace test { |
| 17 |
| 18 using CastWindowManagerAuraTest = aura::test::AuraTestBase; |
| 19 |
| 20 class CastTestWindowDelegate : public aura::test::TestWindowDelegate { |
| 21 public: |
| 22 CastTestWindowDelegate() : key_code_(ui::VKEY_UNKNOWN) {} |
| 23 ~CastTestWindowDelegate() override {} |
| 24 |
| 25 // Overridden from TestWindowDelegate: |
| 26 void OnKeyEvent(ui::KeyEvent* event) override { |
| 27 key_code_ = event->key_code(); |
| 28 } |
| 29 |
| 30 ui::KeyboardCode key_code() { return key_code_; } |
| 31 |
| 32 private: |
| 33 ui::KeyboardCode key_code_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(CastTestWindowDelegate); |
| 36 }; |
| 37 |
| 38 TEST_F(CastWindowManagerAuraTest, InitialWindowId) { |
| 39 CastTestWindowDelegate* window_delegate = new CastTestWindowDelegate(); |
| 40 std::unique_ptr<aura::Window> window(new aura::Window(window_delegate)); |
| 41 window->Init(ui::LAYER_NOT_DRAWN); |
| 42 |
| 43 // We have chosen WindowId::BOTTOM to match the initial window ID of an Aura |
| 44 // window so that z-ordering works correctly. |
| 45 EXPECT_EQ(window->id(), CastWindowManager::WindowId::BOTTOM); |
| 46 } |
| 47 |
| 48 TEST_F(CastWindowManagerAuraTest, WindowInput) { |
| 49 std::unique_ptr<CastWindowManager> window_manager( |
| 50 CastWindowManager::Create(true /* enable input */)); |
| 51 |
| 52 CastTestWindowDelegate* window_delegate = new CastTestWindowDelegate(); |
| 53 std::unique_ptr<aura::Window> window(new aura::Window(window_delegate)); |
| 54 window->Init(ui::LAYER_NOT_DRAWN); |
| 55 window->SetName("event window"); |
| 56 window_manager->AddWindow(window.get()); |
| 57 window->SetBounds(gfx::Rect(0, 0, 1280, 720)); |
| 58 window->Show(); |
| 59 EXPECT_FALSE(window->IsRootWindow()); |
| 60 EXPECT_TRUE(window->GetHost()); |
| 61 |
| 62 // Confirm that the Aura focus client tracks window focus correctly. |
| 63 aura::client::FocusClient* focus_client = |
| 64 aura::client::GetFocusClient(window.get()); |
| 65 EXPECT_TRUE(focus_client); |
| 66 EXPECT_FALSE(focus_client->GetFocusedWindow()); |
| 67 window->Focus(); |
| 68 EXPECT_EQ(window.get(), focus_client->GetFocusedWindow()); |
| 69 |
| 70 // Confirm that a keyboard event is delivered to the window. |
| 71 std::unique_ptr<ui::test::EventGenerator> event_generator( |
| 72 new ui::test::EventGenerator(window.get())); |
| 73 event_generator->PressKey(ui::VKEY_0, ui::EF_NONE); |
| 74 EXPECT_EQ(ui::VKEY_0, window_delegate->key_code()); |
| 75 |
| 76 event_generator.reset(); |
| 77 window.reset(); |
| 78 window_manager.reset(); |
| 79 } |
| 80 |
| 81 TEST_F(CastWindowManagerAuraTest, WindowInputDisabled) { |
| 82 std::unique_ptr<CastWindowManager> window_manager( |
| 83 CastWindowManager::Create(false /* enable input */)); |
| 84 |
| 85 CastTestWindowDelegate* window_delegate = new CastTestWindowDelegate(); |
| 86 std::unique_ptr<aura::Window> window(new aura::Window(window_delegate)); |
| 87 window->Init(ui::LAYER_NOT_DRAWN); |
| 88 window->SetName("event window"); |
| 89 window_manager->AddWindow(window.get()); |
| 90 window->SetBounds(gfx::Rect(0, 0, 1280, 720)); |
| 91 window->Show(); |
| 92 EXPECT_FALSE(window->IsRootWindow()); |
| 93 EXPECT_TRUE(window->GetHost()); |
| 94 |
| 95 // Confirm that the Aura focus client tracks window focus correctly. |
| 96 aura::client::FocusClient* focus_client = |
| 97 aura::client::GetFocusClient(window.get()); |
| 98 EXPECT_TRUE(focus_client); |
| 99 EXPECT_FALSE(focus_client->GetFocusedWindow()); |
| 100 window->Focus(); |
| 101 EXPECT_EQ(window.get(), focus_client->GetFocusedWindow()); |
| 102 |
| 103 // Confirm that a key event is *not* delivered to the window when input is |
| 104 // disabled. |
| 105 std::unique_ptr<ui::test::EventGenerator> event_generator( |
| 106 new ui::test::EventGenerator(window.get())); |
| 107 event_generator->PressKey(ui::VKEY_0, ui::EF_NONE); |
| 108 EXPECT_EQ(ui::VKEY_UNKNOWN, window_delegate->key_code()); |
| 109 |
| 110 event_generator.reset(); |
| 111 window.reset(); |
| 112 window_manager.reset(); |
| 113 } |
| 114 |
| 115 } // namespace test |
| 116 } // namespace chromecast |
OLD | NEW |