Chromium Code Reviews| Index: chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller_unittest.cc |
| diff --git a/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller_unittest.cc b/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..affd9b832aa96848419b74b1355012976a6d1f18 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller_unittest.cc |
| @@ -0,0 +1,111 @@ |
| +// Copyright 2016 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 "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller.h" |
| + |
| +#include <algorithm> |
| +#include <vector> |
| + |
| +#include "ash/shell.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/manager/display_manager.h" |
| +#include "ui/events/base_event_utils.h" |
| +#include "ui/events/event_handler.h" |
| +#include "ui/events/test/event_generator.h" |
| +#include "ui/events/test/events_test_utils.h" |
| + |
| +using namespace display; |
| + |
| +namespace chromeos { |
|
stevenjb
2016/12/22 01:14:21
nit: blank line
malaykeshav
2016/12/22 11:50:07
Done
|
| +namespace { |
| +const auto kTouchIntervalThreshold = base::TimeDelta::FromMilliseconds(200); |
|
stevenjb
2016/12/22 01:14:21
See other comment.
malaykeshav
2016/12/22 11:50:07
Removed.
|
| +} |
| + |
| +class TouchCalibratorControllerTest : public ash::test::AshTestBase { |
| + public: |
| + TouchCalibratorControllerTest() {} |
| + |
| + const Display& InitDisplays() { |
| + UpdateDisplay("500x500,500x500"); |
| + DisplayIdList display_id_list = |
| + display_manager()->GetCurrentDisplayIdList(); |
| + int64_t target_display_id = display_id_list[1]; |
|
stevenjb
2016/12/22 01:14:21
Why [1]? 1 should probably be a defined constant,
malaykeshav
2016/12/22 11:50:07
Initialized a constant instead of rvalue.
Through
|
| + const Display& touch_display = |
| + display_manager()->GetDisplayForId(target_display_id); |
| + return touch_display; |
| + } |
| + |
| + void StartCalibrationChecks(TouchCalibratorController* ctrl, |
| + const Display& target_display) { |
| + EXPECT_FALSE(ctrl->is_calibrating()); |
| + EXPECT_FALSE(!!ctrl->touch_calibrator_views_.size()); |
| + |
| + ctrl->StartCalibration(target_display); |
| + EXPECT_TRUE(ctrl->is_calibrating()); |
| + EXPECT_EQ(ctrl->touch_calibrator_views_.size(), 2UL); |
|
stevenjb
2016/12/22 01:14:21
2 should probably also be a constant.
malaykeshav
2016/12/22 11:50:07
Done
|
| + |
| + TouchCalibratorView* target_calibrator_view = |
| + ctrl->touch_calibrator_views_[target_display.id()].get(); |
| + |
| + EXPECT_EQ(target_calibrator_view->GetState(), TouchCalibratorView::UNKNOWN); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TouchCalibratorControllerTest); |
| +}; |
| + |
| +TEST_F(TouchCalibratorControllerTest, StartCalibration) { |
| + const Display& touch_display = InitDisplays(); |
| + TouchCalibratorController touch_calibrator_controller; |
| + StartCalibrationChecks(&touch_calibrator_controller, touch_display); |
| + |
| + ui::EventTargetTestApi test_api(ash::Shell::GetInstance()); |
| + const ui::EventHandlerList& handlers = test_api.pre_target_handlers(); |
| + ui::EventHandlerList::const_iterator event_target = |
| + std::find(handlers.begin(), handlers.end(), &touch_calibrator_controller); |
| + EXPECT_NE(event_target, handlers.end()); |
| +} |
| + |
| +TEST_F(TouchCalibratorControllerTest, KeyEventIntercept) { |
| + const Display& touch_display = InitDisplays(); |
| + TouchCalibratorController touch_calibrator_controller; |
| + StartCalibrationChecks(&touch_calibrator_controller, touch_display); |
| + |
| + ui::test::EventGenerator& eg = GetEventGenerator(); |
| + EXPECT_TRUE(touch_calibrator_controller.is_calibrating()); |
| + eg.PressKey(ui::VKEY_ESCAPE, ui::EF_NONE); |
| + EXPECT_FALSE(touch_calibrator_controller.is_calibrating()); |
| +} |
| + |
| +TEST_F(TouchCalibratorControllerTest, TouchThreshold) { |
| + const Display& touch_display = InitDisplays(); |
| + TouchCalibratorController touch_calibrator_controller; |
| + StartCalibrationChecks(&touch_calibrator_controller, touch_display); |
| + |
| + ui::test::EventGenerator& eg = GetEventGenerator(); |
| + |
| + base::Time current_timestamp = base::Time::Now(); |
| + touch_calibrator_controller.last_touch_timestamp_ = current_timestamp; |
| + |
| + eg.set_current_location(gfx::Point(0, 0)); |
| + eg.PressTouch(); |
| + eg.ReleaseTouch(); |
| + |
| + EXPECT_EQ(touch_calibrator_controller.last_touch_timestamp_, |
| + current_timestamp); |
| + |
| + current_timestamp = base::Time::Now(); |
| + touch_calibrator_controller.last_touch_timestamp_ = |
| + current_timestamp - (kTouchIntervalThreshold * 2); |
| + |
| + eg.PressTouch(); |
| + eg.ReleaseTouch(); |
| + |
| + EXPECT_LT(current_timestamp, |
| + touch_calibrator_controller.last_touch_timestamp_); |
| +} |
| + |
| +} // namespace chromeos |