Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 2886283004: input: Fix running the completion callback for telemetry gesture. (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 653 }
654 return testing::AssertionSuccess(); 654 return testing::AssertionSuccess();
655 } 655 }
656 656
657 private: 657 private:
658 gfx::PointF position_; 658 gfx::PointF position_;
659 int clickCount_; 659 int clickCount_;
660 WebMouseEvent::Button button_; 660 WebMouseEvent::Button button_;
661 }; 661 };
662 662
663 class DummySyntheticGestureControllerDelegate
664 : public SyntheticGestureController::Delegate {
665 public:
666 DummySyntheticGestureControllerDelegate() {}
667 ~DummySyntheticGestureControllerDelegate() override {}
668
669 private:
670 // SyntheticGestureController::Delegate:
671 void RequestBeginFrameForSynthesizedInput(
672 base::OnceClosure callback) override {}
673 bool HasGestureStopped() override { return true; }
674
675 DISALLOW_COPY_AND_ASSIGN(DummySyntheticGestureControllerDelegate);
676 };
677
663 class SyntheticGestureControllerTestBase { 678 class SyntheticGestureControllerTestBase {
664 public: 679 public:
665 SyntheticGestureControllerTestBase() {} 680 SyntheticGestureControllerTestBase() {}
666 ~SyntheticGestureControllerTestBase() {} 681 ~SyntheticGestureControllerTestBase() {}
667 682
668 protected: 683 protected:
669 template<typename MockGestureTarget> 684 template<typename MockGestureTarget>
670 void CreateControllerAndTarget() { 685 void CreateControllerAndTarget() {
671 target_ = new MockGestureTarget(); 686 target_ = new MockGestureTarget();
672 controller_ = base::MakeUnique<SyntheticGestureController>( 687 controller_ = base::MakeUnique<SyntheticGestureController>(
673 std::unique_ptr<SyntheticGestureTarget>(target_), 688 &delegate_, std::unique_ptr<SyntheticGestureTarget>(target_));
674 base::Bind([](base::OnceClosure callback) {}));
675 } 689 }
676 690
677 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) { 691 void QueueSyntheticGesture(std::unique_ptr<SyntheticGesture> gesture) {
678 controller_->QueueSyntheticGesture( 692 controller_->QueueSyntheticGesture(
679 std::move(gesture), 693 std::move(gesture),
680 base::Bind( 694 base::Bind(
681 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted, 695 &SyntheticGestureControllerTestBase::OnSyntheticGestureCompleted,
682 base::Unretained(this))); 696 base::Unretained(this)));
683 } 697 }
684 698
685 void FlushInputUntilComplete() { 699 void FlushInputUntilComplete() {
686 do 700 do
687 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs); 701 time_ += base::TimeDelta::FromMilliseconds(kFlushInputRateInMs);
688 while (controller_->DispatchNextEvent(time_)); 702 while (controller_->DispatchNextEvent(time_));
689 } 703 }
690 704
691 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) { 705 void OnSyntheticGestureCompleted(SyntheticGesture::Result result) {
692 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); 706 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING);
693 if (result == SyntheticGesture::GESTURE_FINISHED) 707 if (result == SyntheticGesture::GESTURE_FINISHED)
694 num_success_++; 708 num_success_++;
695 else 709 else
696 num_failure_++; 710 num_failure_++;
697 } 711 }
698 712
699 base::TimeDelta GetTotalTime() const { return time_ - start_time_; } 713 base::TimeDelta GetTotalTime() const { return time_ - start_time_; }
700 714
701 MockSyntheticGestureTarget* target_; 715 MockSyntheticGestureTarget* target_;
716 DummySyntheticGestureControllerDelegate delegate_;
702 std::unique_ptr<SyntheticGestureController> controller_; 717 std::unique_ptr<SyntheticGestureController> controller_;
703 base::TimeTicks start_time_; 718 base::TimeTicks start_time_;
704 base::TimeTicks time_; 719 base::TimeTicks time_;
705 int num_success_; 720 int num_success_;
706 int num_failure_; 721 int num_failure_;
707 }; 722 };
708 723
709 class SyntheticGestureControllerTest 724 class SyntheticGestureControllerTest
710 : public SyntheticGestureControllerTestBase, 725 : public SyntheticGestureControllerTestBase,
711 public testing::Test { 726 public testing::Test {
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 EXPECT_EQ(4, num_success_); 1757 EXPECT_EQ(4, num_success_);
1743 EXPECT_EQ(0, num_failure_); 1758 EXPECT_EQ(0, num_failure_);
1744 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4); 1759 EXPECT_EQ(pointer_mouse_target->num_actions_dispatched(), 4);
1745 EXPECT_TRUE( 1760 EXPECT_TRUE(
1746 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1)); 1761 pointer_mouse_target->SyntheticMouseActionDispatchedCorrectly(param, 1));
1747 } 1762 }
1748 1763
1749 } // namespace 1764 } // namespace
1750 1765
1751 } // namespace content 1766 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698