Commit 4a572046 authored by evy@chromium.org's avatar evy@chromium.org

Added wrapper test class for touch_exploration_controller.

Wrapper class is currently located in the unittest file and is a friend of touch_exploration_controller.

BUG=377040

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=283741

Review URL: https://codereview.chromium.org/386043002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284483 0039d316-1c4b-4281-b951-d872f2087c98
parent 20c3df0f
......@@ -35,41 +35,10 @@ TouchExplorationController::TouchExplorationController(
root_window->GetHost()->GetEventSource()->AddEventRewriter(this);
}
TouchExplorationController::~TouchExplorationController() {
root_window_->GetHost()->GetEventSource()->RemoveEventRewriter(this);
}
void TouchExplorationController::CallTapTimerNowForTesting() {
DCHECK(tap_timer_.IsRunning());
tap_timer_.Stop();
OnTapTimerFired();
}
void TouchExplorationController::CallTapTimerNowIfRunningForTesting() {
if (tap_timer_.IsRunning()) {
tap_timer_.Stop();
OnTapTimerFired();
}
}
void TouchExplorationController::SetEventHandlerForTesting(
ui::EventHandler* event_handler_for_testing) {
event_handler_for_testing_ = event_handler_for_testing;
}
bool TouchExplorationController::IsInNoFingersDownStateForTesting() const {
return state_ == NO_FINGERS_DOWN;
}
bool TouchExplorationController::IsInGestureInProgressStateForTesting() const {
return state_ == GESTURE_IN_PROGRESS;
}
void TouchExplorationController::SuppressVLOGsForTesting(bool suppress) {
VLOG_on_ = !suppress;
}
ui::EventRewriteStatus TouchExplorationController::RewriteEvent(
const ui::Event& event,
scoped_ptr<ui::Event>* rewritten_event) {
......
......@@ -103,16 +103,9 @@ class UI_CHROMEOS_EXPORT TouchExplorationController
explicit TouchExplorationController(aura::Window* root_window);
virtual ~TouchExplorationController();
void CallTapTimerNowForTesting();
void CallTapTimerNowIfRunningForTesting();
void SetEventHandlerForTesting(ui::EventHandler* event_handler_for_testing);
bool IsInNoFingersDownStateForTesting() const;
bool IsInGestureInProgressStateForTesting() const;
// VLOGs should be suppressed in tests that generate a lot of logs,
// for example permutations of nine touch events.
void SuppressVLOGsForTesting(bool suppress);
private:
friend class TouchExplorationControllerTestApi;
// Overridden from ui::EventRewriter
virtual ui::EventRewriteStatus RewriteEvent(
const ui::Event& event,
......
......@@ -22,6 +22,7 @@
namespace ui {
namespace {
// Records all mouse, touch, gesture, and key events.
class EventCapturer : public ui::EventHandler {
public:
......@@ -73,6 +74,54 @@ int Factorial(int n) {
} // namespace
class TouchExplorationControllerTestApi {
public:
TouchExplorationControllerTestApi(
TouchExplorationController* touch_exploration_controller) {
touch_exploration_controller_.reset(touch_exploration_controller);
}
void CallTapTimerNowForTesting() {
DCHECK(touch_exploration_controller_->tap_timer_.IsRunning());
touch_exploration_controller_->tap_timer_.Stop();
touch_exploration_controller_->OnTapTimerFired();
}
void CallTapTimerNowIfRunningForTesting() {
if (touch_exploration_controller_->tap_timer_.IsRunning()) {
touch_exploration_controller_->tap_timer_.Stop();
touch_exploration_controller_->OnTapTimerFired();
}
}
void SetEventHandlerForTesting(
ui::EventHandler* event_handler_for_testing) {
touch_exploration_controller_->event_handler_for_testing_ =
event_handler_for_testing;
}
bool IsInNoFingersDownStateForTesting() const {
return touch_exploration_controller_->state_ ==
touch_exploration_controller_->NO_FINGERS_DOWN;
}
bool IsInGestureInProgressStateForTesting() const {
return touch_exploration_controller_->state_ ==
touch_exploration_controller_->GESTURE_IN_PROGRESS;
}
// VLOGs should be suppressed in tests that generate a lot of logs,
// for example permutations of nine touch events.
void SuppressVLOGsForTesting(bool suppress) {
touch_exploration_controller_->VLOG_on_ = !suppress;
}
private:
scoped_ptr<TouchExplorationController> touch_exploration_controller_;
DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi);
};
class TouchExplorationTest : public aura::test::AuraTestBase {
public:
TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) {
......@@ -163,8 +212,8 @@ class TouchExplorationTest : public aura::test::AuraTestBase {
if (!on && touch_exploration_controller_.get()) {
touch_exploration_controller_.reset();
} else if (on && !touch_exploration_controller_.get()) {
touch_exploration_controller_.reset(
new ui::TouchExplorationController(root_window()));
touch_exploration_controller_.reset(new TouchExplorationControllerTestApi(
new ui::TouchExplorationController(root_window())));
touch_exploration_controller_->SetEventHandlerForTesting(
&event_capturer_);
cursor_client()->ShowCursor();
......@@ -221,7 +270,8 @@ class TouchExplorationTest : public aura::test::AuraTestBase {
private:
EventCapturer event_capturer_;
scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_;
scoped_ptr<TouchExplorationControllerTestApi>
touch_exploration_controller_;
scoped_ptr<aura::test::TestCursorClient> cursor_client_;
DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment