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

Side by Side Diff: ui/wm/core/ime_util_chromeos_unittest.cc

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « ui/wm/core/ime_util_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 ImeUtilChromeosTest() = default;
19 ~ImeUtilChromeosTest() override = default;
20
21 void SetUp() override {
22 AuraTestBase::SetUp();
23 screen_position_client_ = base::MakeUnique<DefaultScreenPositionClient>();
24 aura::client::SetScreenPositionClient(root_window(),
25 screen_position_client_.get());
26
27 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
28 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior))
29 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior);
30 }
31
32 void TearDown() override {
33 aura::client::SetScreenPositionClient(root_window(), nullptr);
34 AuraTestBase::TearDown();
35 }
36
37 private:
38 std::unique_ptr<aura::client::ScreenPositionClient> screen_position_client_;
39
40 DISALLOW_COPY_AND_ASSIGN(ImeUtilChromeosTest);
41 };
42
43 TEST_F(ImeUtilChromeosTest, RestoreWindowBounds) {
44 const gfx::Rect bounds(10, 20, 100, 200);
45 aura::Window* window =
46 aura::test::CreateTestWindowWithBounds(bounds, root_window());
47
48 EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey));
49 EXPECT_EQ(bounds, window->bounds());
50
51 RestoreWindowBoundsOnClientFocusLost(window);
52 EXPECT_EQ(bounds, window->bounds());
53
54 gfx::Rect r1(40, 50, 150, 200);
55 window->SetProperty(kVirtualKeyboardRestoreBoundsKey, new gfx::Rect(r1));
56 RestoreWindowBoundsOnClientFocusLost(window);
57 EXPECT_EQ(r1, window->bounds());
58 EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey));
59 }
60
61 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_NotCovered) {
62 const gfx::Rect bounds(0, 0, 100, 200);
63 aura::Window* window =
64 aura::test::CreateTestWindowWithBounds(bounds, root_window());
65 EXPECT_EQ(bounds, window->bounds());
66 EXPECT_EQ(bounds, window->GetBoundsInScreen());
67
68 // The rect doesn't overlap on the window.
69 gfx::Rect rect(300, 300, 100, 100);
70 EXPECT_TRUE(gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
71 EnsureWindowNotInRect(window, rect);
72 // The bounds should not be changed.
73 EXPECT_EQ(bounds, window->bounds());
74 EXPECT_EQ(bounds, window->GetBoundsInScreen());
75 }
76
77 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveUp) {
78 const gfx::Rect original_bounds(10, 100, 100, 10);
79 aura::Window* window =
80 aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
81 EXPECT_EQ(original_bounds, window->bounds());
82 EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
83
84 // The rect overlaps the window. The window is moved up by
85 // EnsureWindowNotInRect.
86 gfx::Rect rect(50, 50, 200, 200);
87 EXPECT_FALSE(
88 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
89 EnsureWindowNotInRect(window, rect);
90 EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->bounds());
91 EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->GetBoundsInScreen());
92 }
93
94 TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveToTop) {
95 const gfx::Rect original_bounds(10, 10, 100, 100);
96 aura::Window* window =
97 aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
98 EXPECT_EQ(original_bounds, window->bounds());
99 EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
100
101 // The rect overlaps the window. The window is moved up by
102 // EnsureWinodwNotInRect, but there is not enough space above the window.
103 gfx::Rect rect(50, 50, 200, 200);
104 EXPECT_FALSE(
105 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
106 EnsureWindowNotInRect(window, rect);
107 EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->bounds());
108 EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->GetBoundsInScreen());
109 }
110
111 TEST_F(ImeUtilChromeosTest, MoveUpThenRestore) {
112 const gfx::Rect original_bounds(50, 50, 100, 100);
113 aura::Window* window =
114 aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
115 EXPECT_EQ(original_bounds, window->bounds());
116 EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
117
118 // EnsureWindowNotInRect moves up the window.
119 gfx::Rect rect(50, 50, 200, 200);
120 EXPECT_FALSE(
121 gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
122 EnsureWindowNotInRect(window, rect);
123 EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->bounds());
124 EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->GetBoundsInScreen());
125
126 // The new rect doesn't overlap the moved window bounds, but still overlaps
127 // the original window bounds.
128 rect = gfx::Rect(50, 120, 200, 200);
129 EXPECT_FALSE(gfx::IntersectRects(rect, original_bounds).IsEmpty());
130 EnsureWindowNotInRect(window, rect);
131 EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->bounds());
132 EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->GetBoundsInScreen());
133
134 // Now the rect doesn't overlap the original window bounds. The original
135 // window bounds should be restored.
136 rect = gfx::Rect(200, 200, 200, 200);
137 EXPECT_TRUE(gfx::IntersectRects(rect, original_bounds).IsEmpty());
138 EnsureWindowNotInRect(window, rect);
139 EXPECT_EQ(original_bounds, window->bounds());
140 EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
141 }
142
143 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/ime_util_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698