| 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 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/run_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 14 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 15 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/autofill/browser/autofill_common_test.h" | 18 #include "components/autofill/browser/autofill_common_test.h" |
| 18 #include "components/autofill/browser/autofill_metrics.h" | 19 #include "components/autofill/browser/autofill_metrics.h" |
| 19 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" | 20 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" |
| 20 #include "components/autofill/browser/test_personal_data_manager.h" | 21 #include "components/autofill/browser/test_personal_data_manager.h" |
| 21 #include "components/autofill/browser/wallet/full_wallet.h" | 22 #include "components/autofill/browser/wallet/full_wallet.h" |
| 22 #include "components/autofill/browser/wallet/instrument.h" | 23 #include "components/autofill/browser/wallet/instrument.h" |
| 23 #include "components/autofill/browser/wallet/wallet_address.h" | 24 #include "components/autofill/browser/wallet/wallet_address.h" |
| 24 #include "components/autofill/browser/wallet/wallet_client.h" | 25 #include "components/autofill/browser/wallet/wallet_client.h" |
| 25 #include "components/autofill/browser/wallet/wallet_service_url.h" | 26 #include "components/autofill/browser/wallet/wallet_service_url.h" |
| 26 #include "components/autofill/browser/wallet/wallet_test_util.h" | 27 #include "components/autofill/browser/wallet/wallet_test_util.h" |
| 27 #include "components/autofill/common/autofill_switches.h" | 28 #include "components/autofill/common/autofill_switches.h" |
| 28 #include "components/autofill/common/form_data.h" | 29 #include "components/autofill/common/form_data.h" |
| 29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "content/public/test/web_contents_tester.h" | 32 #include "content/public/test/web_contents_tester.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 35 |
| 35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 36 #include "ui/base/win/scoped_ole_initializer.h" | 37 #include "ui/base/win/scoped_ole_initializer.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 using testing::_; | 40 using testing::_; |
| 40 | 41 |
| 41 namespace autofill { | 42 namespace autofill { |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 const char kFakeEmail[] = "user@example.com"; | 46 const char kFakeEmail[] = "user@example.com"; |
| 46 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | 47 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; |
| 47 const char kEditedBillingAddress[] = "123 edited billing address"; | 48 const char kEditedBillingAddress[] = "123 edited billing address"; |
| 48 const char* kFieldsFromPage[] = | 49 const char* kFieldsFromPage[] = |
| 49 { "email", "cc-number", "billing region", "shipping region" }; | 50 { "email", "cc-number", "billing region", "shipping region" }; |
| 50 const char kSettingsOrigin[] = "Chrome settings"; | 51 const char kSettingsOrigin[] = "Chrome settings"; |
| 51 | 52 |
| 52 using content::BrowserThread; | |
| 53 | |
| 54 void SetOutputValue(const DetailInputs& inputs, | 53 void SetOutputValue(const DetailInputs& inputs, |
| 55 DetailOutputMap* outputs, | 54 DetailOutputMap* outputs, |
| 56 AutofillFieldType type, | 55 AutofillFieldType type, |
| 57 const std::string& value) { | 56 const std::string& value) { |
| 58 for (size_t i = 0; i < inputs.size(); ++i) { | 57 for (size_t i = 0; i < inputs.size(); ++i) { |
| 59 const DetailInput& input = inputs[i]; | 58 const DetailInput& input = inputs[i]; |
| 60 (*outputs)[&input] = input.type == type ? | 59 (*outputs)[&input] = input.type == type ? |
| 61 ASCIIToUTF16(value) : | 60 ASCIIToUTF16(value) : |
| 62 input.initial_value; | 61 input.initial_value; |
| 63 } | 62 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 TestPersonalDataManager test_manager_; | 279 TestPersonalDataManager test_manager_; |
| 281 testing::NiceMock<TestWalletClient> test_wallet_client_; | 280 testing::NiceMock<TestWalletClient> test_wallet_client_; |
| 282 bool is_first_run_; | 281 bool is_first_run_; |
| 283 GURL open_tab_url_; | 282 GURL open_tab_url_; |
| 284 DialogType dialog_type_; | 283 DialogType dialog_type_; |
| 285 | 284 |
| 286 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 285 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 287 }; | 286 }; |
| 288 | 287 |
| 289 class AutofillDialogControllerTest : public testing::Test { | 288 class AutofillDialogControllerTest : public testing::Test { |
| 290 public: | 289 protected: |
| 291 AutofillDialogControllerTest() | 290 AutofillDialogControllerTest() |
| 292 : ui_thread_(BrowserThread::UI, &loop_), | 291 : form_structure_(NULL) { |
| 293 file_thread_(BrowserThread::FILE), | |
| 294 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | |
| 295 io_thread_(BrowserThread::IO), | |
| 296 form_structure_(NULL) { | |
| 297 file_thread_.Start(); | |
| 298 file_blocking_thread_.Start(); | |
| 299 io_thread_.StartIOThread(); | |
| 300 } | 292 } |
| 301 | 293 |
| 302 virtual ~AutofillDialogControllerTest() {} | |
| 303 | |
| 304 // testing::Test implementation: | 294 // testing::Test implementation: |
| 305 virtual void SetUp() OVERRIDE { | 295 virtual void SetUp() OVERRIDE { |
| 306 profile()->CreateRequestContext(); | 296 profile()->CreateRequestContext(); |
| 307 test_web_contents_.reset( | 297 test_web_contents_.reset( |
| 308 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 298 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
| 309 | 299 |
| 310 SetUpControllerWithFormData(DefaultFormData()); | 300 SetUpControllerWithFormData(DefaultFormData()); |
| 311 } | 301 } |
| 312 | 302 |
| 313 virtual void TearDown() OVERRIDE { | 303 virtual void TearDown() OVERRIDE { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 TestingProfile* profile() { return &profile_; } | 380 TestingProfile* profile() { return &profile_; } |
| 391 | 381 |
| 392 const FormStructure* form_structure() { return form_structure_; } | 382 const FormStructure* form_structure() { return form_structure_; } |
| 393 | 383 |
| 394 private: | 384 private: |
| 395 void FinishedCallback(const FormStructure* form_structure, | 385 void FinishedCallback(const FormStructure* form_structure, |
| 396 const std::string& google_transaction_id) { | 386 const std::string& google_transaction_id) { |
| 397 form_structure_ = form_structure; | 387 form_structure_ = form_structure; |
| 398 } | 388 } |
| 399 | 389 |
| 390 // Must be first member to ensure TestBrowserThreads outlive other objects. |
| 391 content::TestBrowserThreadBundle thread_bundle_; |
| 392 |
| 400 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
| 401 // http://crbug.com/227221 | 394 // http://crbug.com/227221 |
| 402 ui::ScopedOleInitializer ole_initializer_; | 395 ui::ScopedOleInitializer ole_initializer_; |
| 403 #endif | 396 #endif |
| 404 | 397 |
| 405 // A bunch of threads are necessary for classes like TestWebContents and | |
| 406 // URLRequestContextGetter not to fall over. | |
| 407 base::MessageLoopForUI loop_; | |
| 408 content::TestBrowserThread ui_thread_; | |
| 409 content::TestBrowserThread file_thread_; | |
| 410 content::TestBrowserThread file_blocking_thread_; | |
| 411 content::TestBrowserThread io_thread_; | |
| 412 TestingProfile profile_; | 398 TestingProfile profile_; |
| 413 | 399 |
| 414 // The controller owns itself. | 400 // The controller owns itself. |
| 415 base::WeakPtr<TestAutofillDialogController> controller_; | 401 base::WeakPtr<TestAutofillDialogController> controller_; |
| 416 | 402 |
| 417 scoped_ptr<content::WebContents> test_web_contents_; | 403 scoped_ptr<content::WebContents> test_web_contents_; |
| 418 | 404 |
| 419 // Must outlive the controller. | 405 // Must outlive the controller. |
| 420 AutofillMetrics metric_logger_; | 406 AutofillMetrics metric_logger_; |
| 421 | 407 |
| 422 // Returned when the dialog closes successfully. | 408 // Returned when the dialog closes successfully. |
| 423 const FormStructure* form_structure_; | 409 const FormStructure* form_structure_; |
| 424 | |
| 425 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | |
| 426 }; | 410 }; |
| 427 | 411 |
| 428 } // namespace | 412 } // namespace |
| 429 | 413 |
| 430 // This test makes sure nothing falls over when fields are being validity- | 414 // This test makes sure nothing falls over when fields are being validity- |
| 431 // checked. | 415 // checked. |
| 432 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 416 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
| 433 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 417 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 434 DialogSection section = static_cast<DialogSection>(i); | 418 DialogSection section = static_cast<DialogSection>(i); |
| 435 const DetailInputs& shipping_inputs = | 419 const DetailInputs& shipping_inputs = |
| (...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd)); | 1885 ASSERT_FALSE(command_line->HasSwitch(switches::kWalletServiceUseProd)); |
| 1902 EXPECT_FALSE( | 1886 EXPECT_FALSE( |
| 1903 NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); | 1887 NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); |
| 1904 | 1888 |
| 1905 command_line->AppendSwitch(switches::kWalletServiceUseProd); | 1889 command_line->AppendSwitch(switches::kWalletServiceUseProd); |
| 1906 EXPECT_TRUE( | 1890 EXPECT_TRUE( |
| 1907 NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); | 1891 NotificationsOfType(DialogNotification::DEVELOPER_WARNING).empty()); |
| 1908 } | 1892 } |
| 1909 | 1893 |
| 1910 } // namespace autofill | 1894 } // namespace autofill |
| OLD | NEW |