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 "ui/wm/core/ime_util_chromeos.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 #include "ui/aura/test/aura_test_base.h" | |
10 #include "ui/aura/test/test_windows.h" | |
11 #include "ui/base/ui_base_switches.h" | |
12 #include "ui/wm/core/default_screen_position_client.h" | |
13 | |
14 namespace wm { | |
15 | |
16 class ImeUtilChromeosTest : public aura::test::AuraTestBase { | |
17 public: | |
18 void SetUp() override { | |
19 AuraTestBase::SetUp(); | |
20 screen_position_client_ = base::MakeUnique<DefaultScreenPositionClient>(); | |
21 aura::client::SetScreenPositionClient(root_window(), | |
22 screen_position_client_.get()); | |
23 | |
24 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
25 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) | |
26 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); | |
27 } | |
28 | |
29 void TearDown() override { | |
30 aura::client::SetScreenPositionClient(root_window(), nullptr); | |
31 AuraTestBase::TearDown(); | |
32 } | |
33 | |
34 private: | |
35 std::unique_ptr<aura::client::ScreenPositionClient> screen_position_client_; | |
36 }; | |
sky
2017/04/28 20:17:51
DISALLOW...
yhanada
2017/05/01 09:12:48
Done.
| |
37 | |
38 TEST_F(ImeUtilChromeosTest, RestoreWindowBounds) { | |
39 const gfx::Rect bounds(10, 20, 100, 200); | |
40 aura::Window* window = | |
41 aura::test::CreateTestWindowWithBounds(bounds, root_window()); | |
42 | |
43 EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey)); | |
44 EXPECT_EQ(bounds, window->bounds()); | |
45 | |
46 RestoreWindowBoundsOnClientFocusLost(window); | |
47 EXPECT_EQ(bounds, window->bounds()); | |
48 | |
49 gfx::Rect r1(40, 50, 150, 200); | |
50 window->SetProperty(kVirtualKeyboardRestoreBoundsKey, new gfx::Rect(r1)); | |
51 RestoreWindowBoundsOnClientFocusLost(window); | |
52 EXPECT_EQ(r1, window->bounds()); | |
53 EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey)); | |
54 } | |
55 | |
56 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_NotCovered) { | |
57 const gfx::Rect bounds(0, 0, 100, 200); | |
58 aura::Window* window = | |
59 aura::test::CreateTestWindowWithBounds(bounds, root_window()); | |
60 EXPECT_EQ(bounds, window->bounds()); | |
61 EXPECT_EQ(bounds, window->GetBoundsInScreen()); | |
62 | |
63 // The rect doesn't overlap on the window. | |
64 gfx::Rect rect(300, 300, 100, 100); | |
65 EXPECT_TRUE(gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty()); | |
66 EnsureWindowNotInRect(window, rect); | |
67 // The bounds should not be changed. | |
68 EXPECT_EQ(bounds, window->bounds()); | |
69 EXPECT_EQ(bounds, window->GetBoundsInScreen()); | |
70 } | |
71 | |
72 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveUp) { | |
73 const gfx::Rect original_bounds(10, 100, 100, 10); | |
74 aura::Window* window = | |
75 aura::test::CreateTestWindowWithBounds(original_bounds, root_window()); | |
76 EXPECT_EQ(original_bounds, window->bounds()); | |
77 EXPECT_EQ(original_bounds, window->GetBoundsInScreen()); | |
78 | |
79 // The rect overlaps the window. The window is moved up by | |
80 // EnsureWindowNotInRect. | |
81 gfx::Rect rect(50, 50, 200, 200); | |
82 EXPECT_FALSE( | |
83 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty()); | |
84 EnsureWindowNotInRect(window, rect); | |
85 EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->bounds()); | |
86 EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->GetBoundsInScreen()); | |
87 } | |
88 | |
89 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveToTop) { | |
90 const gfx::Rect original_bounds(10, 10, 100, 100); | |
91 aura::Window* window = | |
92 aura::test::CreateTestWindowWithBounds(original_bounds, root_window()); | |
93 EXPECT_EQ(original_bounds, window->bounds()); | |
94 EXPECT_EQ(original_bounds, window->GetBoundsInScreen()); | |
95 | |
96 // The rect overlaps the window. The window is moved up by | |
97 // EnsureWinodwNotInRect, but there is not enough space above the window. | |
98 gfx::Rect rect(50, 50, 200, 200); | |
99 EXPECT_FALSE( | |
100 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty()); | |
101 EnsureWindowNotInRect(window, rect); | |
102 EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->bounds()); | |
103 EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->GetBoundsInScreen()); | |
104 } | |
105 | |
106 TEST_F(ImeUtilChromeosTest, MoveUpThenRestore) { | |
107 const gfx::Rect original_bounds(50, 50, 100, 100); | |
108 aura::Window* window = | |
109 aura::test::CreateTestWindowWithBounds(original_bounds, root_window()); | |
110 EXPECT_EQ(original_bounds, window->bounds()); | |
111 EXPECT_EQ(original_bounds, window->GetBoundsInScreen()); | |
112 | |
113 // EnsureWindowNotInRect moves up the window. | |
114 gfx::Rect rect(50, 50, 200, 200); | |
115 EXPECT_FALSE( | |
116 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty()); | |
117 EnsureWindowNotInRect(window, rect); | |
118 EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->bounds()); | |
119 EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->GetBoundsInScreen()); | |
120 | |
121 // The new rect doesn't overlap the moved window bounds, but still overlaps | |
122 // the original window bounds. | |
123 rect = gfx::Rect(50, 120, 200, 200); | |
124 EXPECT_FALSE(gfx::IntersectRects(rect, original_bounds).IsEmpty()); | |
125 EnsureWindowNotInRect(window, rect); | |
126 EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->bounds()); | |
127 EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->GetBoundsInScreen()); | |
128 | |
129 // Now the rect doesn't overlap the original window bounds. The original | |
130 // window bounds should be restored. | |
131 rect = gfx::Rect(200, 200, 200, 200); | |
132 EXPECT_TRUE(gfx::IntersectRects(rect, original_bounds).IsEmpty()); | |
133 EnsureWindowNotInRect(window, rect); | |
134 EXPECT_EQ(original_bounds, window->bounds()); | |
135 EXPECT_EQ(original_bounds, window->GetBoundsInScreen()); | |
136 } | |
137 | |
138 } // namespace wm | |
OLD | NEW |