keyboard_ui_model_unittest.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2019 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 "ash/keyboard/ui/keyboard_ui_model.h"
  5. #include "base/test/metrics/histogram_tester.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace keyboard {
  8. TEST(KeyboardUIModelTest, ChangeToValidStateRecordsPositiveHistogram) {
  9. base::HistogramTester histogram_tester;
  10. KeyboardUIModel model;
  11. ASSERT_EQ(KeyboardUIState::kInitial, model.state());
  12. model.ChangeState(KeyboardUIState::kLoading);
  13. histogram_tester.ExpectUniqueSample(
  14. "VirtualKeyboard.ControllerStateTransition",
  15. GetStateTransitionHash(KeyboardUIState::kInitial,
  16. KeyboardUIState::kLoading),
  17. 1);
  18. }
  19. // Test fails DCHECK when the state transition is invalid. This is expected.
  20. #if !DCHECK_IS_ON()
  21. TEST(KeyboardUIModelTest, ChangeToInvalidStateRecordsNegativeHistogram) {
  22. base::HistogramTester histogram_tester;
  23. KeyboardUIModel model;
  24. ASSERT_EQ(KeyboardUIState::kInitial, model.state());
  25. model.ChangeState(KeyboardUIState::kShown);
  26. histogram_tester.ExpectUniqueSample(
  27. "VirtualKeyboard.ControllerStateTransition",
  28. -GetStateTransitionHash(KeyboardUIState::kInitial,
  29. KeyboardUIState::kShown),
  30. 1);
  31. }
  32. #endif
  33. } // namespace keyboard