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

Side by Side Diff: chrome/renderer/autofill/page_click_tracker_browsertest.cc

Issue 1305353013: Tests for user gesture detection in page click tracker. [DO NOT REVIEW] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@user-gesture
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | components/autofill/content/renderer/page_click_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "components/autofill/content/renderer/page_click_tracker.h"
6
5 #include "base/basictypes.h" 7 #include "base/basictypes.h"
6 #include "chrome/test/base/chrome_render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
7 #include "components/autofill/content/renderer/page_click_listener.h" 9 #include "components/autofill/content/renderer/page_click_listener.h"
8 #include "components/autofill/content/renderer/page_click_tracker.h"
9 #include "content/public/renderer/render_view.h" 10 #include "content/public/renderer/render_view.h"
11 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 13 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
12 #include "third_party/WebKit/public/platform/WebSize.h" 14 #include "third_party/WebKit/public/platform/WebSize.h"
13 #include "third_party/WebKit/public/web/WebDocument.h" 15 #include "third_party/WebKit/public/web/WebDocument.h"
14 #include "third_party/WebKit/public/web/WebInputElement.h" 16 #include "third_party/WebKit/public/web/WebInputElement.h"
15 #include "third_party/WebKit/public/web/WebSettings.h" 17 #include "third_party/WebKit/public/web/WebSettings.h"
16 #include "third_party/WebKit/public/web/WebTextAreaElement.h" 18 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
17 #include "third_party/WebKit/public/web/WebView.h" 19 #include "third_party/WebKit/public/web/WebView.h"
18 #include "ui/events/keycodes/keyboard_codes.h" 20 #include "ui/events/keycodes/keyboard_codes.h"
19 21
20 namespace autofill { 22 namespace autofill {
21 23
24 using testing::Return;
25
26 class MockPageClickTracker : public PageClickTracker {
27 public:
28 MockPageClickTracker(content::RenderFrame* render_frame,
29 PageClickListener* listener)
30 : PageClickTracker(render_frame, listener) {
31 ON_CALL(*this, IsUserGesture()).WillByDefault(Return(true));
32 ON_CALL(*this, IsKeyboardAccessory()).WillByDefault(Return(false));
33 }
34
35 ~MockPageClickTracker() override {}
36
37 MOCK_CONST_METHOD0(IsUserGesture, bool());
38 MOCK_CONST_METHOD0(IsKeyboardAccessory, bool());
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(MockPageClickTracker);
42 };
43
22 class TestPageClickListener : public PageClickListener { 44 class TestPageClickListener : public PageClickListener {
23 public: 45 public:
24 TestPageClickListener() 46 TestPageClickListener()
25 : form_control_element_clicked_called_(false), 47 : form_control_element_clicked_called_(false),
26 was_focused_(false) {} 48 was_focused_(false) {}
27 49
28 void FormControlElementClicked(const blink::WebFormControlElement& element, 50 void FormControlElementClicked(const blink::WebFormControlElement& element,
29 bool was_focused) override { 51 bool was_focused) override {
30 form_control_element_clicked_called_ = true; 52 form_control_element_clicked_called_ = true;
31 form_control_element_clicked_ = element; 53 form_control_element_clicked_ = element;
(...skipping 11 matching lines...) Expand all
43 bool was_focused_; 65 bool was_focused_;
44 }; 66 };
45 67
46 class PageClickTrackerTest : public ChromeRenderViewTest { 68 class PageClickTrackerTest : public ChromeRenderViewTest {
47 protected: 69 protected:
48 void SetUp() override { 70 void SetUp() override {
49 ChromeRenderViewTest::SetUp(); 71 ChromeRenderViewTest::SetUp();
50 72
51 // RenderView creates PageClickTracker but it doesn't keep it around. 73 // RenderView creates PageClickTracker but it doesn't keep it around.
52 // Rather than make it do so for the test, we create a new object. 74 // Rather than make it do so for the test, we create a new object.
53 page_click_tracker_.reset(new PageClickTracker(view_->GetMainRenderFrame(), 75 page_click_tracker_.reset(new testing::NiceMock<MockPageClickTracker>(
54 &test_listener_)); 76 view_->GetMainRenderFrame(), &test_listener_));
55 77
56 // Must be set before loading HTML. 78 // Must be set before loading HTML.
57 view_->GetWebView()->setDefaultPageScaleLimits(1, 4); 79 view_->GetWebView()->setDefaultPageScaleLimits(1, 4);
58 80
59 LoadHTML("<form>" 81 LoadHTML("<form>"
60 " <input type='text' id='text_1'></input><br>" 82 " <input type='text' id='text_1'></input><br>"
61 " <input type='text' id='text_2'></input><br>" 83 " <input type='text' id='text_2'></input><br>"
62 " <textarea id='textarea_1'></textarea><br>" 84 " <textarea id='textarea_1'></textarea><br>"
63 " <textarea id='textarea_2'></textarea><br>" 85 " <textarea id='textarea_2'></textarea><br>"
64 " <input type='button' id='button'></input><br>" 86 " <input type='button' id='button'></input><br>"
(...skipping 13 matching lines...) Expand all
78 } 100 }
79 101
80 void TearDown() override { 102 void TearDown() override {
81 text_.reset(); 103 text_.reset();
82 textarea_.reset(); 104 textarea_.reset();
83 test_listener_.ClearResults(); 105 test_listener_.ClearResults();
84 page_click_tracker_.reset(); 106 page_click_tracker_.reset();
85 ChromeRenderViewTest::TearDown(); 107 ChromeRenderViewTest::TearDown();
86 } 108 }
87 109
88 scoped_ptr<PageClickTracker> page_click_tracker_; 110 scoped_ptr<MockPageClickTracker> page_click_tracker_;
89 TestPageClickListener test_listener_; 111 TestPageClickListener test_listener_;
90 blink::WebElement text_; 112 blink::WebElement text_;
91 blink::WebElement textarea_; 113 blink::WebElement textarea_;
92 }; 114 };
93 115
94 // Tests that PageClickTracker does notify correctly when an input 116 // Tests that PageClickTracker does notify correctly when an input
95 // node is clicked. 117 // node is clicked.
96 TEST_F(PageClickTrackerTest, PageClickTrackerInputClicked) { 118 TEST_F(PageClickTrackerTest, PageClickTrackerInputClicked) {
97 EXPECT_NE(text_, text_.document().focusedElement()); 119 EXPECT_NE(text_, text_.document().focusedElement());
98 // Click the text field once. 120 // Click the text field once.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EXPECT_NE(text_, text_.document().focusedElement()); 260 EXPECT_NE(text_, text_.document().focusedElement());
239 // Tap outside of element bounds, but tap width is overlapping the field. 261 // Tap outside of element bounds, but tap width is overlapping the field.
240 gfx::Rect element_bounds = GetElementBounds("text_1"); 262 gfx::Rect element_bounds = GetElementBounds("text_1");
241 SimulateRectTap(element_bounds - 263 SimulateRectTap(element_bounds -
242 gfx::Vector2d(element_bounds.width() / 2 + 1, 0)); 264 gfx::Vector2d(element_bounds.width() / 2 + 1, 0));
243 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_); 265 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
244 EXPECT_FALSE(test_listener_.was_focused_); 266 EXPECT_FALSE(test_listener_.was_focused_);
245 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_); 267 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_);
246 } 268 }
247 269
270 TEST_F(PageClickTrackerTest, KeyboardAccessoryForMouseDown) {
271 LOG(ERROR) << "Starting the test...";
272 EXPECT_CALL(*page_click_tracker_, IsKeyboardAccessory())
273 .WillOnce(Return(true));
274 page_click_tracker_->OnMouseDown(text_);
275 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
276 }
277
278 TEST_F(PageClickTrackerTest, KeyboardAccessoryForUserGestureFocusedNodeChange) {
279 EXPECT_CALL(*page_click_tracker_, IsKeyboardAccessory())
280 .WillOnce(Return(true));
281 page_click_tracker_->FocusedNodeChanged(blink::WebNode());
282 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
283 }
284
285 TEST_F(PageClickTrackerTest,
286 NoKeyboardAccessoryForNonUserGestureFocusedNodeChange) {
287 EXPECT_CALL(*page_click_tracker_, IsUserGesture()).WillOnce(Return(false));
288 EXPECT_CALL(*page_click_tracker_, IsKeyboardAccessory())
289 .WillOnce(Return(true));
290 page_click_tracker_->FocusedNodeChanged(blink::WebNode());
291 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
292 }
293
294 TEST_F(PageClickTrackerTest, NoKeyboardAccessoryForFocusChangeComplete) {
295 EXPECT_CALL(*page_click_tracker_, IsKeyboardAccessory())
296 .WillOnce(Return(true));
297 page_click_tracker_->FocusChangeComplete();
298 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
299 }
300
248 } // namespace autofill 301 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/page_click_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698