Chromium Code Reviews| 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_view.h" | 19 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 19 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 20 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 20 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 21 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 21 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle r.h" | 22 #include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controlle r.h" |
| 22 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" | 23 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/common/chrome_switches.h" | |
| 26 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 32 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
| 31 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" | 33 #include "components/autofill/content/browser/wallet/mock_wallet_client.h" |
| 32 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 34 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
| 33 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 35 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
| 34 #include "components/autofill/core/browser/autofill_metrics.h" | 36 #include "components/autofill/core/browser/autofill_metrics.h" |
| 35 #include "components/autofill/core/browser/autofill_test_utils.h" | 37 #include "components/autofill/core/browser/autofill_test_utils.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 180 |
| 179 void set_notifications(const std::vector<DialogNotification>& notifications) { | 181 void set_notifications(const std::vector<DialogNotification>& notifications) { |
| 180 notifications_ = notifications; | 182 notifications_ = notifications; |
| 181 } | 183 } |
| 182 | 184 |
| 183 TestPersonalDataManager* GetTestingManager() { | 185 TestPersonalDataManager* GetTestingManager() { |
| 184 return &test_manager_; | 186 return &test_manager_; |
| 185 } | 187 } |
| 186 | 188 |
| 187 using AutofillDialogControllerImpl::IsEditingExistingData; | 189 using AutofillDialogControllerImpl::IsEditingExistingData; |
| 190 using AutofillDialogControllerImpl::IsManuallyEditingSection; | |
| 188 using AutofillDialogControllerImpl::IsPayingWithWallet; | 191 using AutofillDialogControllerImpl::IsPayingWithWallet; |
| 189 using AutofillDialogControllerImpl::IsSubmitPausedOn; | 192 using AutofillDialogControllerImpl::IsSubmitPausedOn; |
| 190 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 193 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 191 using AutofillDialogControllerImpl::AccountChooserModelForTesting; | 194 using AutofillDialogControllerImpl::AccountChooserModelForTesting; |
| 192 using AutofillDialogControllerImpl:: | 195 using AutofillDialogControllerImpl:: |
| 193 ClearLastWalletItemsFetchTimestampForTesting; | 196 ClearLastWalletItemsFetchTimestampForTesting; |
| 194 | 197 |
| 195 void set_use_validation(bool use_validation) { | 198 void set_use_validation(bool use_validation) { |
| 196 use_validation_ = use_validation; | 199 use_validation_ = use_validation; |
| 197 } | 200 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 RunMessageLoop(); | 552 RunMessageLoop(); |
| 550 | 553 |
| 551 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 554 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
| 552 metric_logger().dialog_dismissal_action()); | 555 metric_logger().dialog_dismissal_action()); |
| 553 } | 556 } |
| 554 | 557 |
| 555 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { | 558 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { |
| 556 AutofillProfile full_profile(test::GetFullProfile()); | 559 AutofillProfile full_profile(test::GetFullProfile()); |
| 557 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 560 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 558 | 561 |
| 562 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING); | |
| 563 model->ActivatedAt(model->GetItemCount() - 2); | |
| 564 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
|
Evan Stade
2014/01/14 17:19:38
nit: add comment about what the second to last ite
Dan Beam
2014/01/15 03:10:48
Done.
| |
| 565 | |
| 559 const DetailInputs& inputs = | 566 const DetailInputs& inputs = |
| 560 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 567 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 561 const ServerFieldType triggering_type = inputs[0].type; | 568 const ServerFieldType triggering_type = inputs[0].type; |
| 562 base::string16 value = full_profile.GetRawInfo(triggering_type); | 569 base::string16 value = full_profile.GetRawInfo(triggering_type); |
| 563 TestableAutofillDialogView* view = controller()->GetTestableView(); | 570 TestableAutofillDialogView* view = controller()->GetTestableView(); |
| 564 view->SetTextContentsOfInput(triggering_type, | 571 view->SetTextContentsOfInput(triggering_type, |
| 565 value.substr(0, value.size() / 2)); | 572 value.substr(0, value.size() / 2)); |
| 566 view->ActivateInput(triggering_type); | 573 view->ActivateInput(triggering_type); |
| 567 | 574 |
| 568 ASSERT_EQ(triggering_type, controller()->popup_input_type()); | 575 ASSERT_EQ(triggering_type, controller()->popup_input_type()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 | 609 |
| 603 // For now, no matter what, the country must always be US. See | 610 // For now, no matter what, the country must always be US. See |
| 604 // http://crbug.com/247518 | 611 // http://crbug.com/247518 |
| 605 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 612 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 606 FillInputFromForeignProfile) { | 613 FillInputFromForeignProfile) { |
| 607 AutofillProfile full_profile(test::GetFullProfile()); | 614 AutofillProfile full_profile(test::GetFullProfile()); |
| 608 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 615 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), |
| 609 ASCIIToUTF16("France"), "en-US"); | 616 ASCIIToUTF16("France"), "en-US"); |
| 610 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 617 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
| 611 | 618 |
| 619 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING); | |
| 620 model->ActivatedAt(model->GetItemCount() - 2); | |
| 621 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
| 622 | |
| 612 const DetailInputs& inputs = | 623 const DetailInputs& inputs = |
| 613 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 624 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 614 const ServerFieldType triggering_type = inputs[0].type; | 625 const ServerFieldType triggering_type = inputs[0].type; |
| 615 base::string16 value = full_profile.GetRawInfo(triggering_type); | 626 base::string16 value = full_profile.GetRawInfo(triggering_type); |
| 616 TestableAutofillDialogView* view = controller()->GetTestableView(); | 627 TestableAutofillDialogView* view = controller()->GetTestableView(); |
| 617 view->SetTextContentsOfInput(triggering_type, | 628 view->SetTextContentsOfInput(triggering_type, |
| 618 value.substr(0, value.size() / 2)); | 629 value.substr(0, value.size() / 2)); |
| 619 view->ActivateInput(triggering_type); | 630 view->ActivateInput(triggering_type); |
| 620 | 631 |
| 621 ASSERT_EQ(triggering_type, controller()->popup_input_type()); | 632 ASSERT_EQ(triggering_type, controller()->popup_input_type()); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 | 1101 |
| 1091 controller()->OnDidGetWalletItems( | 1102 controller()->OnDidGetWalletItems( |
| 1092 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | 1103 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
| 1093 | 1104 |
| 1094 // Wallet should now be selected and Chrome shouldn't have crashed (which can | 1105 // Wallet should now be selected and Chrome shouldn't have crashed (which can |
| 1095 // happen if the WebContents is deleted while proccessing a nav entry commit). | 1106 // happen if the WebContents is deleted while proccessing a nav entry commit). |
| 1096 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); | 1107 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); |
| 1097 } | 1108 } |
| 1098 | 1109 |
| 1099 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { | 1110 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { |
| 1100 InitializeController(); | |
| 1101 | |
| 1102 controller()->OnDidFetchWalletCookieValue(std::string()); | 1111 controller()->OnDidFetchWalletCookieValue(std::string()); |
| 1103 std::vector<std::string> usernames; | 1112 std::vector<std::string> usernames; |
| 1104 usernames.push_back("user_0@example.com"); | 1113 usernames.push_back("user_0@example.com"); |
| 1105 controller()->OnDidGetWalletItems( | 1114 controller()->OnDidGetWalletItems( |
| 1106 wallet::GetTestWalletItemsWithUsers(usernames, 0)); | 1115 wallet::GetTestWalletItemsWithUsers(usernames, 0)); |
| 1107 | 1116 |
| 1108 // Switch to Autofill. | 1117 // Switch to Autofill. |
| 1109 AccountChooserModel* account_chooser_model = | 1118 AccountChooserModel* account_chooser_model = |
| 1110 controller()->AccountChooserModelForTesting(); | 1119 controller()->AccountChooserModelForTesting(); |
| 1111 account_chooser_model->ActivatedAt( | 1120 account_chooser_model->ActivatedAt( |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1331 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 1340 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 1332 MAYBE_DoesWorkOnHttpWithFlag) { | 1341 MAYBE_DoesWorkOnHttpWithFlag) { |
| 1333 net::SpawnedTestServer http_server( | 1342 net::SpawnedTestServer http_server( |
| 1334 net::SpawnedTestServer::TYPE_HTTP, | 1343 net::SpawnedTestServer::TYPE_HTTP, |
| 1335 net::SpawnedTestServer::kLocalhost, | 1344 net::SpawnedTestServer::kLocalhost, |
| 1336 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1345 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 1337 ASSERT_TRUE(http_server.Start()); | 1346 ASSERT_TRUE(http_server.Start()); |
| 1338 EXPECT_TRUE(RunTestPage(http_server)); | 1347 EXPECT_TRUE(RunTestPage(http_server)); |
| 1339 } | 1348 } |
| 1340 | 1349 |
| 1350 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | |
| 1351 CountryChangeRebuildsSection) { | |
| 1352 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 1353 command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n); | |
| 1354 ASSERT_TRUE(i18ninput::Enabled()); | |
| 1355 | |
| 1356 InitializeController(); | |
| 1357 | |
| 1358 controller()->OnDidFetchWalletCookieValue(std::string()); | |
| 1359 controller()->OnDidGetWalletItems( | |
| 1360 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | |
| 1361 EXPECT_TRUE(controller()->IsPayingWithWallet()); | |
| 1362 | |
| 1363 // Select "Add new shipping address...". | |
| 1364 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); | |
| 1365 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
| 1366 | |
| 1367 TestableAutofillDialogView* view = controller()->GetTestableView(); | |
| 1368 ASSERT_EQ(ASCIIToUTF16("United States"), | |
| 1369 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); | |
| 1370 | |
| 1371 const DetailInputs& us_inputs = | |
| 1372 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | |
| 1373 EXPECT_EQ(8U, us_inputs.size()); | |
| 1374 | |
| 1375 // Check that there's no dependent locality for the US layout. | |
| 1376 for (size_t i = 0; i < us_inputs.size(); ++i) { | |
| 1377 EXPECT_NE(us_inputs[i].type, ADDRESS_HOME_DEPENDENT_LOCALITY); | |
| 1378 } | |
| 1379 | |
| 1380 // Add some valid user input that should be preserved when country changes and | |
| 1381 // switch from United States to China. | |
| 1382 view->SetTextContentsOfInput(NAME_FULL, ASCIIToUTF16("B. Loblaw")); | |
| 1383 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("China")); | |
| 1384 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); | |
| 1385 | |
| 1386 EXPECT_EQ(ASCIIToUTF16("B. Loblaw"), view->GetTextContentsOfInput(NAME_FULL)); | |
| 1387 EXPECT_EQ(ASCIIToUTF16("China"), | |
| 1388 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); | |
| 1389 | |
| 1390 const DetailInputs& cn_inputs = | |
| 1391 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | |
| 1392 EXPECT_EQ(9U, cn_inputs.size()); | |
| 1393 | |
| 1394 // Check that there is dependent locality for the Chinese layout. | |
| 1395 size_t i = 0; | |
| 1396 for (; i < cn_inputs.size(); ++i) { | |
| 1397 if (cn_inputs[i].type == ADDRESS_HOME_DEPENDENT_LOCALITY) | |
| 1398 break; | |
| 1399 } | |
| 1400 EXPECT_LT(i, cn_inputs.size()); | |
| 1401 | |
| 1402 // Changing data sources should preserve country selection. | |
| 1403 ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser(); | |
| 1404 account_chooser->ActivatedAt(account_chooser->GetItemCount() - 1); | |
| 1405 EXPECT_FALSE(controller()->IsPayingWithWallet()); | |
| 1406 | |
| 1407 EXPECT_EQ(ASCIIToUTF16("China"), | |
| 1408 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); | |
| 1409 | |
| 1410 // Selecting "Add new shipping address..." with a non-default country should | |
| 1411 // clear the manual input in that section and reset to default country. | |
| 1412 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); | |
| 1413 | |
| 1414 EXPECT_EQ(base::string16(), view->GetTextContentsOfInput(NAME_FULL)); | |
|
Evan Stade
2014/01/14 17:19:38
you should also check that NAME_FULL still has som
Dan Beam
2014/01/15 03:10:48
oh, I did have that... somehow it got dropped. ad
| |
| 1415 EXPECT_EQ(ASCIIToUTF16("United States"), | |
| 1416 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); | |
| 1417 } | |
| 1418 | |
| 1341 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. | 1419 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. |
| 1342 class AutofillDialogControllerSecurityTest : | 1420 class AutofillDialogControllerSecurityTest : |
| 1343 public AutofillDialogControllerTest { | 1421 public AutofillDialogControllerTest { |
| 1344 public: | 1422 public: |
| 1345 AutofillDialogControllerSecurityTest() {} | 1423 AutofillDialogControllerSecurityTest() {} |
| 1346 virtual ~AutofillDialogControllerSecurityTest() {} | 1424 virtual ~AutofillDialogControllerSecurityTest() {} |
| 1347 | 1425 |
| 1348 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1426 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 1349 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); | 1427 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); |
| 1350 } | 1428 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 MAYBE_DoesntWorkOnBrokenHttps) { | 1475 MAYBE_DoesntWorkOnBrokenHttps) { |
| 1398 net::SpawnedTestServer https_server( | 1476 net::SpawnedTestServer https_server( |
| 1399 net::SpawnedTestServer::TYPE_HTTPS, | 1477 net::SpawnedTestServer::TYPE_HTTPS, |
| 1400 SSLOptions(SSLOptions::CERT_EXPIRED), | 1478 SSLOptions(SSLOptions::CERT_EXPIRED), |
| 1401 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1479 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 1402 ASSERT_TRUE(https_server.Start()); | 1480 ASSERT_TRUE(https_server.Start()); |
| 1403 EXPECT_FALSE(RunTestPage(https_server)); | 1481 EXPECT_FALSE(RunTestPage(https_server)); |
| 1404 } | 1482 } |
| 1405 | 1483 |
| 1406 } // namespace autofill | 1484 } // namespace autofill |
| OLD | NEW |