| 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 <map> | 5 #include <map> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "chrome/browser/signin/account_tracker_service_factory.h" | 21 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 22 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 22 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 23 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 23 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| 24 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 24 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 25 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" | |
| 26 #include "chrome/browser/ui/autofill/mock_address_validator.h" | 25 #include "chrome/browser/ui/autofill/mock_address_validator.h" |
| 27 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" | 26 #include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h" |
| 28 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle
r.h" | |
| 29 #include "chrome/browser/web_data_service_factory.h" | 27 #include "chrome/browser/web_data_service_factory.h" |
| 30 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 34 #include "chrome/test/base/scoped_testing_local_state.h" | 32 #include "chrome/test/base/scoped_testing_local_state.h" |
| 35 #include "chrome/test/base/testing_browser_process.h" | 33 #include "chrome/test/base/testing_browser_process.h" |
| 36 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
| 37 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 35 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| 38 #include "components/autofill/core/browser/autofill_metrics.h" | 36 #include "components/autofill/core/browser/autofill_metrics.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 void TearDown() override { | 316 void TearDown() override { |
| 319 if (controller_) | 317 if (controller_) |
| 320 controller_->ViewClosed(); | 318 controller_->ViewClosed(); |
| 321 ChromeRenderViewHostTestHarness::TearDown(); | 319 ChromeRenderViewHostTestHarness::TearDown(); |
| 322 } | 320 } |
| 323 | 321 |
| 324 void Reset() { | 322 void Reset() { |
| 325 if (controller_) | 323 if (controller_) |
| 326 controller_->ViewClosed(); | 324 controller_->ViewClosed(); |
| 327 | 325 |
| 328 test_generated_bubble_controller_ = | |
| 329 new testing::NiceMock<TestGeneratedCreditCardBubbleController>( | |
| 330 web_contents()); | |
| 331 ASSERT_TRUE(test_generated_bubble_controller_->IsInstalled()); | |
| 332 | |
| 333 mock_new_card_bubble_controller_.reset( | 326 mock_new_card_bubble_controller_.reset( |
| 334 new MockNewCreditCardBubbleController); | 327 new MockNewCreditCardBubbleController); |
| 335 | 328 |
| 336 profile()->GetPrefs()->ClearPref(::prefs::kAutofillDialogSaveData); | 329 profile()->GetPrefs()->ClearPref(::prefs::kAutofillDialogSaveData); |
| 337 | 330 |
| 338 // We have to clear the old local state before creating a new one. | 331 // We have to clear the old local state before creating a new one. |
| 339 scoped_local_state_.reset(); | 332 scoped_local_state_.reset(); |
| 340 scoped_local_state_.reset(new ScopedTestingLocalState( | 333 scoped_local_state_.reset(new ScopedTestingLocalState( |
| 341 TestingBrowserProcess::GetGlobal())); | 334 TestingBrowserProcess::GetGlobal())); |
| 342 | 335 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 EXPECT_FALSE(billing_name.empty()); | 486 EXPECT_FALSE(billing_name.empty()); |
| 494 EXPECT_FALSE(shipping_name.empty()); | 487 EXPECT_FALSE(shipping_name.empty()); |
| 495 EXPECT_EQ(cc_name, billing_name); | 488 EXPECT_EQ(cc_name, billing_name); |
| 496 EXPECT_EQ(cc_name, shipping_name); | 489 EXPECT_EQ(cc_name, shipping_name); |
| 497 } | 490 } |
| 498 | 491 |
| 499 TestAutofillDialogController* controller() { return controller_.get(); } | 492 TestAutofillDialogController* controller() { return controller_.get(); } |
| 500 | 493 |
| 501 const FormStructure* form_structure() { return form_structure_; } | 494 const FormStructure* form_structure() { return form_structure_; } |
| 502 | 495 |
| 503 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { | |
| 504 return test_generated_bubble_controller_; | |
| 505 } | |
| 506 | |
| 507 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { | 496 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { |
| 508 return mock_new_card_bubble_controller_.get(); | 497 return mock_new_card_bubble_controller_.get(); |
| 509 } | 498 } |
| 510 | 499 |
| 511 private: | 500 private: |
| 512 void FinishedCallback(AutofillClient::RequestAutocompleteResult result, | 501 void FinishedCallback(AutofillClient::RequestAutocompleteResult result, |
| 513 const base::string16& debug_message, | 502 const base::string16& debug_message, |
| 514 const FormStructure* form_structure) { | 503 const FormStructure* form_structure) { |
| 515 form_structure_ = form_structure; | 504 form_structure_ = form_structure; |
| 516 } | 505 } |
| 517 | 506 |
| 518 #if defined(OS_WIN) | 507 #if defined(OS_WIN) |
| 519 // http://crbug.com/227221 | 508 // http://crbug.com/227221 |
| 520 ui::ScopedOleInitializer ole_initializer_; | 509 ui::ScopedOleInitializer ole_initializer_; |
| 521 #endif | 510 #endif |
| 522 | 511 |
| 523 // The controller owns itself. | 512 // The controller owns itself. |
| 524 base::WeakPtr<TestAutofillDialogController> controller_; | 513 base::WeakPtr<TestAutofillDialogController> controller_; |
| 525 | 514 |
| 526 // Returned when the dialog closes successfully. | 515 // Returned when the dialog closes successfully. |
| 527 const FormStructure* form_structure_; | 516 const FormStructure* form_structure_; |
| 528 | 517 |
| 529 // Used to monitor if the Autofill credit card bubble is shown. Owned by | |
| 530 // |web_contents()|. | |
| 531 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller_; | |
| 532 | |
| 533 // Used to record when new card bubbles would show. Created in |Reset()|. | 518 // Used to record when new card bubbles would show. Created in |Reset()|. |
| 534 scoped_ptr<MockNewCreditCardBubbleController> | 519 scoped_ptr<MockNewCreditCardBubbleController> |
| 535 mock_new_card_bubble_controller_; | 520 mock_new_card_bubble_controller_; |
| 536 | 521 |
| 537 scoped_ptr<ScopedTestingLocalState> scoped_local_state_; | 522 scoped_ptr<ScopedTestingLocalState> scoped_local_state_; |
| 538 }; | 523 }; |
| 539 | 524 |
| 540 } // namespace | 525 } // namespace |
| 541 | 526 |
| 542 TEST_F(AutofillDialogControllerTest, RefuseToShowWithNoAutocompleteAttributes) { | 527 TEST_F(AutofillDialogControllerTest, RefuseToShowWithNoAutocompleteAttributes) { |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 controller()->OnAccept(); | 1367 controller()->OnAccept(); |
| 1383 EXPECT_TRUE(form_structure()); | 1368 EXPECT_TRUE(form_structure()); |
| 1384 } | 1369 } |
| 1385 | 1370 |
| 1386 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { | 1371 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { |
| 1387 FillCreditCardInputs(); | 1372 FillCreditCardInputs(); |
| 1388 controller()->OnAccept(); | 1373 controller()->OnAccept(); |
| 1389 controller()->ViewClosed(); | 1374 controller()->ViewClosed(); |
| 1390 | 1375 |
| 1391 EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown()); | 1376 EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown()); |
| 1392 EXPECT_EQ(0, test_generated_bubble_controller()->bubbles_shown()); | |
| 1393 } | 1377 } |
| 1394 | 1378 |
| 1395 TEST_F(AutofillDialogControllerTest, SaveInChromeByDefault) { | 1379 TEST_F(AutofillDialogControllerTest, SaveInChromeByDefault) { |
| 1396 EXPECT_TRUE(controller()->ShouldSaveInChrome()); | 1380 EXPECT_TRUE(controller()->ShouldSaveInChrome()); |
| 1397 FillCreditCardInputs(); | 1381 FillCreditCardInputs(); |
| 1398 controller()->OnAccept(); | 1382 controller()->OnAccept(); |
| 1399 EXPECT_TRUE(controller()->ShouldSaveInChrome()); | 1383 EXPECT_TRUE(controller()->ShouldSaveInChrome()); |
| 1400 } | 1384 } |
| 1401 | 1385 |
| 1402 TEST_F(AutofillDialogControllerTest, | 1386 TEST_F(AutofillDialogControllerTest, |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 SECTION_SHIPPING, | 1823 SECTION_SHIPPING, |
| 1840 NAME_FULL, | 1824 NAME_FULL, |
| 1841 gfx::NativeView(), | 1825 gfx::NativeView(), |
| 1842 gfx::Rect(), | 1826 gfx::Rect(), |
| 1843 profile.GetRawInfo(NAME_FULL).substr(0, 1), | 1827 profile.GetRawInfo(NAME_FULL).substr(0, 1), |
| 1844 true); | 1828 true); |
| 1845 EXPECT_EQ(NAME_FULL, controller()->popup_input_type()); | 1829 EXPECT_EQ(NAME_FULL, controller()->popup_input_type()); |
| 1846 } | 1830 } |
| 1847 | 1831 |
| 1848 } // namespace autofill | 1832 } // namespace autofill |
| OLD | NEW |