blob: 300940c288ee5d0b45315203dd2ad8fdc7d582e0 [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"
10#include "ui/compositor/layer_type.h"
11
12namespace ash {
13namespace wm {
14
15using WindowFinderTest = AshTestBase;
16
17TEST_F(WindowFinderTest, FindTopmostWindows) {
18 std::unique_ptr<aura::Window> window1 =
19 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
20 std::unique_ptr<aura::Window> window2 =
21 CreateTestWindow(gfx::Rect(50, 0, 100, 100));
22 std::unique_ptr<aura::Window> window3 =
23 CreateTestWindow(gfx::Rect(0, 50, 100, 100));
24
25 // Those windows shouldn't be LAYER_TEXTURED -- to check the behavior of
26 // IsTopLevelWindow().
27 ASSERT_NE(ui::LAYER_TEXTURED, window1->layer()->type());
28 ASSERT_NE(ui::LAYER_TEXTURED, window2->layer()->type());
29 ASSERT_NE(ui::LAYER_TEXTURED, window3->layer()->type());
30
31 std::set<aura::Window*> ignore;
32 ignore.insert(window3.get());
33
34 aura::Window* real_topmost = nullptr;
35 EXPECT_EQ(window1.get(),
36 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost));
37 EXPECT_EQ(window1.get(), real_topmost);
38
39 EXPECT_EQ(window2.get(),
40 GetTopmostWindowAtPoint(gfx::Point(60, 10), ignore, &real_topmost));
41 EXPECT_EQ(window2.get(), real_topmost);
42
43 EXPECT_EQ(window2.get(),
44 GetTopmostWindowAtPoint(gfx::Point(60, 60), ignore, &real_topmost));
45 EXPECT_EQ(window3.get(), real_topmost);
46
47 EXPECT_EQ(window1.get(),
48 GetTopmostWindowAtPoint(gfx::Point(10, 60), ignore, &real_topmost));
49 EXPECT_EQ(window3.get(), real_topmost);
50
51 window1->parent()->StackChildAtTop(window1.get());
52 EXPECT_EQ(window1.get(),
53 GetTopmostWindowAtPoint(gfx::Point(60, 10), ignore, &real_topmost));
54 EXPECT_EQ(window1.get(), real_topmost);
55
56 ignore.clear();
57 ignore.insert(window1.get());
58 aura::Window* wallpaper_container = Shell::GetContainer(
59 Shell::GetPrimaryRootWindow(), kShellWindowId_WallpaperContainer);
60 aura::Window* topmost =
61 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, &real_topmost);
62 EXPECT_TRUE(wallpaper_container->Contains(topmost));
63 EXPECT_EQ(ui::LAYER_TEXTURED, topmost->layer()->type());
64 EXPECT_EQ(window1.get(), real_topmost);
65}
66
67TEST_F(WindowFinderTest, RealTopmostCanBeNullptr) {
68 std::unique_ptr<aura::Window> window1 =
69 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
70 std::set<aura::Window*> ignore;
71
72 EXPECT_EQ(window1.get(),
73 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, nullptr));
74}
75
76TEST_F(WindowFinderTest, MultipleDisplays) {
77 UpdateDisplay("200x200,300x300");
78
79 std::unique_ptr<aura::Window> window1 =
80 CreateTestWindow(gfx::Rect(0, 0, 100, 100));
81 std::unique_ptr<aura::Window> window2 =
82 CreateTestWindow(gfx::Rect(200, 0, 100, 100));
83 ASSERT_NE(window1->GetRootWindow(), window2->GetRootWindow());
84
85 std::set<aura::Window*> ignore;
86 EXPECT_EQ(window1.get(),
87 GetTopmostWindowAtPoint(gfx::Point(10, 10), ignore, nullptr));
88 EXPECT_EQ(window2.get(),
89 GetTopmostWindowAtPoint(gfx::Point(210, 10), ignore, nullptr));
90 EXPECT_EQ(nullptr,
91 GetTopmostWindowAtPoint(gfx::Point(10, 210), ignore, nullptr));
92}
93
94} // namespace wm
95} // namespace ash