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

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

Issue 1026493002: Allow only a user gesture to trigger autofill popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not layout frame. Created 5 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
« no previous file with comments | « no previous file | chrome/renderer/autofill/password_autofill_agent_browsertest.cc » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/test/base/chrome_render_view_test.h" 9 #include "chrome/test/base/chrome_render_view_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "components/autofill/content/common/autofill_messages.h" 11 #include "components/autofill/content/common/autofill_messages.h"
12 #include "components/autofill/content/renderer/autofill_agent.h" 12 #include "components/autofill/content/renderer/autofill_agent.h"
13 #include "components/autofill/core/common/form_data.h" 13 #include "components/autofill/core/common/form_data.h"
14 #include "components/autofill/core/common/form_field_data.h" 14 #include "components/autofill/core/common/form_field_data.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/renderer/render_frame.h" 16 #include "content/public/renderer/render_frame.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h" 19 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/public/platform/WebVector.h" 20 #include "third_party/WebKit/public/platform/WebVector.h"
21 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
22 #include "third_party/WebKit/public/web/WebFormElement.h" 22 #include "third_party/WebKit/public/web/WebFormElement.h"
23 #include "third_party/WebKit/public/web/WebInputElement.h" 23 #include "third_party/WebKit/public/web/WebInputElement.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" 24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 #include "third_party/WebKit/public/web/WebView.h"
25 26
26 using base::ASCIIToUTF16; 27 using base::ASCIIToUTF16;
27 using blink::WebDocument; 28 using blink::WebDocument;
28 using blink::WebElement; 29 using blink::WebElement;
29 using blink::WebFormElement; 30 using blink::WebFormElement;
30 using blink::WebFrame; 31 using blink::WebFrame;
31 using blink::WebLocalFrame; 32 using blink::WebLocalFrame;
32 using blink::WebInputElement; 33 using blink::WebInputElement;
33 using blink::WebString; 34 using blink::WebString;
34 using blink::WebURLRequest; 35 using blink::WebURLRequest;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 expected.max_length = WebInputElement::defaultMaxLength(); 239 expected.max_length = WebInputElement::defaultMaxLength();
239 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]); 240 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[7]);
240 241
241 expected.name = ASCIIToUTF16("PHONE_HOME_WHOLE_NUMBER"); 242 expected.name = ASCIIToUTF16("PHONE_HOME_WHOLE_NUMBER");
242 expected.value.clear(); 243 expected.value.clear();
243 expected.form_control_type = "text"; 244 expected.form_control_type = "text";
244 expected.max_length = WebInputElement::defaultMaxLength(); 245 expected.max_length = WebInputElement::defaultMaxLength();
245 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[8]); 246 EXPECT_FORM_FIELD_DATA_EQUALS(expected, forms[0].fields[8]);
246 } 247 }
247 248
249 TEST_F(AutofillRendererTest, IgnoreNonUserGestureTextFieldChanges) {
250 LoadHTML("<form method='post'>"
251 " <input type='text' id='full_name'/>"
252 "</form>");
253
254 blink::WebInputElement full_name =
255 GetMainFrame()->document().getElementById("full_name")
256 .to<blink::WebInputElement>();
257 while (!full_name.focused())
258 GetMainFrame()->view()->advanceFocus(false);
259
260 // Not a user gesture, so no IPC message to browser.
261 full_name.setValue("Alice", true);
262 GetMainFrame()->toWebLocalFrame()->autofillClient()->textFieldDidChange(
263 full_name);
264 base::MessageLoop::current()->RunUntilIdle();
265 ASSERT_EQ(nullptr, render_thread_->sink().GetFirstMessageMatching(
266 AutofillHostMsg_TextFieldDidChange::ID));
267
268 // A user gesture will send a message to the browser.
269 SimulateUserInputChangeForElement(&full_name, "Alice");
270 ASSERT_NE(nullptr, render_thread_->sink().GetFirstMessageMatching(
271 AutofillHostMsg_TextFieldDidChange::ID));
272 }
273
248 class RequestAutocompleteRendererTest : public AutofillRendererTest { 274 class RequestAutocompleteRendererTest : public AutofillRendererTest {
249 public: 275 public:
250 RequestAutocompleteRendererTest() 276 RequestAutocompleteRendererTest()
251 : invoking_frame_(NULL), sibling_frame_(NULL) {} 277 : invoking_frame_(NULL), sibling_frame_(NULL) {}
252 ~RequestAutocompleteRendererTest() override {} 278 ~RequestAutocompleteRendererTest() override {}
253 279
254 protected: 280 protected:
255 void SetUp() override { 281 void SetUp() override {
256 AutofillRendererTest::SetUp(); 282 AutofillRendererTest::SetUp();
257 283
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 }; 342 };
317 343
318 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) { 344 TEST_F(RequestAutocompleteRendererTest, InvokingTwiceOnlyShowsOnce) {
319 // Attempting to show the requestAutocomplete dialog again should be ignored. 345 // Attempting to show the requestAutocomplete dialog again should be ignored.
320 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form()); 346 invoking_frame_->autofillClient()->didRequestAutocomplete(invoking_form());
321 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( 347 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
322 AutofillHostMsg_RequestAutocomplete::ID)); 348 AutofillHostMsg_RequestAutocomplete::ID));
323 } 349 }
324 350
325 } // namespace autofill 351 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/autofill/password_autofill_agent_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698