1 // Copyright (c) 2012 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 "chrome/browser/ui/gtk/event_utils.h" 6 7 #include "base/basictypes.h" 8 #include "base/strings/stringprintf.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "ui/events/event_constants.h" 11 12 namespace event_utils { 13 14 namespace { 15 16 const guint states[] = { 17 GDK_LOCK_MASK, 18 GDK_CONTROL_MASK, 19 GDK_SHIFT_MASK, 20 GDK_MOD1_MASK, 21 GDK_BUTTON1_MASK, 22 GDK_BUTTON2_MASK, 23 GDK_BUTTON3_MASK 24 }; 25 26 const int flags[] = { 27 ui::EF_CAPS_LOCK_DOWN, 28 ui::EF_CONTROL_DOWN, 29 ui::EF_SHIFT_DOWN, 30 ui::EF_ALT_DOWN, 31 ui::EF_LEFT_MOUSE_BUTTON, 32 ui::EF_MIDDLE_MOUSE_BUTTON, 33 ui::EF_RIGHT_MOUSE_BUTTON 34 }; 35 36 } // namespace 37 38 TEST(EventUtilsTest, EventFlagsFromGdkState) { 39 ASSERT_EQ(arraysize(states), arraysize(flags)); 40 41 const int size = arraysize(states); 42 for (int i = 0; i < size; ++i) { 43 SCOPED_TRACE(base::StringPrintf( 44 "Checking EventFlagsFromGdkState: i = %d", i)); 45 EXPECT_EQ(flags[i], EventFlagsFromGdkState(states[i])); 46 } 47 48 for (int i = 0; i < size; ++i) { 49 for (int j = i + 1; j < size; ++j) { 50 SCOPED_TRACE(base::StringPrintf( 51 "Checking EventFlagsFromGdkState: i = %d, j = %d", i, j)); 52 EXPECT_EQ(flags[i] | flags[j], 53 EventFlagsFromGdkState(states[i] | states[j])); 54 } 55 } 56 } 57 58 } // namespace event_utils 59