| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/autofill/account_chooser_model.h" | 16 #include "chrome/browser/ui/autofill/account_chooser_model.h" |
| 17 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 17 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 18 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 18 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 20 #include "chrome/browser/ui/autofill/autofill_dialog_view_tester.h" | 20 #include "chrome/browser/ui/autofill/autofill_dialog_view_tester.h" |
| 21 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
| 21 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 22 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 22 #include "chrome/browser/ui/autofill/mock_address_validator.h" | 23 #include "chrome/browser/ui/autofill/mock_address_validator.h" |
| 23 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | |
| 24 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" | 24 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" |
| 25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 33 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 using base::ASCIIToUTF16; | 76 using base::ASCIIToUTF16; |
| 77 | 77 |
| 78 namespace autofill { | 78 namespace autofill { |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 | 81 |
| 82 using testing::Return; | 82 using testing::Return; |
| 83 using testing::_; | 83 using testing::_; |
| 84 using ::i18n::addressinput::AddressValidator; | 84 using ::i18n::addressinput::AddressValidator; |
| 85 | 85 |
| 86 void MockCallback(AutofillManagerDelegate::RequestAutocompleteResult, | 86 void MockCallback(AutofillClient::RequestAutocompleteResult, |
| 87 const base::string16& message, | 87 const base::string16& message, |
| 88 const FormStructure*) {} | 88 const FormStructure*) { |
| 89 } |
| 89 | 90 |
| 90 class MockAutofillMetrics : public AutofillMetrics { | 91 class MockAutofillMetrics : public AutofillMetrics { |
| 91 public: | 92 public: |
| 92 MockAutofillMetrics() | 93 MockAutofillMetrics() |
| 93 : dialog_dismissal_action_(static_cast<DialogDismissalAction>(-1)) {} | 94 : dialog_dismissal_action_(static_cast<DialogDismissalAction>(-1)) {} |
| 94 virtual ~MockAutofillMetrics() {} | 95 virtual ~MockAutofillMetrics() {} |
| 95 | 96 |
| 96 virtual void LogDialogUiDuration( | 97 virtual void LogDialogUiDuration( |
| 97 const base::TimeDelta& duration, | 98 const base::TimeDelta& duration, |
| 98 DialogDismissalAction dismissal_action) const OVERRIDE { | 99 DialogDismissalAction dismissal_action) const OVERRIDE { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 message_loop_runner_->Run(); | 397 message_loop_runner_->Run(); |
| 397 } | 398 } |
| 398 | 399 |
| 399 // Loads an HTML page in |GetActiveWebContents()| with markup as follows: | 400 // Loads an HTML page in |GetActiveWebContents()| with markup as follows: |
| 400 // <form>|form_inner_html|</form>. After loading, emulates a click event on | 401 // <form>|form_inner_html|</form>. After loading, emulates a click event on |
| 401 // the page as requestAutocomplete() must be in response to a user gesture. | 402 // the page as requestAutocomplete() must be in response to a user gesture. |
| 402 // Returns the |AutofillDialogControllerImpl| created by this invocation. | 403 // Returns the |AutofillDialogControllerImpl| created by this invocation. |
| 403 AutofillDialogControllerImpl* SetUpHtmlAndInvoke( | 404 AutofillDialogControllerImpl* SetUpHtmlAndInvoke( |
| 404 const std::string& form_inner_html) { | 405 const std::string& form_inner_html) { |
| 405 content::WebContents* contents = GetActiveWebContents(); | 406 content::WebContents* contents = GetActiveWebContents(); |
| 406 TabAutofillManagerDelegate* delegate = | 407 ChromeAutofillClient* client = |
| 407 TabAutofillManagerDelegate::FromWebContents(contents); | 408 ChromeAutofillClient::FromWebContents(contents); |
| 408 CHECK(!delegate->GetDialogControllerForTesting()); | 409 CHECK(!client->GetDialogControllerForTesting()); |
| 409 | 410 |
| 410 ui_test_utils::NavigateToURL( | 411 ui_test_utils::NavigateToURL( |
| 411 browser(), GURL(std::string("data:text/html,") + | 412 browser(), GURL(std::string("data:text/html,") + |
| 412 "<!doctype html>" | 413 "<!doctype html>" |
| 413 "<html>" | 414 "<html>" |
| 414 "<body>" | 415 "<body>" |
| 415 "<form>" + form_inner_html + "</form>" | 416 "<form>" + form_inner_html + "</form>" |
| 416 "<script>" | 417 "<script>" |
| 417 "var invalidEvents = [];" | 418 "var invalidEvents = [];" |
| 418 "function recordInvalid(e) {" | 419 "function recordInvalid(e) {" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 " }" | 456 " }" |
| 456 " send('');" | 457 " send('');" |
| 457 "};" | 458 "};" |
| 458 "</script>" | 459 "</script>" |
| 459 "</body>" | 460 "</body>" |
| 460 "</html>")); | 461 "</html>")); |
| 461 | 462 |
| 462 InitiateDialog(); | 463 InitiateDialog(); |
| 463 AutofillDialogControllerImpl* controller = | 464 AutofillDialogControllerImpl* controller = |
| 464 static_cast<AutofillDialogControllerImpl*>( | 465 static_cast<AutofillDialogControllerImpl*>( |
| 465 delegate->GetDialogControllerForTesting()); | 466 client->GetDialogControllerForTesting()); |
| 466 return controller; | 467 return controller; |
| 467 } | 468 } |
| 468 | 469 |
| 469 // Loads an html page on a provided server, the causes it to launch rAc. | 470 // Loads an html page on a provided server, the causes it to launch rAc. |
| 470 // Returns whether rAc succesfully launched. | 471 // Returns whether rAc succesfully launched. |
| 471 bool RunTestPage(const net::SpawnedTestServer& server) { | 472 bool RunTestPage(const net::SpawnedTestServer& server) { |
| 472 GURL url = server.GetURL( | 473 GURL url = server.GetURL( |
| 473 "files/request_autocomplete/test_page.html"); | 474 "files/request_autocomplete/test_page.html"); |
| 474 ui_test_utils::NavigateToURL(browser(), url); | 475 ui_test_utils::NavigateToURL(browser(), url); |
| 475 | 476 |
| 476 // Pass through the broken SSL interstitial, if any. | 477 // Pass through the broken SSL interstitial, if any. |
| 477 content::WebContents* contents = GetActiveWebContents(); | 478 content::WebContents* contents = GetActiveWebContents(); |
| 478 content::InterstitialPage* interstitial_page = | 479 content::InterstitialPage* interstitial_page = |
| 479 contents->GetInterstitialPage(); | 480 contents->GetInterstitialPage(); |
| 480 if (interstitial_page) { | 481 if (interstitial_page) { |
| 481 ui_test_utils::UrlLoadObserver observer( | 482 ui_test_utils::UrlLoadObserver observer( |
| 482 url, | 483 url, |
| 483 content::Source<content::NavigationController>( | 484 content::Source<content::NavigationController>( |
| 484 &contents->GetController())); | 485 &contents->GetController())); |
| 485 interstitial_page->Proceed(); | 486 interstitial_page->Proceed(); |
| 486 observer.Wait(); | 487 observer.Wait(); |
| 487 } | 488 } |
| 488 | 489 |
| 489 InitiateDialog(); | 490 InitiateDialog(); |
| 490 | 491 |
| 491 TabAutofillManagerDelegate* delegate = | 492 ChromeAutofillClient* client = |
| 492 TabAutofillManagerDelegate::FromWebContents(contents); | 493 ChromeAutofillClient::FromWebContents(contents); |
| 493 AutofillDialogControllerImpl* controller = | 494 AutofillDialogControllerImpl* controller = |
| 494 static_cast<AutofillDialogControllerImpl*>( | 495 static_cast<AutofillDialogControllerImpl*>( |
| 495 delegate->GetDialogControllerForTesting()); | 496 client->GetDialogControllerForTesting()); |
| 496 return !!controller; | 497 return !!controller; |
| 497 } | 498 } |
| 498 | 499 |
| 499 // Wait for a message from the DOM automation controller (from JS in the | 500 // Wait for a message from the DOM automation controller (from JS in the |
| 500 // page). Requires |SetUpHtmlAndInvoke()| be called first. | 501 // page). Requires |SetUpHtmlAndInvoke()| be called first. |
| 501 void ExpectDomMessage(const std::string& expected) { | 502 void ExpectDomMessage(const std::string& expected) { |
| 502 std::string message; | 503 std::string message; |
| 503 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); | 504 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); |
| 504 dom_message_queue_->ClearQueue(); | 505 dom_message_queue_->ClearQueue(); |
| 505 EXPECT_EQ("\"" + expected + "\"", message); | 506 EXPECT_EQ("\"" + expected + "\"", message); |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, RefreshOnManageTabClose) { | 1416 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, RefreshOnManageTabClose) { |
| 1416 ASSERT_TRUE(browser()->is_type_tabbed()); | 1417 ASSERT_TRUE(browser()->is_type_tabbed()); |
| 1417 | 1418 |
| 1418 // GetWalletItems() is called when controller() is created in SetUp(). | 1419 // GetWalletItems() is called when controller() is created in SetUp(). |
| 1419 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); | 1420 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); |
| 1420 controller()->OnDidFetchWalletCookieValue(std::string()); | 1421 controller()->OnDidFetchWalletCookieValue(std::string()); |
| 1421 controller()->OnDidGetWalletItems( | 1422 controller()->OnDidGetWalletItems( |
| 1422 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | 1423 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
| 1423 | 1424 |
| 1424 content::WebContents* dialog_invoker = controller()->GetWebContents(); | 1425 content::WebContents* dialog_invoker = controller()->GetWebContents(); |
| 1425 TabAutofillManagerDelegate::FromWebContents(dialog_invoker)-> | 1426 ChromeAutofillClient::FromWebContents(dialog_invoker) |
| 1426 SetDialogControllerForTesting(controller()->AsWeakPtr()); | 1427 ->SetDialogControllerForTesting(controller()->AsWeakPtr()); |
| 1427 | 1428 |
| 1428 // Open a new tab by selecting "Manage my shipping details..." in Wallet mode. | 1429 // Open a new tab by selecting "Manage my shipping details..." in Wallet mode. |
| 1429 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1430 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1430 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2); | 1431 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2); |
| 1431 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1432 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1432 ASSERT_NE(dialog_invoker, GetActiveWebContents()); | 1433 ASSERT_NE(dialog_invoker, GetActiveWebContents()); |
| 1433 | 1434 |
| 1434 // Closing the tab opened by "Manage my shipping details..." should refresh | 1435 // Closing the tab opened by "Manage my shipping details..." should refresh |
| 1435 // the dialog. | 1436 // the dialog. |
| 1436 controller()->ClearLastWalletItemsFetchTimestampForTesting(); | 1437 controller()->ClearLastWalletItemsFetchTimestampForTesting(); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 // Relevant country loaded but revalidation already happened, no further | 1734 // Relevant country loaded but revalidation already happened, no further |
| 1734 // validation should occur. | 1735 // validation should occur. |
| 1735 controller()->OnAddressValidationRulesLoaded("DE", false); | 1736 controller()->OnAddressValidationRulesLoaded("DE", false); |
| 1736 | 1737 |
| 1737 // Cancelling the dialog causes additional validation to see if the user | 1738 // Cancelling the dialog causes additional validation to see if the user |
| 1738 // cancelled with invalid fields, so verify and clear here. | 1739 // cancelled with invalid fields, so verify and clear here. |
| 1739 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator()); | 1740 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator()); |
| 1740 } | 1741 } |
| 1741 | 1742 |
| 1742 } // namespace autofill | 1743 } // namespace autofill |
| OLD | NEW |