keyboard_event_counter_unittest.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2016 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. #include "ui/events/keyboard_event_counter.h"
  5. #include <memory>
  6. #include "base/run_loop.h"
  7. #include "build/build_config.h"
  8. #include "testing/gmock/include/gmock/gmock.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace ui {
  11. TEST(KeyboardEventCounterTest, KeyPressCounter) {
  12. KeyboardEventCounter counter;
  13. EXPECT_EQ(0u, counter.GetKeyPressCount());
  14. counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
  15. EXPECT_EQ(1u, counter.GetKeyPressCount());
  16. // Holding the same key without releasing it does not increase the count.
  17. counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
  18. EXPECT_EQ(1u, counter.GetKeyPressCount());
  19. // Releasing the key does not affect the total count.
  20. counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0);
  21. EXPECT_EQ(1u, counter.GetKeyPressCount());
  22. counter.OnKeyboardEvent(ui::ET_KEY_PRESSED, ui::VKEY_0);
  23. counter.OnKeyboardEvent(ui::ET_KEY_RELEASED, ui::VKEY_0);
  24. EXPECT_EQ(2u, counter.GetKeyPressCount());
  25. }
  26. } // namespace ui