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

Side by Side Diff: athena/screen/screen_manager_unittest.cc

Issue 414903002: Introduce 'grab_inputs' property for athena container. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "athena/screen/public/screen_manager.h"
6
7 #include <algorithm>
8
9 #include "athena/test/athena_test_base.h"
10 #include "ui/aura/test/event_generator.h"
11 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/window.h"
13 #include "ui/wm/core/window_util.h"
14
15 namespace athena {
16
17 typedef test::AthenaTestBase ScreenManagerTest;
18
19 aura::Window* CreateTestWindow(aura::Window* container,
20 aura::WindowDelegate* delegate,
21 const gfx::Rect& bounds) {
22 aura::Window* window = new aura::Window(delegate);
23 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
24 window->Init(aura::WINDOW_LAYER_TEXTURED);
25 container->AddChild(window);
26 window->Show();
27 window->SetBounds(bounds);
28 return window;
29 }
30
31 TEST_F(ScreenManagerTest, CreateContainer) {
32 size_t num_containers = root_window()->children().size();
33
34 aura::Window* container = ScreenManager::Get()->CreateContainer(
35 ScreenManager::ContainerParams("test"));
36 EXPECT_EQ("test", container->name());
37
38 const aura::Window::Windows& containers = root_window()->children();
39 EXPECT_EQ(num_containers + 1, containers.size());
40 EXPECT_NE(containers.end(),
41 std::find(containers.begin(), containers.end(), container));
42 }
43
44 TEST_F(ScreenManagerTest, NonActivatableContainer) {
45 ScreenManager::ContainerParams non_activatable("non_activatable");
46 non_activatable.can_activate_children = false;
47 aura::Window* no_activatable_container =
48 ScreenManager::Get()->CreateContainer(non_activatable);
49
50 ScreenManager::ContainerParams activatable("activatable");
51 activatable.can_activate_children = true;
52 aura::Window* activatable_container =
53 ScreenManager::Get()->CreateContainer(activatable);
54
55 scoped_ptr<aura::Window> window(CreateTestWindow(
56 no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100)));
57 EXPECT_FALSE(wm::CanActivateWindow(window.get()));
58
59 activatable_container->AddChild(window.get());
60 EXPECT_TRUE(wm::CanActivateWindow(window.get()));
61 }
62
63 TEST_F(ScreenManagerTest, GrabInputContainer) {
64 ScreenManager::ContainerParams normal_params("normal");
65 normal_params.can_activate_children = true;
66 aura::Window* normal_container =
67 ScreenManager::Get()->CreateContainer(normal_params);
68
69 aura::test::EventCountDelegate normal_delegate;
70 scoped_ptr<aura::Window> normal_window(CreateTestWindow(
71 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100)));
72
73 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get()));
74 wm::ActivateWindow(normal_window.get());
75 aura::test::EventGenerator event_generator(root_window());
76 event_generator.MoveMouseTo(0, 0);
77 event_generator.ClickLeftButton();
78 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset());
79 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE);
80 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
81 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset());
82
83 ScreenManager::ContainerParams grab_params("grabbing");
84 grab_params.can_activate_children = true;
85 grab_params.grab_inputs = true;
86 aura::Window* grab_container =
87 ScreenManager::Get()->CreateContainer(grab_params);
88
89 EXPECT_FALSE(wm::CanActivateWindow(normal_window.get()));
90
91 aura::test::EventCountDelegate grab_delegate;
92 scoped_ptr<aura::Window> grab_window(CreateTestWindow(
93 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100)));
94 EXPECT_TRUE(wm::CanActivateWindow(grab_window.get()));
95
96 wm::ActivateWindow(grab_window.get());
97
98 // (0, 0) is still on normal_window, but the event should not go there
99 // because grabbing_container prevents it.
100 event_generator.MoveMouseTo(0, 0);
101 event_generator.ClickLeftButton();
102 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset());
103 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset());
104
105 event_generator.MoveMouseTo(20, 20);
106 event_generator.ClickLeftButton();
107 EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset());
108
109 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE);
110 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
111 EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset());
112 EXPECT_EQ("1 1", grab_delegate.GetKeyCountsAndReset());
113 }
114
115 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698