Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "ui/aura/mus/window_tree_host_mus.h" | |
| 6 | |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "ui/aura/client/default_capture_client.h" | |
| 10 #include "ui/aura/client/focus_client.h" | |
| 11 #include "ui/aura/env.h" | |
| 12 #include "ui/aura/mus/property_converter.h" | |
| 13 #include "ui/aura/mus/window_port_mus.h" | |
| 14 #include "ui/aura/mus/window_tree_client_delegate.h" | |
| 15 #include "ui/aura/mus/window_tree_host_mus.h" | |
| 16 #include "ui/aura/test/env_test_helper.h" | |
| 17 #include "ui/aura/test/mus/test_window_tree.h" | |
| 18 #include "ui/aura/test/mus/test_window_tree_client_setup.h" | |
| 19 #include "ui/aura/test/test_focus_client.h" | |
| 20 #include "ui/aura/test/test_screen.h" | |
| 21 #include "ui/aura/window_port_local.h" | |
| 22 #include "ui/compositor/test/context_factories_for_test.h" | |
| 23 #include "ui/wm/core/wm_state.h" | |
| 24 | |
| 25 namespace aura { | |
| 26 | |
| 27 // AuraMusClientTestBase doesn't appear to be going through the | |
| 28 // WindowTreeHostMus path at all. So instead, we create a minimal environment | |
|
sky
2016/11/19 15:29:31
There is a TODO about making the default display a
Elliot Glaysher
2016/11/22 00:48:07
Done.
The confusion on my end was having aura::Wi
| |
| 29 // where we build our own TestWindowTree and Window. | |
| 30 class WindowTreeHostMusTest : public testing::Test, | |
| 31 public aura::WindowTreeClientDelegate { | |
| 32 public: | |
| 33 WindowTreeHostMusTest() {} | |
| 34 ~WindowTreeHostMusTest() override {} | |
| 35 | |
| 36 void SetUp() override { | |
| 37 Test::SetUp(); | |
| 38 wm_state_ = base::MakeUnique<wm::WMState>(); | |
| 39 focus_client_ = base::MakeUnique<test::TestFocusClient>(); | |
| 40 capture_client_ = base::MakeUnique<client::DefaultCaptureClient>(); | |
| 41 property_converter_ = base::MakeUnique<aura::PropertyConverter>(); | |
| 42 | |
| 43 // The ContextFactory must exist before any Compositors are created. | |
| 44 bool enable_pixel_output = false; | |
| 45 ui::ContextFactory* context_factory = | |
| 46 ui::InitializeContextFactoryForTests(enable_pixel_output); | |
| 47 | |
| 48 if (!Env::GetInstanceDontCreate()) | |
| 49 env_ = Env::CreateInstance(Env::Mode::MUS); | |
| 50 Env::GetInstance()->set_context_factory(context_factory); | |
| 51 | |
| 52 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>(); | |
| 53 window_tree_client_setup_->Init(this); | |
| 54 | |
| 55 test_screen_.reset(TestScreen::Create(gfx::Size(800, 600))); | |
| 56 display::Screen::SetScreenInstance(test_screen_.get()); | |
| 57 | |
| 58 window_tree_host_mus_ = | |
| 59 base::MakeUnique<WindowTreeHostMus>(window_tree_client()); | |
| 60 } | |
| 61 | |
| 62 void TearDown() override { | |
| 63 window_tree_host_mus_.reset(); | |
| 64 if (display::Screen::GetScreen() == test_screen_.get()) | |
| 65 display::Screen::SetScreenInstance(nullptr); | |
| 66 window_tree_client_setup_.reset(); | |
| 67 | |
| 68 ui::TerminateContextFactoryForTests(); | |
| 69 Test::TearDown(); | |
| 70 } | |
| 71 | |
| 72 WindowTreeHostMus* window_tree_host_mus() { | |
| 73 return window_tree_host_mus_.get(); | |
| 74 } | |
| 75 | |
| 76 TestWindowTree* test_window_tree() { | |
| 77 return window_tree_client_setup_->window_tree(); | |
| 78 } | |
| 79 | |
| 80 WindowTreeClient* window_tree_client() { | |
| 81 return window_tree_client_setup_->window_tree_client(); | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 // WindowTreeClientDelegate: | |
| 86 void OnEmbed( | |
| 87 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {} | |
| 88 void OnLostConnection(aura::WindowTreeClient* client) override {} | |
| 89 void OnEmbedRootDestroyed(aura::Window* root) override {} | |
| 90 void OnPointerEventObserved(const ui::PointerEvent& event, | |
| 91 aura::Window* target) override {} | |
| 92 aura::client::CaptureClient* GetCaptureClient() override { | |
| 93 return capture_client_.get(); | |
| 94 } | |
| 95 aura::PropertyConverter* GetPropertyConverter() override { | |
| 96 return property_converter_.get(); | |
| 97 } | |
| 98 | |
| 99 // Needed by the compositor. | |
| 100 base::MessageLoopForUI message_loop_; | |
| 101 | |
| 102 std::unique_ptr<aura::Env> env_; | |
| 103 | |
| 104 std::unique_ptr<wm::WMState> wm_state_; | |
| 105 std::unique_ptr<client::DefaultCaptureClient> capture_client_; | |
| 106 std::unique_ptr<client::FocusClient> focus_client_; | |
| 107 std::unique_ptr<aura::PropertyConverter> property_converter_; | |
| 108 std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_; | |
| 109 std::unique_ptr<TestScreen> test_screen_; | |
| 110 | |
| 111 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_mus_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostMusTest); | |
| 114 }; | |
| 115 | |
| 116 TEST_F(WindowTreeHostMusTest, UpdateClientArea) { | |
| 117 gfx::Insets new_insets(10, 11, 12, 13); | |
| 118 window_tree_host_mus()->SetClientArea(new_insets); | |
| 119 EXPECT_EQ(new_insets, test_window_tree()->last_client_area()); | |
| 120 } | |
| 121 | |
| 122 TEST_F(WindowTreeHostMusTest, SetHitTestMask) { | |
| 123 EXPECT_FALSE(test_window_tree()->last_hit_test_mask().has_value()); | |
| 124 gfx::Rect mask(10, 10, 10, 10); | |
| 125 window_tree_host_mus()->SetHitTestMask(mask); | |
| 126 ASSERT_TRUE(test_window_tree()->last_hit_test_mask().has_value()); | |
| 127 EXPECT_EQ(mask, test_window_tree()->last_hit_test_mask()); | |
| 128 | |
| 129 window_tree_host_mus()->ClearHitTestMask(); | |
| 130 ASSERT_FALSE(test_window_tree()->last_hit_test_mask().has_value()); | |
| 131 } | |
| 132 | |
| 133 } // namespace aura | |
| OLD | NEW |