Index: ui/aura/desktop_unittest.cc |
diff --git a/ui/aura/desktop_unittest.cc b/ui/aura/desktop_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cac63dbffa230a1580a9aaf9fcbf29010e0224a9 |
--- /dev/null |
+++ b/ui/aura/desktop_unittest.cc |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2011 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 "ui/aura/desktop.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/aura/event.h" |
+#include "ui/aura/test/aura_test_base.h" |
+#include "ui/aura/test/event_generator.h" |
+ |
+namespace aura { |
+namespace test { |
+ |
+typedef AuraTestBase DesktopTest; |
+ |
+// Check that we correctly track the state of the mouse buttons in response to |
+// button press and release events. |
+TEST_F(DesktopTest, MouseButtonState) { |
+ Desktop* desktop = Desktop::GetInstance(); |
+ EXPECT_FALSE(desktop->IsMouseButtonDown()); |
+ |
+ gfx::Point location; |
+ scoped_ptr<MouseEvent> event; |
+ |
+ // Press the left button. |
+ event.reset(new MouseEvent( |
+ ui::ET_MOUSE_PRESSED, |
+ location, |
+ ui::EF_LEFT_BUTTON_DOWN)); |
+ desktop->DispatchMouseEvent(event.get()); |
+ EXPECT_TRUE(desktop->IsMouseButtonDown()); |
+ |
+ // Additionally press the right. |
+ event.reset(new MouseEvent( |
+ ui::ET_MOUSE_PRESSED, |
+ location, |
+ ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); |
+ desktop->DispatchMouseEvent(event.get()); |
+ EXPECT_TRUE(desktop->IsMouseButtonDown()); |
+ |
+ // Release the left button. |
+ event.reset(new MouseEvent( |
+ ui::ET_MOUSE_RELEASED, |
+ location, |
+ ui::EF_RIGHT_BUTTON_DOWN)); |
+ desktop->DispatchMouseEvent(event.get()); |
+ EXPECT_TRUE(desktop->IsMouseButtonDown()); |
+ |
+ // Release the right button. We should ignore the Shift-is-down flag. |
+ event.reset(new MouseEvent( |
+ ui::ET_MOUSE_RELEASED, |
+ location, |
+ ui::EF_SHIFT_DOWN)); |
+ desktop->DispatchMouseEvent(event.get()); |
+ EXPECT_FALSE(desktop->IsMouseButtonDown()); |
+ |
+ // Press the middle button. |
+ event.reset(new MouseEvent( |
+ ui::ET_MOUSE_PRESSED, |
+ location, |
+ ui::EF_MIDDLE_BUTTON_DOWN)); |
+ desktop->DispatchMouseEvent(event.get()); |
+ EXPECT_TRUE(desktop->IsMouseButtonDown()); |
+} |
+ |
+} // namespace test |
+} // namespace aura |