blob: 3799fe13107575c50ae1fa0a1d87e9956c5cab78 [file] [log] [blame]
Jun Mukai6c0f9aa2018-08-11 01:09:551// Copyright 2018 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 "ash/wm/window_finder.h"
6
7#include "ash/public/cpp/shell_window_ids.h"
8#include "ash/shell.h"
9#include "ash/test/ash_test_base.h"
Jun Mukaia69663772018-11-06 22:29:0210#include "ui/aura/window_targeter.h"
Jun Mukai6c0f9aa2018-08-11 01:09:5511#include "ui/compositor/layer_type.h"
Jun Mukaia69663772018-11-06 22:29:0212#include "ui/gfx/geometry/insets.h"
Jun Mukai6c0f9aa2018-08-11 01:09:5513
14namespace ash {
15namespace wm {
16
17using WindowFinderTest = AshTestBase;
18
19TEST_F(WindowFinderTest, FindTopmostWindows) {
20 std::unique_ptr<aura::Window> window1 =
21 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
22 std::unique_ptr<aura::Window> window2 =
23 CreateTestWindow(gfx::Rect(50, 0, 100, 100));
24 std::unique_ptr<aura::Window> window3 =
25 CreateTestWindow(gfx::Rect(0, 50, 100, 100));
26
27 // Those windows shouldn't be LAYER_TEXTURED -- to check the behavior of
28 // IsTopLevelWindow().
29 ASSERT_NE(ui::LAYER_TEXTURED, window1->layer()->type());
30 ASSERT_NE(ui::LAYER_TEXTURED, window2->layer()->type());
31 ASSERT_NE(ui::LAYER_TEXTURED, window3->layer()->type());
32
33 std::set<aura::Window*> ignore;
34 ignore.insert(window3.get());
35
36 aura::Window* real_topmost = nullptr;
37 EXPECT_EQ(window1.get(),
38 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost));
39 EXPECT_EQ(window1.get(), real_topmost);
40
41 EXPECT_EQ(window2.get(),
42 GetTopmostWindowAtPoint(gfx::Point(60, 10), ignore, &real_topmost));
43 EXPECT_EQ(window2.get(), real_topmost);
44
45 EXPECT_EQ(window2.get(),
46 GetTopmostWindowAtPoint(gfx::Point(60, 60), ignore, &real_topmost));
47 EXPECT_EQ(window3.get(), real_topmost);
48
49 EXPECT_EQ(window1.get(),
50 GetTopmostWindowAtPoint(gfx::Point(10, 60), ignore, &real_topmost));
51 EXPECT_EQ(window3.get(), real_topmost);
52
53 window1->parent()->StackChildAtTop(window1.get());
54 EXPECT_EQ(window1.get(),
55 GetTopmostWindowAtPoint(gfx::Point(60, 10), ignore, &real_topmost));
56 EXPECT_EQ(window1.get(), real_topmost);
57
58 ignore.clear();
59 ignore.insert(window1.get());
60 aura::Window* wallpaper_container = Shell::GetContainer(
61 Shell::GetPrimaryRootWindow(), kShellWindowId_WallpaperContainer);
62 aura::Window* topmost =
63 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost);
64 EXPECT_TRUE(wallpaper_container->Contains(topmost));
65 EXPECT_EQ(ui::LAYER_TEXTURED, topmost->layer()->type());
66 EXPECT_EQ(window1.get(), real_topmost);
67}
68
69TEST_F(WindowFinderTest, RealTopmostCanBeNullptr) {
70 std::unique_ptr<aura::Window> window1 =
71 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
72 std::set<aura::Window*> ignore;
73
74 EXPECT_EQ(window1.get(),
75 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, nullptr));
76}
77
78TEST_F(WindowFinderTest, MultipleDisplays) {
79 UpdateDisplay("200x200,300x300");
80
81 std::unique_ptr<aura::Window> window1 =
82 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
83 std::unique_ptr<aura::Window> window2 =
84 CreateTestWindow(gfx::Rect(200, 0, 100, 100));
85 ASSERT_NE(window1->GetRootWindow(), window2->GetRootWindow());
86
87 std::set<aura::Window*> ignore;
88 EXPECT_EQ(window1.get(),
89 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, nullptr));
90 EXPECT_EQ(window2.get(),
91 GetTopmostWindowAtPoint(gfx::Point(210, 10), ignore, nullptr));
92 EXPECT_EQ(nullptr,
93 GetTopmostWindowAtPoint(gfx::Point(10, 210), ignore, nullptr));
94}
95
Jun Mukaia69663772018-11-06 22:29:0296TEST_F(WindowFinderTest, WindowTargeterWithHitTestRects) {
97 std::unique_ptr<aura::Window> window1 =
98 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
99 std::unique_ptr<aura::Window> window2 =
100 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
101
102 std::set<aura::Window*> ignore;
103
104 aura::Window* real_topmost = nullptr;
105 EXPECT_EQ(window2.get(),
106 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost));
107 EXPECT_EQ(window2.get(), real_topmost);
108
109 auto targeter = std::make_unique<aura::WindowTargeter>();
110 targeter->SetInsets(gfx::Insets(0, 50, 0, 0));
111 window2->SetEventTargeter(std::move(targeter));
112
113 EXPECT_EQ(window1.get(),
114 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost));
115 EXPECT_EQ(window1.get(), real_topmost);
116 EXPECT_EQ(window2.get(),
117 GetTopmostWindowAtPoint(gfx::Point(60, 10), ignore, &real_topmost));
118 EXPECT_EQ(window2.get(), real_topmost);
119}
120
Jun Mukai6c0f9aa2018-08-11 01:09:55121} // namespace wm
122} // namespace ash