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

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

Issue 715733002: [Android] Show autofill popup after animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make this Android CL independent from the ChromeOS CL. Created 5 years, 11 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/strings/stringprintf.h"
6 #include "chrome/test/base/chrome_render_view_test.h" 7 #include "chrome/test/base/chrome_render_view_test.h"
7 #include "components/autofill/content/renderer/page_click_listener.h" 8 #include "components/autofill/content/renderer/page_click_listener.h"
8 #include "components/autofill/content/renderer/page_click_tracker.h" 9 #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"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
12 #include "third_party/WebKit/public/web/WebInputElement.h" 13 #include "third_party/WebKit/public/web/WebInputElement.h"
13 #include "third_party/WebKit/public/web/WebTextAreaElement.h" 14 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
14 #include "third_party/WebKit/public/web/WebView.h" 15 #include "third_party/WebKit/public/web/WebView.h"
15 #include "third_party/WebKit/public/platform/WebSize.h" 16 #include "third_party/WebKit/public/platform/WebSize.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 68 }
68 69
69 void TearDown() override { 70 void TearDown() override {
70 text_.reset(); 71 text_.reset();
71 textarea_.reset(); 72 textarea_.reset();
72 test_listener_.ClearResults(); 73 test_listener_.ClearResults();
73 page_click_tracker_.reset(); 74 page_click_tracker_.reset();
74 ChromeRenderViewTest::TearDown(); 75 ChromeRenderViewTest::TearDown();
75 } 76 }
76 77
77 // Simulates a click on the given element and then waits for the stack 78 // Simulates a click on the given element and the corresponding response from
78 // to unwind. 79 // the browser about completing the animation effects.
79 void SendElementClick(const std::string& element_id) { 80 void SendElementClick(const std::string& element_id) {
80 EXPECT_TRUE(SimulateElementClick(element_id)); 81 EXPECT_TRUE(SimulateElementClick(element_id));
81 ProcessPendingMessages(); 82 SimulateFocusChangeCompleteMessageReceived();
82 } 83 }
83 84
84 // Send all the messages required for a complete key press. 85 // Simulates a JavaScript focus on the given element and the corresponding
85 void SendKeyPress(int key_code) { 86 // response from the browser about complete the animation effects.
86 blink::WebKeyboardEvent keyboard_event; 87 void SendElementFocus(const char* element_id) {
87 keyboard_event.windowsKeyCode = key_code; 88 ExecuteJavaScript(
88 keyboard_event.setKeyIdentifierFromWindowsKeyCode(); 89 base::StringPrintf("document.getElementById('%s').focus();", element_id)
89 90 .c_str());
90 keyboard_event.type = blink::WebInputEvent::RawKeyDown; 91 SimulateFocusChangeCompleteMessageReceived();
91 SendWebKeyboardEvent(keyboard_event);
92
93 keyboard_event.type = blink::WebInputEvent::Char;
94 SendWebKeyboardEvent(keyboard_event);
95
96 keyboard_event.type = blink::WebInputEvent::KeyUp;
97 SendWebKeyboardEvent(keyboard_event);
98 } 92 }
99 93
100 scoped_ptr<PageClickTracker> page_click_tracker_; 94 scoped_ptr<PageClickTracker> page_click_tracker_;
101 TestPageClickListener test_listener_; 95 TestPageClickListener test_listener_;
102 blink::WebElement text_; 96 blink::WebElement text_;
103 blink::WebElement textarea_; 97 blink::WebElement textarea_;
104 }; 98 };
105 99
106 // Tests that PageClickTracker does notify correctly when an input 100 // Tests that PageClickTracker does notify correctly when an input
107 // node is clicked. 101 // node is clicked.
(...skipping 11 matching lines...) Expand all
119 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_); 113 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
120 EXPECT_TRUE(test_listener_.was_focused_); 114 EXPECT_TRUE(test_listener_.was_focused_);
121 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_); 115 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_);
122 test_listener_.ClearResults(); 116 test_listener_.ClearResults();
123 117
124 // Click the button, no notification should happen (this is not a text-input). 118 // Click the button, no notification should happen (this is not a text-input).
125 SendElementClick("button"); 119 SendElementClick("button");
126 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_); 120 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
127 } 121 }
128 122
123 TEST_F(PageClickTrackerTest, PageClickTrackerInputFocusedAndClicked) {
124 // Focus the text field without a click.
125 SendElementFocus("text_1");
126 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
127 test_listener_.ClearResults();
128
129 // Click the focused text field to test that was_focused_ is set correctly.
130 SendElementClick("text_1");
131 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
132 EXPECT_TRUE(test_listener_.was_focused_);
133 EXPECT_TRUE(text_ == test_listener_.form_control_element_clicked_);
134 }
135
129 // Tests that PageClickTracker does notify correctly when a textarea 136 // Tests that PageClickTracker does notify correctly when a textarea
130 // node is clicked. 137 // node is clicked.
131 TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaClicked) { 138 TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaClicked) {
132 // Click the textarea field once. 139 // Click the textarea field once.
133 SendElementClick("textarea_1"); 140 SendElementClick("textarea_1");
134 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_); 141 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
135 EXPECT_FALSE(test_listener_.was_focused_); 142 EXPECT_FALSE(test_listener_.was_focused_);
136 EXPECT_TRUE(textarea_ == test_listener_.form_control_element_clicked_); 143 EXPECT_TRUE(textarea_ == test_listener_.form_control_element_clicked_);
137 test_listener_.ClearResults(); 144 test_listener_.ClearResults();
138 145
139 // Click the textarea field again to test that was_focused_ is set correctly. 146 // Click the textarea field again to test that was_focused_ is set correctly.
140 SendElementClick("textarea_1"); 147 SendElementClick("textarea_1");
141 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_); 148 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
142 EXPECT_TRUE(test_listener_.was_focused_); 149 EXPECT_TRUE(test_listener_.was_focused_);
143 EXPECT_TRUE(textarea_ == test_listener_.form_control_element_clicked_); 150 EXPECT_TRUE(textarea_ == test_listener_.form_control_element_clicked_);
144 test_listener_.ClearResults(); 151 test_listener_.ClearResults();
145 152
146 // Click the button, no notification should happen (this is not a text-input). 153 // Click the button, no notification should happen (this is not a text-input).
147 SendElementClick("button"); 154 SendElementClick("button");
148 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_); 155 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
149 } 156 }
150 157
158 TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaFocusedAndClicked) {
159 // Focus the textarea without a click.
160 SendElementFocus("textarea_1");
161 EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
162 test_listener_.ClearResults();
163
164 // Click the focused text field to test that was_focused_ is set correctly.
165 SendElementClick("textarea_1");
166 EXPECT_TRUE(test_listener_.form_control_element_clicked_called_);
167 EXPECT_TRUE(test_listener_.was_focused_);
168 EXPECT_TRUE(textarea_ == test_listener_.form_control_element_clicked_);
169 test_listener_.ClearResults();
170 }
171
151 } // namespace autofill 172 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698