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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: athena/screen/screen_manager_unittest.cc
diff --git a/athena/screen/screen_manager_unittest.cc b/athena/screen/screen_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..08dff84afb8b7a83adcbabe1b5901302a71ba769
--- /dev/null
+++ b/athena/screen/screen_manager_unittest.cc
@@ -0,0 +1,115 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/screen/public/screen_manager.h"
+
+#include <algorithm>
+
+#include "athena/test/athena_test_base.h"
+#include "ui/aura/test/event_generator.h"
+#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/window.h"
+#include "ui/wm/core/window_util.h"
+
+namespace athena {
+
+typedef test::AthenaTestBase ScreenManagerTest;
+
+aura::Window* CreateTestWindow(aura::Window* container,
+ aura::WindowDelegate* delegate,
+ const gfx::Rect& bounds) {
+ aura::Window* window = new aura::Window(delegate);
+ window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
+ window->Init(aura::WINDOW_LAYER_TEXTURED);
+ container->AddChild(window);
+ window->Show();
+ window->SetBounds(bounds);
+ return window;
+}
+
+TEST_F(ScreenManagerTest, CreateContainer) {
+ size_t num_containers = root_window()->children().size();
+
+ aura::Window* container = ScreenManager::Get()->CreateContainer(
+ ScreenManager::ContainerParams("test"));
+ EXPECT_EQ("test", container->name());
+
+ const aura::Window::Windows& containers = root_window()->children();
+ EXPECT_EQ(num_containers + 1, containers.size());
+ EXPECT_NE(containers.end(),
+ std::find(containers.begin(), containers.end(), container));
+}
+
+TEST_F(ScreenManagerTest, NonActivatableContainer) {
+ ScreenManager::ContainerParams non_activatable("non_activatable");
+ non_activatable.can_activate_children = false;
+ aura::Window* no_activatable_container =
+ ScreenManager::Get()->CreateContainer(non_activatable);
+
+ ScreenManager::ContainerParams activatable("activatable");
+ activatable.can_activate_children = true;
+ aura::Window* activatable_container =
+ ScreenManager::Get()->CreateContainer(activatable);
+
+ scoped_ptr<aura::Window> window(CreateTestWindow(
+ no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100)));
+ EXPECT_FALSE(wm::CanActivateWindow(window.get()));
+
+ activatable_container->AddChild(window.get());
+ EXPECT_TRUE(wm::CanActivateWindow(window.get()));
+}
+
+TEST_F(ScreenManagerTest, GrabInputContainer) {
+ ScreenManager::ContainerParams normal_params("normal");
+ normal_params.can_activate_children = true;
+ aura::Window* normal_container =
+ ScreenManager::Get()->CreateContainer(normal_params);
+
+ aura::test::EventCountDelegate normal_delegate;
+ scoped_ptr<aura::Window> normal_window(CreateTestWindow(
+ normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100)));
+
+ EXPECT_TRUE(wm::CanActivateWindow(normal_window.get()));
+ wm::ActivateWindow(normal_window.get());
+ aura::test::EventGenerator event_generator(root_window());
+ event_generator.MoveMouseTo(0, 0);
+ event_generator.ClickLeftButton();
+ EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset());
+ event_generator.PressKey(ui::VKEY_A, ui::EF_NONE);
+ event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
+ EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset());
+
+ ScreenManager::ContainerParams grab_params("grabbing");
+ grab_params.can_activate_children = true;
+ grab_params.grab_inputs = true;
+ aura::Window* grab_container =
+ ScreenManager::Get()->CreateContainer(grab_params);
+
+ EXPECT_FALSE(wm::CanActivateWindow(normal_window.get()));
+
+ aura::test::EventCountDelegate grab_delegate;
+ scoped_ptr<aura::Window> grab_window(CreateTestWindow(
+ grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100)));
+ EXPECT_TRUE(wm::CanActivateWindow(grab_window.get()));
+
+ wm::ActivateWindow(grab_window.get());
+
+ // (0, 0) is still on normal_window, but the event should not go there
+ // because grabbing_container prevents it.
+ event_generator.MoveMouseTo(0, 0);
+ event_generator.ClickLeftButton();
+ EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset());
+ EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset());
+
+ event_generator.MoveMouseTo(20, 20);
+ event_generator.ClickLeftButton();
+ EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset());
+
+ event_generator.PressKey(ui::VKEY_A, ui::EF_NONE);
+ event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
+ EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset());
+ EXPECT_EQ("1 1", grab_delegate.GetKeyCountsAndReset());
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698