| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/renderer_host/input/gesture_text_selector.h" | 10 #include "content/browser/renderer_host/input/gesture_text_selector.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/events/event_constants.h" | 12 #include "ui/events/event_constants.h" |
| 13 #include "ui/events/gesture_detection/motion_event.h" | 13 #include "ui/events/gesture_detection/motion_event.h" |
| 14 #include "ui/events/test/mock_motion_event.h" | 14 #include "ui/events/test/mock_motion_event.h" |
| 15 #include "ui/gfx/geometry/rect_f.h" | 15 #include "ui/gfx/geometry/rect_f.h" |
| 16 | 16 |
| 17 using ui::MotionEvent; | 17 using ui::MotionEvent; |
| 18 using ui::test::MockMotionEvent; | 18 using ui::test::MockMotionEvent; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 class GestureTextSelectorTest : public testing::Test, | 22 class GestureTextSelectorTest : public testing::Test, |
| 23 public GestureTextSelectorClient { | 23 public GestureTextSelectorClient { |
| 24 public: | 24 public: |
| 25 GestureTextSelectorTest() {} | 25 GestureTextSelectorTest() {} |
| 26 virtual ~GestureTextSelectorTest() {} | 26 virtual ~GestureTextSelectorTest() {} |
| 27 | 27 |
| 28 // Test implementation. | 28 // Test implementation. |
| 29 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() override { |
| 30 selector_.reset(new GestureTextSelector(this)); | 30 selector_.reset(new GestureTextSelector(this)); |
| 31 event_log_.clear(); | 31 event_log_.clear(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 virtual void TearDown() OVERRIDE { | 34 virtual void TearDown() override { |
| 35 selector_.reset(); | 35 selector_.reset(); |
| 36 event_log_.clear(); | 36 event_log_.clear(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // GestureTextSelectorClient implementation. | 39 // GestureTextSelectorClient implementation. |
| 40 virtual void ShowSelectionHandlesAutomatically() OVERRIDE { | 40 virtual void ShowSelectionHandlesAutomatically() override { |
| 41 event_log_.push_back("Show"); | 41 event_log_.push_back("Show"); |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual void SelectRange(float x1, float y1, float x2, float y2) OVERRIDE { | 44 virtual void SelectRange(float x1, float y1, float x2, float y2) override { |
| 45 event_log_.push_back("SelectRange"); | 45 event_log_.push_back("SelectRange"); |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual void LongPress(base::TimeTicks time, float x, float y) OVERRIDE { | 48 virtual void LongPress(base::TimeTicks time, float x, float y) override { |
| 49 event_log_.push_back("LongPress"); | 49 event_log_.push_back("LongPress"); |
| 50 } | 50 } |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 scoped_ptr<GestureTextSelector> selector_; | 53 scoped_ptr<GestureTextSelector> selector_; |
| 54 std::vector<std::string> event_log_; | 54 std::vector<std::string> event_log_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) { | 57 TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) { |
| 58 base::TimeTicks event_time = base::TimeTicks::Now(); | 58 base::TimeTicks event_time = base::TimeTicks::Now(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 event_time += base::TimeDelta::FromMilliseconds(1); | 157 event_time += base::TimeDelta::FromMilliseconds(1); |
| 158 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 158 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
| 159 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 159 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 160 action_up.set_button_state(0); | 160 action_up.set_button_state(0); |
| 161 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 161 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
| 162 ASSERT_EQ(1u, event_log_.size()); | 162 ASSERT_EQ(1u, event_log_.size()); |
| 163 EXPECT_STREQ("LongPress", event_log_.back().c_str()); | 163 EXPECT_STREQ("LongPress", event_log_.back().c_str()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace content | 166 } // namespace content |
| OLD | NEW |