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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 178 |
177 void set_notifications(const std::vector<DialogNotification>& notifications) { | 179 void set_notifications(const std::vector<DialogNotification>& notifications) { |
178 notifications_ = notifications; | 180 notifications_ = notifications; |
179 } | 181 } |
180 | 182 |
181 TestPersonalDataManager* GetTestingManager() { | 183 TestPersonalDataManager* GetTestingManager() { |
182 return &test_manager_; | 184 return &test_manager_; |
183 } | 185 } |
184 | 186 |
185 using AutofillDialogControllerImpl::IsEditingExistingData; | 187 using AutofillDialogControllerImpl::IsEditingExistingData; |
| 188 using AutofillDialogControllerImpl::IsManuallyEditingSection; |
186 using AutofillDialogControllerImpl::IsPayingWithWallet; | 189 using AutofillDialogControllerImpl::IsPayingWithWallet; |
187 using AutofillDialogControllerImpl::IsSubmitPausedOn; | 190 using AutofillDialogControllerImpl::IsSubmitPausedOn; |
188 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 191 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
189 using AutofillDialogControllerImpl::AccountChooserModelForTesting; | 192 using AutofillDialogControllerImpl::AccountChooserModelForTesting; |
190 using AutofillDialogControllerImpl:: | 193 using AutofillDialogControllerImpl:: |
191 ClearLastWalletItemsFetchTimestampForTesting; | 194 ClearLastWalletItemsFetchTimestampForTesting; |
192 | 195 |
193 void set_use_validation(bool use_validation) { | 196 void set_use_validation(bool use_validation) { |
194 use_validation_ = use_validation; | 197 use_validation_ = use_validation; |
195 } | 198 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 RunMessageLoop(); | 550 RunMessageLoop(); |
548 | 551 |
549 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 552 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
550 metric_logger().dialog_dismissal_action()); | 553 metric_logger().dialog_dismissal_action()); |
551 } | 554 } |
552 | 555 |
553 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { | 556 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { |
554 AutofillProfile full_profile(test::GetFullProfile()); | 557 AutofillProfile full_profile(test::GetFullProfile()); |
555 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 558 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
556 | 559 |
| 560 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 561 model->ActivatedAt(model->GetItemCount() - 2); |
| 562 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 563 |
557 const DetailInputs& inputs = | 564 const DetailInputs& inputs = |
558 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 565 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
559 const ServerFieldType triggering_type = inputs[0].type; | 566 const ServerFieldType triggering_type = inputs[0].type; |
560 base::string16 value = full_profile.GetRawInfo(triggering_type); | 567 base::string16 value = full_profile.GetRawInfo(triggering_type); |
561 TestableAutofillDialogView* view = controller()->GetTestableView(); | 568 TestableAutofillDialogView* view = controller()->GetTestableView(); |
562 view->SetTextContentsOfInput(triggering_type, | 569 view->SetTextContentsOfInput(triggering_type, |
563 value.substr(0, value.size() / 2)); | 570 value.substr(0, value.size() / 2)); |
564 view->ActivateInput(triggering_type); | 571 view->ActivateInput(triggering_type); |
565 | 572 |
566 ASSERT_EQ(triggering_type, controller()->popup_input_type()); | 573 ASSERT_EQ(triggering_type, controller()->popup_input_type()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 607 |
601 // For now, no matter what, the country must always be US. See | 608 // For now, no matter what, the country must always be US. See |
602 // http://crbug.com/247518 | 609 // http://crbug.com/247518 |
603 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 610 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
604 FillInputFromForeignProfile) { | 611 FillInputFromForeignProfile) { |
605 AutofillProfile full_profile(test::GetFullProfile()); | 612 AutofillProfile full_profile(test::GetFullProfile()); |
606 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 613 full_profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), |
607 ASCIIToUTF16("France"), "en-US"); | 614 ASCIIToUTF16("France"), "en-US"); |
608 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 615 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
609 | 616 |
| 617 ui::MenuModel* model = controller()->MenuModelForSection(SECTION_SHIPPING); |
| 618 model->ActivatedAt(model->GetItemCount() - 2); |
| 619 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 620 |
610 const DetailInputs& inputs = | 621 const DetailInputs& inputs = |
611 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 622 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
612 const ServerFieldType triggering_type = inputs[0].type; | 623 const ServerFieldType triggering_type = inputs[0].type; |
613 base::string16 value = full_profile.GetRawInfo(triggering_type); | 624 base::string16 value = full_profile.GetRawInfo(triggering_type); |
614 TestableAutofillDialogView* view = controller()->GetTestableView(); | 625 TestableAutofillDialogView* view = controller()->GetTestableView(); |
615 view->SetTextContentsOfInput(triggering_type, | 626 view->SetTextContentsOfInput(triggering_type, |
616 value.substr(0, value.size() / 2)); | 627 value.substr(0, value.size() / 2)); |
617 view->ActivateInput(triggering_type); | 628 view->ActivateInput(triggering_type); |
618 | 629 |
619 ASSERT_EQ(triggering_type, controller()->popup_input_type()); | 630 ASSERT_EQ(triggering_type, controller()->popup_input_type()); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 | 1094 |
1084 controller()->OnDidGetWalletItems( | 1095 controller()->OnDidGetWalletItems( |
1085 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); | 1096 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
1086 | 1097 |
1087 // Wallet should now be selected and Chrome shouldn't have crashed (which can | 1098 // Wallet should now be selected and Chrome shouldn't have crashed (which can |
1088 // happen if the WebContents is deleted while proccessing a nav entry commit). | 1099 // happen if the WebContents is deleted while proccessing a nav entry commit). |
1089 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); | 1100 EXPECT_TRUE(account_chooser_model->WalletIsSelected()); |
1090 } | 1101 } |
1091 | 1102 |
1092 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { | 1103 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AddAccount) { |
1093 InitializeController(); | |
1094 | |
1095 controller()->OnDidFetchWalletCookieValue(std::string()); | 1104 controller()->OnDidFetchWalletCookieValue(std::string()); |
1096 std::vector<std::string> usernames; | 1105 std::vector<std::string> usernames; |
1097 usernames.push_back("user_0@example.com"); | 1106 usernames.push_back("user_0@example.com"); |
1098 controller()->OnDidGetWalletItems( | 1107 controller()->OnDidGetWalletItems( |
1099 wallet::GetTestWalletItemsWithUsers(usernames, 0)); | 1108 wallet::GetTestWalletItemsWithUsers(usernames, 0)); |
1100 | 1109 |
1101 // Switch to Autofill. | 1110 // Switch to Autofill. |
1102 AccountChooserModel* account_chooser_model = | 1111 AccountChooserModel* account_chooser_model = |
1103 controller()->AccountChooserModelForTesting(); | 1112 controller()->AccountChooserModelForTesting(); |
1104 account_chooser_model->ActivatedAt( | 1113 account_chooser_model->ActivatedAt( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 1333 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
1325 MAYBE_DoesWorkOnHttpWithFlag) { | 1334 MAYBE_DoesWorkOnHttpWithFlag) { |
1326 net::SpawnedTestServer http_server( | 1335 net::SpawnedTestServer http_server( |
1327 net::SpawnedTestServer::TYPE_HTTP, | 1336 net::SpawnedTestServer::TYPE_HTTP, |
1328 net::SpawnedTestServer::kLocalhost, | 1337 net::SpawnedTestServer::kLocalhost, |
1329 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1338 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1330 ASSERT_TRUE(http_server.Start()); | 1339 ASSERT_TRUE(http_server.Start()); |
1331 EXPECT_TRUE(RunTestPage(http_server)); | 1340 EXPECT_TRUE(RunTestPage(http_server)); |
1332 } | 1341 } |
1333 | 1342 |
| 1343 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 1344 CountryChangeRebuildsSection) { |
| 1345 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1346 command_line->AppendSwitch(::switches::kEnableAutofillAddressI18n); |
| 1347 ASSERT_TRUE(i18ninput::Enabled()); |
| 1348 |
| 1349 InitializeController(); |
| 1350 |
| 1351 controller()->OnDidFetchWalletCookieValue(std::string()); |
| 1352 controller()->OnDidGetWalletItems( |
| 1353 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED)); |
| 1354 EXPECT_TRUE(controller()->IsPayingWithWallet()); |
| 1355 |
| 1356 // Select "Add new shipping address...". |
| 1357 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); |
| 1358 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1359 |
| 1360 TestableAutofillDialogView* view = controller()->GetTestableView(); |
| 1361 ASSERT_EQ(ASCIIToUTF16("United States"), |
| 1362 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); |
| 1363 |
| 1364 const DetailInputs& us_inputs = |
| 1365 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 1366 EXPECT_EQ(8U, us_inputs.size()); |
| 1367 |
| 1368 // Check that there's no dependent locality for the US layout. |
| 1369 for (size_t i = 0; i < us_inputs.size(); ++i) { |
| 1370 EXPECT_NE(us_inputs[i].type, ADDRESS_HOME_DEPENDENT_LOCALITY); |
| 1371 } |
| 1372 |
| 1373 // Add some valid user input that should be preserved when country changes and |
| 1374 // switch from United States to China. |
| 1375 view->SetTextContentsOfInput(NAME_FULL, ASCIIToUTF16("B. Loblaw")); |
| 1376 view->SetTextContentsOfInput(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("China")); |
| 1377 ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_SHIPPING)); |
| 1378 |
| 1379 EXPECT_EQ(ASCIIToUTF16("B. Loblaw"), view->GetTextContentsOfInput(NAME_FULL)); |
| 1380 EXPECT_EQ(ASCIIToUTF16("China"), |
| 1381 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); |
| 1382 |
| 1383 const DetailInputs& cn_inputs = |
| 1384 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
| 1385 EXPECT_EQ(9U, cn_inputs.size()); |
| 1386 |
| 1387 // Check that there is dependent locality for the Chinese layout. |
| 1388 size_t i = 0; |
| 1389 for (; i < cn_inputs.size(); ++i) { |
| 1390 if (cn_inputs[i].type == ADDRESS_HOME_DEPENDENT_LOCALITY) |
| 1391 break; |
| 1392 } |
| 1393 EXPECT_LT(i, cn_inputs.size()); |
| 1394 |
| 1395 // Changing data sources should preserve country selection. |
| 1396 ui::MenuModel* account_chooser = controller()->MenuModelForAccountChooser(); |
| 1397 account_chooser->ActivatedAt(account_chooser->GetItemCount() - 1); |
| 1398 EXPECT_FALSE(controller()->IsPayingWithWallet()); |
| 1399 |
| 1400 EXPECT_EQ(ASCIIToUTF16("China"), |
| 1401 view->GetTextContentsOfInput(ADDRESS_HOME_COUNTRY)); |
| 1402 } |
| 1403 |
1334 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. | 1404 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. |
1335 class AutofillDialogControllerSecurityTest : | 1405 class AutofillDialogControllerSecurityTest : |
1336 public AutofillDialogControllerTest { | 1406 public AutofillDialogControllerTest { |
1337 public: | 1407 public: |
1338 AutofillDialogControllerSecurityTest() {} | 1408 AutofillDialogControllerSecurityTest() {} |
1339 virtual ~AutofillDialogControllerSecurityTest() {} | 1409 virtual ~AutofillDialogControllerSecurityTest() {} |
1340 | 1410 |
1341 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1411 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
1342 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); | 1412 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); |
1343 } | 1413 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 MAYBE_DoesntWorkOnBrokenHttps) { | 1460 MAYBE_DoesntWorkOnBrokenHttps) { |
1391 net::SpawnedTestServer https_server( | 1461 net::SpawnedTestServer https_server( |
1392 net::SpawnedTestServer::TYPE_HTTPS, | 1462 net::SpawnedTestServer::TYPE_HTTPS, |
1393 SSLOptions(SSLOptions::CERT_EXPIRED), | 1463 SSLOptions(SSLOptions::CERT_EXPIRED), |
1394 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1464 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1395 ASSERT_TRUE(https_server.Start()); | 1465 ASSERT_TRUE(https_server.Start()); |
1396 EXPECT_FALSE(RunTestPage(https_server)); | 1466 EXPECT_FALSE(RunTestPage(https_server)); |
1397 } | 1467 } |
1398 | 1468 |
1399 } // namespace autofill | 1469 } // namespace autofill |
OLD | NEW |