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

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

Issue 63273002: Rename WebKit namespace to blink (part 4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
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/autofill_agent.h"
9 #include "components/autofill/content/renderer/form_autofill_util.h" 9 #include "components/autofill/content/renderer/form_autofill_util.h"
10 #include "components/autofill/content/renderer/password_autofill_agent.h" 10 #include "components/autofill/content/renderer/password_autofill_agent.h"
11 #include "components/autofill/content/renderer/test_password_autofill_agent.h" 11 #include "components/autofill/content/renderer/test_password_autofill_agent.h"
12 #include "components/autofill/core/common/autofill_messages.h" 12 #include "components/autofill/core/common/autofill_messages.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 "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebElement.h" 19 #include "third_party/WebKit/public/web/WebElement.h"
20 #include "third_party/WebKit/public/web/WebFormElement.h" 20 #include "third_party/WebKit/public/web/WebFormElement.h"
21 #include "third_party/WebKit/public/web/WebInputElement.h" 21 #include "third_party/WebKit/public/web/WebInputElement.h"
22 #include "third_party/WebKit/public/web/WebNode.h" 22 #include "third_party/WebKit/public/web/WebNode.h"
23 #include "third_party/WebKit/public/web/WebView.h" 23 #include "third_party/WebKit/public/web/WebView.h"
24 #include "ui/events/keycodes/keyboard_codes.h" 24 #include "ui/events/keycodes/keyboard_codes.h"
25 25
26 using autofill::PasswordForm; 26 using autofill::PasswordForm;
27 using WebKit::WebDocument; 27 using blink::WebDocument;
28 using WebKit::WebElement; 28 using blink::WebElement;
29 using WebKit::WebFrame; 29 using blink::WebFrame;
30 using WebKit::WebInputElement; 30 using blink::WebInputElement;
31 using WebKit::WebString; 31 using blink::WebString;
32 using WebKit::WebView; 32 using blink::WebView;
33 33
34 namespace { 34 namespace {
35 35
36 // The name of the username/password element in the form. 36 // The name of the username/password element in the form.
37 const char kUsernameName[] = "username"; 37 const char kUsernameName[] = "username";
38 const char kPasswordName[] = "password"; 38 const char kPasswordName[] = "password";
39 39
40 const char kAliceUsername[] = "alice"; 40 const char kAliceUsername[] = "alice";
41 const char kAlicePassword[] = "password"; 41 const char kAlicePassword[] = "password";
42 const char kBobUsername[] = "bob"; 42 const char kBobUsername[] = "bob";
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 fill_data_.basic_data.origin = GURL(origin); 192 fill_data_.basic_data.origin = GURL(origin);
193 fill_data_.basic_data.action = GURL("http://www.bidule.com"); 193 fill_data_.basic_data.action = GURL("http://www.bidule.com");
194 194
195 LoadHTML(kFormHTML); 195 LoadHTML(kFormHTML);
196 196
197 // Now retrieves the input elements so the test can access them. 197 // Now retrieves the input elements so the test can access them.
198 WebDocument document = GetMainFrame()->document(); 198 WebDocument document = GetMainFrame()->document();
199 WebElement element = 199 WebElement element =
200 document.getElementById(WebString::fromUTF8(kUsernameName)); 200 document.getElementById(WebString::fromUTF8(kUsernameName));
201 ASSERT_FALSE(element.isNull()); 201 ASSERT_FALSE(element.isNull());
202 username_element_ = element.to<WebKit::WebInputElement>(); 202 username_element_ = element.to<blink::WebInputElement>();
203 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 203 element = document.getElementById(WebString::fromUTF8(kPasswordName));
204 ASSERT_FALSE(element.isNull()); 204 ASSERT_FALSE(element.isNull());
205 password_element_ = element.to<WebKit::WebInputElement>(); 205 password_element_ = element.to<blink::WebInputElement>();
206 } 206 }
207 207
208 virtual void TearDown() { 208 virtual void TearDown() {
209 username_element_.reset(); 209 username_element_.reset();
210 password_element_.reset(); 210 password_element_.reset();
211 ChromeRenderViewTest::TearDown(); 211 ChromeRenderViewTest::TearDown();
212 } 212 }
213 213
214 void ClearUsernameAndPasswordFields() { 214 void ClearUsernameAndPasswordFields() {
215 username_element_.setValue(""); 215 username_element_.setValue("");
(...skipping 12 matching lines...) Expand all
228 if (move_caret_to_end) 228 if (move_caret_to_end)
229 username_element_.setSelectionRange(username.length(), username.length()); 229 username_element_.setSelectionRange(username.length(), username.length());
230 autofill_agent_->textFieldDidChange(username_element_); 230 autofill_agent_->textFieldDidChange(username_element_);
231 // Processing is delayed because of a WebKit bug, see 231 // Processing is delayed because of a WebKit bug, see
232 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. 232 // PasswordAutocompleteManager::TextDidChangeInTextField() for details.
233 base::MessageLoop::current()->RunUntilIdle(); 233 base::MessageLoop::current()->RunUntilIdle();
234 } 234 }
235 235
236 void SimulateKeyDownEvent(const WebInputElement& element, 236 void SimulateKeyDownEvent(const WebInputElement& element,
237 ui::KeyboardCode key_code) { 237 ui::KeyboardCode key_code) {
238 WebKit::WebKeyboardEvent key_event; 238 blink::WebKeyboardEvent key_event;
239 key_event.windowsKeyCode = key_code; 239 key_event.windowsKeyCode = key_code;
240 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); 240 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event);
241 } 241 }
242 242
243 void CheckTextFieldsState(const std::string& username, 243 void CheckTextFieldsState(const std::string& username,
244 bool username_autofilled, 244 bool username_autofilled,
245 const std::string& password, 245 const std::string& password,
246 bool password_autofilled) { 246 bool password_autofilled) {
247 EXPECT_EQ(username, 247 EXPECT_EQ(username,
248 static_cast<std::string>(username_element_.value().utf8())); 248 static_cast<std::string>(username_element_.value().utf8()));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 " <INPUT type='password' id='password'/>" 314 " <INPUT type='password' id='password'/>"
315 " <INPUT type='submit' value='Login'/>" 315 " <INPUT type='submit' value='Login'/>"
316 "</FORM>"; 316 "</FORM>";
317 LoadHTML(kEmptyActionFormHTML); 317 LoadHTML(kEmptyActionFormHTML);
318 318
319 // Retrieve the input elements so the test can access them. 319 // Retrieve the input elements so the test can access them.
320 WebDocument document = GetMainFrame()->document(); 320 WebDocument document = GetMainFrame()->document();
321 WebElement element = 321 WebElement element =
322 document.getElementById(WebString::fromUTF8(kUsernameName)); 322 document.getElementById(WebString::fromUTF8(kUsernameName));
323 ASSERT_FALSE(element.isNull()); 323 ASSERT_FALSE(element.isNull());
324 username_element_ = element.to<WebKit::WebInputElement>(); 324 username_element_ = element.to<blink::WebInputElement>();
325 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 325 element = document.getElementById(WebString::fromUTF8(kPasswordName));
326 ASSERT_FALSE(element.isNull()); 326 ASSERT_FALSE(element.isNull());
327 password_element_ = element.to<WebKit::WebInputElement>(); 327 password_element_ = element.to<blink::WebInputElement>();
328 328
329 // Set the expected form origin and action URLs. 329 // Set the expected form origin and action URLs.
330 std::string origin("data:text/html;charset=utf-8,"); 330 std::string origin("data:text/html;charset=utf-8,");
331 origin += kEmptyActionFormHTML; 331 origin += kEmptyActionFormHTML;
332 fill_data_.basic_data.origin = GURL(origin); 332 fill_data_.basic_data.origin = GURL(origin);
333 fill_data_.basic_data.action = GURL(origin); 333 fill_data_.basic_data.action = GURL(origin);
334 334
335 // Simulate the browser sending back the login info, it triggers the 335 // Simulate the browser sending back the login info, it triggers the
336 // autocomplete. 336 // autocomplete.
337 SimulateOnFillPasswordForm(fill_data_); 337 SimulateOnFillPasswordForm(fill_data_);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 " <INPUT type='text' id='password'/>" 432 " <INPUT type='text' id='password'/>"
433 " <INPUT type='submit' value='Login'/>" 433 " <INPUT type='submit' value='Login'/>"
434 "</FORM>"; 434 "</FORM>";
435 LoadHTML(kTextFieldPasswordFormHTML); 435 LoadHTML(kTextFieldPasswordFormHTML);
436 436
437 // Retrieve the input elements so the test can access them. 437 // Retrieve the input elements so the test can access them.
438 WebDocument document = GetMainFrame()->document(); 438 WebDocument document = GetMainFrame()->document();
439 WebElement element = 439 WebElement element =
440 document.getElementById(WebString::fromUTF8(kUsernameName)); 440 document.getElementById(WebString::fromUTF8(kUsernameName));
441 ASSERT_FALSE(element.isNull()); 441 ASSERT_FALSE(element.isNull());
442 username_element_ = element.to<WebKit::WebInputElement>(); 442 username_element_ = element.to<blink::WebInputElement>();
443 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 443 element = document.getElementById(WebString::fromUTF8(kPasswordName));
444 ASSERT_FALSE(element.isNull()); 444 ASSERT_FALSE(element.isNull());
445 password_element_ = element.to<WebKit::WebInputElement>(); 445 password_element_ = element.to<blink::WebInputElement>();
446 446
447 // Set the expected form origin URL. 447 // Set the expected form origin URL.
448 std::string origin("data:text/html;charset=utf-8,"); 448 std::string origin("data:text/html;charset=utf-8,");
449 origin += kTextFieldPasswordFormHTML; 449 origin += kTextFieldPasswordFormHTML;
450 fill_data_.basic_data.origin = GURL(origin); 450 fill_data_.basic_data.origin = GURL(origin);
451 451
452 SimulateOnFillPasswordForm(fill_data_); 452 SimulateOnFillPasswordForm(fill_data_);
453 453
454 // Fields should still be empty. 454 // Fields should still be empty.
455 CheckTextFieldsState(std::string(), false, std::string(), false); 455 CheckTextFieldsState(std::string(), false, std::string(), false);
456 } 456 }
457 457
458 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForPasswordFieldUsernames) { 458 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForPasswordFieldUsernames) {
459 const char kPasswordFieldUsernameFormHTML[] = 459 const char kPasswordFieldUsernameFormHTML[] =
460 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" 460 "<FORM name='LoginTestForm' action='http://www.bidule.com'>"
461 " <INPUT type='password' id='username'/>" 461 " <INPUT type='password' id='username'/>"
462 " <INPUT type='password' id='password'/>" 462 " <INPUT type='password' id='password'/>"
463 " <INPUT type='submit' value='Login'/>" 463 " <INPUT type='submit' value='Login'/>"
464 "</FORM>"; 464 "</FORM>";
465 LoadHTML(kPasswordFieldUsernameFormHTML); 465 LoadHTML(kPasswordFieldUsernameFormHTML);
466 466
467 // Retrieve the input elements so the test can access them. 467 // Retrieve the input elements so the test can access them.
468 WebDocument document = GetMainFrame()->document(); 468 WebDocument document = GetMainFrame()->document();
469 WebElement element = 469 WebElement element =
470 document.getElementById(WebString::fromUTF8(kUsernameName)); 470 document.getElementById(WebString::fromUTF8(kUsernameName));
471 ASSERT_FALSE(element.isNull()); 471 ASSERT_FALSE(element.isNull());
472 username_element_ = element.to<WebKit::WebInputElement>(); 472 username_element_ = element.to<blink::WebInputElement>();
473 element = document.getElementById(WebString::fromUTF8(kPasswordName)); 473 element = document.getElementById(WebString::fromUTF8(kPasswordName));
474 ASSERT_FALSE(element.isNull()); 474 ASSERT_FALSE(element.isNull());
475 password_element_ = element.to<WebKit::WebInputElement>(); 475 password_element_ = element.to<blink::WebInputElement>();
476 476
477 // Set the expected form origin URL. 477 // Set the expected form origin URL.
478 std::string origin("data:text/html;charset=utf-8,"); 478 std::string origin("data:text/html;charset=utf-8,");
479 origin += kPasswordFieldUsernameFormHTML; 479 origin += kPasswordFieldUsernameFormHTML;
480 fill_data_.basic_data.origin = GURL(origin); 480 fill_data_.basic_data.origin = GURL(origin);
481 481
482 SimulateOnFillPasswordForm(fill_data_); 482 SimulateOnFillPasswordForm(fill_data_);
483 483
484 // Fields should still be empty. 484 // Fields should still be empty.
485 CheckTextFieldsState(std::string(), false, std::string(), false); 485 CheckTextFieldsState(std::string(), false, std::string(), false);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 SimulateOnFillPasswordForm(fill_data_); 613 SimulateOnFillPasswordForm(fill_data_);
614 614
615 // Clear the text fields to start fresh. 615 // Clear the text fields to start fresh.
616 ClearUsernameAndPasswordFields(); 616 ClearUsernameAndPasswordFields();
617 617
618 // To simulate accepting an item in the suggestion drop-down we just mimic 618 // To simulate accepting an item in the suggestion drop-down we just mimic
619 // what the WebView does: it sets the element value then calls 619 // what the WebView does: it sets the element value then calls
620 // didSelectAutofillSuggestion on the renderer. 620 // didSelectAutofillSuggestion on the renderer.
621 autofill_agent_->didSelectAutofillSuggestion(username_element_, 621 autofill_agent_->didSelectAutofillSuggestion(username_element_,
622 ASCIIToUTF16(kAliceUsername), 622 ASCIIToUTF16(kAliceUsername),
623 WebKit::WebString(), 623 blink::WebString(),
624 0); 624 0);
625 // Autocomplete should not have kicked in. 625 // Autocomplete should not have kicked in.
626 CheckTextFieldsState(std::string(), false, std::string(), false); 626 CheckTextFieldsState(std::string(), false, std::string(), false);
627 } 627 }
628 628
629 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) { 629 TEST_F(PasswordAutofillAgentTest, IsWebNodeVisibleTest) {
630 WebKit::WebVector<WebKit::WebFormElement> forms1, forms2, forms3; 630 blink::WebVector<blink::WebFormElement> forms1, forms2, forms3;
631 WebKit::WebFrame* frame; 631 blink::WebFrame* frame;
632 632
633 LoadHTML(kVisibleFormHTML); 633 LoadHTML(kVisibleFormHTML);
634 frame = GetMainFrame(); 634 frame = GetMainFrame();
635 frame->document().forms(forms1); 635 frame->document().forms(forms1);
636 ASSERT_EQ(1u, forms1.size()); 636 ASSERT_EQ(1u, forms1.size());
637 EXPECT_TRUE(IsWebNodeVisible(forms1[0])); 637 EXPECT_TRUE(IsWebNodeVisible(forms1[0]));
638 638
639 LoadHTML(kEmptyFormHTML); 639 LoadHTML(kEmptyFormHTML);
640 frame = GetMainFrame(); 640 frame = GetMainFrame();
641 frame->document().forms(forms2); 641 frame->document().forms(forms2);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 692 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
693 AutofillHostMsg_PasswordFormsRendered::ID)); 693 AutofillHostMsg_PasswordFormsRendered::ID));
694 694
695 render_thread_->sink().ClearMessages(); 695 render_thread_->sink().ClearMessages();
696 LoadHTML(kWebpageWithDynamicContent); 696 LoadHTML(kWebpageWithDynamicContent);
697 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( 697 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
698 AutofillHostMsg_PasswordFormsRendered::ID)); 698 AutofillHostMsg_PasswordFormsRendered::ID));
699 } 699 }
700 700
701 } // namespace autofill 701 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698