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

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

Issue 2766053002: [refactor] Fix autofill features for payments when the form is inside an OOPIF (Closed)
Patch Set: Fixing tests Created 3 years, 8 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 (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 <memory> 5 #include <memory>
6 6
7 #include "chrome/test/base/chrome_render_view_test.h" 7 #include "chrome/test/base/chrome_render_view_test.h"
8 #include "components/autofill/content/renderer/autofill_agent.h"
8 #include "components/autofill/content/renderer/page_click_listener.h" 9 #include "components/autofill/content/renderer/page_click_listener.h"
9 #include "components/autofill/content/renderer/page_click_tracker.h" 10 #include "components/autofill/content/renderer/page_click_tracker.h"
10 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 13 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
13 #include "third_party/WebKit/public/platform/WebSize.h" 14 #include "third_party/WebKit/public/platform/WebSize.h"
14 #include "third_party/WebKit/public/web/WebDocument.h" 15 #include "third_party/WebKit/public/web/WebDocument.h"
15 #include "third_party/WebKit/public/web/WebInputElement.h" 16 #include "third_party/WebKit/public/web/WebInputElement.h"
16 #include "third_party/WebKit/public/web/WebSettings.h" 17 #include "third_party/WebKit/public/web/WebSettings.h"
17 #include "third_party/WebKit/public/web/WebView.h" 18 #include "third_party/WebKit/public/web/WebView.h"
(...skipping 25 matching lines...) Expand all
43 bool was_focused_; 44 bool was_focused_;
44 }; 45 };
45 46
46 class PageClickTrackerTest : public ChromeRenderViewTest { 47 class PageClickTrackerTest : public ChromeRenderViewTest {
47 protected: 48 protected:
48 void SetUp() override { 49 void SetUp() override {
49 ChromeRenderViewTest::SetUp(); 50 ChromeRenderViewTest::SetUp();
50 51
51 // RenderView creates PageClickTracker but it doesn't keep it around. 52 // 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. 53 // Rather than make it do so for the test, we create a new object.
53 page_click_tracker_.reset(new PageClickTracker(view_->GetMainRenderFrame(), 54 page_click_tracker_ =
vabr (Chromium) 2017/04/14 06:44:24 While your code is correct, it takes some mental e
EhsanK 2017/04/18 17:55:19 Thanks! Sorry for the vagueness in the code. But I
54 &test_listener_)); 55 new PageClickTracker(view_->GetMainRenderFrame(), &test_listener_);
56
57 autofill_agent_->set_page_click_tracker_for_testing(page_click_tracker_);
55 58
56 // Must be set before loading HTML. 59 // Must be set before loading HTML.
57 view_->GetWebView()->SetDefaultPageScaleLimits(1, 4); 60 view_->GetWebView()->SetDefaultPageScaleLimits(1, 4);
58 61
59 LoadHTML("<form>" 62 LoadHTML("<form>"
60 " <input type='text' id='text_1'></input><br>" 63 " <input type='text' id='text_1'></input><br>"
61 " <input type='text' id='text_2'></input><br>" 64 " <input type='text' id='text_2'></input><br>"
62 " <textarea id='textarea_1'></textarea><br>" 65 " <textarea id='textarea_1'></textarea><br>"
63 " <textarea id='textarea_2'></textarea><br>" 66 " <textarea id='textarea_2'></textarea><br>"
64 " <input type='button' id='button'></input><br>" 67 " <input type='button' id='button'></input><br>"
(...skipping 10 matching lines...) Expand all
75 78
76 // Enable show-ime event when element is focused by indicating that a user 79 // Enable show-ime event when element is focused by indicating that a user
77 // gesture has been processed since load. 80 // gesture has been processed since load.
78 EXPECT_TRUE(SimulateElementClick("button")); 81 EXPECT_TRUE(SimulateElementClick("button"));
79 } 82 }
80 83
81 void TearDown() override { 84 void TearDown() override {
82 text_.Reset(); 85 text_.Reset();
83 textarea_.Reset(); 86 textarea_.Reset();
84 test_listener_.ClearResults(); 87 test_listener_.ClearResults();
85 page_click_tracker_.reset();
86 ChromeRenderViewTest::TearDown(); 88 ChromeRenderViewTest::TearDown();
87 } 89 }
88 90
89 std::unique_ptr<PageClickTracker> page_click_tracker_; 91 PageClickTracker* page_click_tracker_;
vabr (Chromium) 2017/04/14 06:44:24 nit: Please rename to page_click_tracker_weak_ to
EhsanK 2017/04/18 17:55:19 Thanks! Removed as explained in comment above.
90 TestPageClickListener test_listener_; 92 TestPageClickListener test_listener_;
91 blink::WebElement text_; 93 blink::WebElement text_;
92 blink::WebElement textarea_; 94 blink::WebElement textarea_;
93 }; 95 };
94 96
95 // Tests that PageClickTracker does notify correctly when an input 97 // Tests that PageClickTracker does notify correctly when an input
96 // node is clicked. 98 // node is clicked.
97 TEST_F(PageClickTrackerTest, PageClickTrackerInputClicked) { 99 TEST_F(PageClickTrackerTest, PageClickTrackerInputClicked) {
98 EXPECT_NE(text_, text_.GetDocument().FocusedElement()); 100 EXPECT_NE(text_, text_.GetDocument().FocusedElement());
99 // Click the text field once. 101 // Click the text field once.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Tap outside of element bounds, but tap width is overlapping the field. 242 // Tap outside of element bounds, but tap width is overlapping the field.
241 gfx::Rect element_bounds = GetElementBounds("text_1"); 243 gfx::Rect element_bounds = GetElementBounds("text_1");
242 SimulateRectTap(element_bounds - 244 SimulateRectTap(element_bounds -
243 gfx::Vector2d(element_bounds.width() / 2 + 1, 0)); 245 gfx::Vector2d(element_bounds.width() / 2 + 1, 0));
244 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_); 246 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
245 EXPECT_FALSE(test_listener_.was_focused_); 247 EXPECT_FALSE(test_listener_.was_focused_);
246 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_); 248 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_);
247 } 249 }
248 250
249 } // namespace autofill 251 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698