1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/ime_util_chromeos.h"
#include "base/command_line.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_windows.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/geometry/insets.h"
namespace wm {
using ImeUtilChromeosTest = aura::test::AuraTestBase;
TEST_F(ImeUtilChromeosTest, RestoreWindowBounds) {
const gfx::Rect bounds(10, 20, 100, 200);
aura::Window* window =
aura::test::CreateTestWindowWithBounds(bounds, root_window());
EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey));
EXPECT_EQ(bounds, window->bounds());
RestoreWindowBoundsOnClientFocusLost(window);
EXPECT_EQ(bounds, window->bounds());
gfx::Rect r1(40, 50, 150, 200);
window->SetProperty(kVirtualKeyboardRestoreBoundsKey, r1);
RestoreWindowBoundsOnClientFocusLost(window);
EXPECT_EQ(r1, window->bounds());
EXPECT_EQ(nullptr, window->GetProperty(kVirtualKeyboardRestoreBoundsKey));
}
TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_NotCovered) {
const gfx::Rect bounds(0, 0, 100, 200);
aura::Window* window =
aura::test::CreateTestWindowWithBounds(bounds, root_window());
EXPECT_EQ(bounds, window->bounds());
EXPECT_EQ(bounds, window->GetBoundsInScreen());
// The rect doesn't overlap on the window.
gfx::Rect rect(300, 300, 100, 100);
EXPECT_TRUE(gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
EnsureWindowNotInRect(window, rect);
// The bounds should not be changed.
EXPECT_EQ(bounds, window->bounds());
EXPECT_EQ(bounds, window->GetBoundsInScreen());
}
TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveUp) {
const gfx::Rect original_bounds(10, 100, 100, 10);
aura::Window* window =
aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
EXPECT_EQ(original_bounds, window->bounds());
EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
// The rect overlaps the window. The window is moved up by
// EnsureWindowNotInRect.
gfx::Rect rect(50, 50, 200, 200);
EXPECT_FALSE(
gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->bounds());
EXPECT_EQ(gfx::Rect(10, 40, 100, 10), window->GetBoundsInScreen());
}
TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRect_MoveToTop) {
const gfx::Rect original_bounds(10, 10, 100, 100);
aura::Window* window =
aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
EXPECT_EQ(original_bounds, window->bounds());
EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
// The rect overlaps the window. The window is moved up by
// EnsureWinodwNotInRect, but there is not enough space above the window.
gfx::Rect rect(50, 50, 200, 200);
EXPECT_FALSE(
gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->bounds());
EXPECT_EQ(gfx::Rect(10, 0, 100, 100), window->GetBoundsInScreen());
RestoreWindowBoundsOnClientFocusLost(window);
// Sets a workspace insets to simulate that something (such as docked
// magnifier) occupies some space on top. Original bounds must be inside
// the new work area.
constexpr int kOccupiedTopHeight = 5;
ASSERT_GE(original_bounds.y(), kOccupiedTopHeight);
test_screen()->SetWorkAreaInsets(
gfx::Insets::TLBR(kOccupiedTopHeight, 0, 0, 0));
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(gfx::Rect(10, kOccupiedTopHeight, 100, 100), window->bounds());
}
TEST_F(ImeUtilChromeosTest, MoveUpThenRestore) {
const gfx::Rect original_bounds(50, 50, 100, 100);
aura::Window* window =
aura::test::CreateTestWindowWithBounds(original_bounds, root_window());
EXPECT_EQ(original_bounds, window->bounds());
EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
// EnsureWindowNotInRect moves up the window.
gfx::Rect rect(50, 50, 200, 200);
EXPECT_FALSE(
gfx::IntersectRects(window->GetBoundsInScreen(), rect).IsEmpty());
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->bounds());
EXPECT_EQ(gfx::Rect(50, 0, 100, 100), window->GetBoundsInScreen());
// The new rect doesn't overlap the moved window bounds, but still overlaps
// the original window bounds.
rect = gfx::Rect(50, 120, 200, 200);
EXPECT_FALSE(gfx::IntersectRects(rect, original_bounds).IsEmpty());
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->bounds());
EXPECT_EQ(gfx::Rect(50, 20, 100, 100), window->GetBoundsInScreen());
// Now the rect doesn't overlap the original window bounds. The original
// window bounds should be restored.
rect = gfx::Rect(200, 200, 200, 200);
EXPECT_TRUE(gfx::IntersectRects(rect, original_bounds).IsEmpty());
EnsureWindowNotInRect(window, rect);
EXPECT_EQ(original_bounds, window->bounds());
EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
}
} // namespace wm
|