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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

Issue 178263004: rAc - Only show countries we're able to fill in. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android build Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('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/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"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run 333 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run
334 // loop. It also drains the NSAutoreleasePool. 334 // loop. It also drains the NSAutoreleasePool.
335 void CycleRunLoops() { 335 void CycleRunLoops() {
336 content::RunAllPendingInMessageLoop(); 336 content::RunAllPendingInMessageLoop();
337 #if defined(OS_MACOSX) 337 #if defined(OS_MACOSX)
338 chrome::testing::NSRunLoopRunAllPending(); 338 chrome::testing::NSRunLoopRunAllPending();
339 AutoreleasePool()->Recycle(); 339 AutoreleasePool()->Recycle();
340 #endif 340 #endif
341 } 341 }
342 342
343 void InitializeController() { 343 void InitializeControllerWithoutShowing() {
344 FormData form; 344 FormData form;
345 form.name = ASCIIToUTF16("TestForm"); 345 form.name = ASCIIToUTF16("TestForm");
346 form.method = ASCIIToUTF16("POST"); 346 form.method = ASCIIToUTF16("POST");
347 form.user_submitted = true; 347 form.user_submitted = true;
348 348
349 FormFieldData field; 349 FormFieldData field;
350 field.autocomplete_attribute = "shipping tel"; 350 field.autocomplete_attribute = "shipping tel";
351 form.fields.push_back(field); 351 form.fields.push_back(field);
352 352
353 test_generated_bubble_controller_ = 353 test_generated_bubble_controller_ =
354 new testing::NiceMock<TestGeneratedCreditCardBubbleController>( 354 new testing::NiceMock<TestGeneratedCreditCardBubbleController>(
355 GetActiveWebContents()); 355 GetActiveWebContents());
356 ASSERT_TRUE(test_generated_bubble_controller_->IsInstalled()); 356 ASSERT_TRUE(test_generated_bubble_controller_->IsInstalled());
357 357
358 message_loop_runner_ = new content::MessageLoopRunner; 358 message_loop_runner_ = new content::MessageLoopRunner;
359 controller_ = new TestAutofillDialogController( 359 controller_ = new TestAutofillDialogController(
360 GetActiveWebContents(), 360 GetActiveWebContents(),
361 form, 361 form,
362 metric_logger_, 362 metric_logger_,
363 message_loop_runner_); 363 message_loop_runner_);
364 }
365
366 void InitializeController() {
367 InitializeControllerWithoutShowing();
364 controller_->Show(); 368 controller_->Show();
365 CycleRunLoops(); // Ensures dialog is fully visible. 369 CycleRunLoops(); // Ensures dialog is fully visible.
366 } 370 }
367 371
368 content::WebContents* GetActiveWebContents() { 372 content::WebContents* GetActiveWebContents() {
369 return browser()->tab_strip_model()->GetActiveWebContents(); 373 return browser()->tab_strip_model()->GetActiveWebContents();
370 } 374 }
371 375
372 scoped_ptr<AutofillDialogViewTester> GetViewTester() { 376 scoped_ptr<AutofillDialogViewTester> GetViewTester() {
373 return AutofillDialogViewTester::For(controller()->view()).Pass(); 377 return AutofillDialogViewTester::For(controller()->view()).Pass();
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Belarus")); 1451 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Belarus"));
1448 view->ActivateInput(ADDRESS_HOME_COUNTRY); 1452 view->ActivateInput(ADDRESS_HOME_COUNTRY);
1449 1453
1450 // Verify the name is still there. 1454 // Verify the name is still there.
1451 EXPECT_EQ(ASCIIToUTF16("B. Loblaw"), view->GetTextContentsOfInput(NAME_FULL)); 1455 EXPECT_EQ(ASCIIToUTF16("B. Loblaw"), view->GetTextContentsOfInput(NAME_FULL));
1452 1456
1453 EXPECT_TRUE(SectionHasField(SECTION_BILLING, ADDRESS_BILLING_SORTING_CODE)); 1457 EXPECT_TRUE(SectionHasField(SECTION_BILLING, ADDRESS_BILLING_SORTING_CODE));
1454 EXPECT_TRUE(SectionHasField(SECTION_SHIPPING, ADDRESS_HOME_SORTING_CODE)); 1458 EXPECT_TRUE(SectionHasField(SECTION_SHIPPING, ADDRESS_HOME_SORTING_CODE));
1455 } 1459 }
1456 1460
1457 // A shim to install a TestPersonalDataManager instead of the real thing.
1458 class TestPersonalDataManagerService
1459 : public autofill::PersonalDataManagerService {
1460 public:
1461 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
1462 return new TestPersonalDataManagerService();
1463 }
1464
1465 TestPersonalDataManagerService() {}
1466 virtual ~TestPersonalDataManagerService() {}
1467
1468 virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE {
1469 return &test_data_manager_;
1470 }
1471 TestPersonalDataManager* GetTestPersonalDataManager() {
1472 return &test_data_manager_;
1473 }
1474
1475 private:
1476 TestPersonalDataManager test_data_manager_;
1477 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManagerService);
1478 };
1479
1480 // Changing the data source to or from Wallet preserves the shipping country, 1461 // Changing the data source to or from Wallet preserves the shipping country,
1481 // but not the billing country because Wallet only supports US billing 1462 // but not the billing country because Wallet only supports US billing
1482 // addresses. 1463 // addresses.
1483 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, 1464 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
1484 ChangingDataSourcePreservesCountry) { 1465 ChangingDataSourcePreservesCountry) {
1485 // Set the default country to Canada. 1466 InitializeControllerWithoutShowing();
1486 static_cast<TestPersonalDataManagerService*>( 1467 controller()->GetTestingManager()->set_default_country_code("CA");
1487 autofill::PersonalDataManagerFactory::GetInstance()-> 1468 controller()->Show();
1488 SetTestingFactoryAndUse( 1469 CycleRunLoops();
1489 browser()->profile(),
1490 TestPersonalDataManagerService::Build))->
1491 GetTestPersonalDataManager()->set_default_country_code("CA");
1492 1470
1493 InitializeController();
1494 AutofillProfile verified_profile(test::GetVerifiedProfile()); 1471 AutofillProfile verified_profile(test::GetVerifiedProfile());
1495 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 1472 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
1496 1473
1497 CreditCard verified_card(test::GetVerifiedCreditCard()); 1474 CreditCard verified_card(test::GetVerifiedCreditCard());
1498 controller()->GetTestingManager()->AddTestingCreditCard(&verified_card); 1475 controller()->GetTestingManager()->AddTestingCreditCard(&verified_card);
1476 EXPECT_FALSE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1499 1477
1500 controller()->OnDidFetchWalletCookieValue(std::string()); 1478 controller()->OnDidFetchWalletCookieValue(std::string());
1501 scoped_ptr<wallet::WalletItems> items = 1479 scoped_ptr<wallet::WalletItems> items =
1502 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); 1480 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED);
1503 items->AddAccount(wallet::GetTestGaiaAccount()); 1481 items->AddAccount(wallet::GetTestGaiaAccount());
1504 items->AddInstrument(wallet::GetTestMaskedInstrument()); 1482 items->AddInstrument(wallet::GetTestMaskedInstrument());
1505 items->AddAddress(wallet::GetTestShippingAddress()); 1483 items->AddAddress(wallet::GetTestShippingAddress());
1506 controller()->OnDidGetWalletItems(items.Pass()); 1484 controller()->OnDidGetWalletItems(items.Pass());
1507 1485
1508 EXPECT_TRUE(controller()->IsPayingWithWallet()); 1486 EXPECT_TRUE(controller()->IsPayingWithWallet());
1509 1487
1510 // Select "Add new shipping address...". 1488 // Select "Add new shipping address...".
1511 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2); 1489 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(2);
1490 EXPECT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING));
1512 1491
1513 // Default shipping country matches timezone, but default billing is always 1492 // Default shipping country matches PDM's default, but default billing is
1514 // US in Wallet mode. 1493 // always US in Wallet mode.
1515 scoped_ptr<AutofillDialogViewTester> view = GetViewTester(); 1494 scoped_ptr<AutofillDialogViewTester> view = GetViewTester();
1516 ASSERT_EQ(ASCIIToUTF16("Canada"), 1495 ASSERT_EQ(ASCIIToUTF16("Canada"),
1517 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); 1496 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
1518 ASSERT_EQ(ASCIIToUTF16("United States"), 1497 ASSERT_EQ(ASCIIToUTF16("United States"),
1519 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY)); 1498 view->GetTextContentsOfInput(ADDRESS_BILLING_COUNTRY));
1520 1499
1521 // Switch the shipping country. 1500 // Switch the shipping country.
1522 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Belarus")); 1501 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Belarus"));
1523 EXPECT_EQ(ASCIIToUTF16("Belarus"), 1502 EXPECT_EQ(ASCIIToUTF16("Belarus"),
1524 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); 1503 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // Relevant country loaded but revalidation already happened, no further 1643 // Relevant country loaded but revalidation already happened, no further
1665 // validation should occur. 1644 // validation should occur.
1666 controller()->OnAddressValidationRulesLoaded("DE", false); 1645 controller()->OnAddressValidationRulesLoaded("DE", false);
1667 1646
1668 // Cancelling the dialog causes additional validation to see if the user 1647 // Cancelling the dialog causes additional validation to see if the user
1669 // cancelled with invalid fields, so verify and clear here. 1648 // cancelled with invalid fields, so verify and clear here.
1670 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator()); 1649 testing::Mock::VerifyAndClearExpectations(controller()->GetMockValidator());
1671 } 1650 }
1672 1651
1673 } // namespace autofill 1652 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698