| 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/guid.h" | 5 #include "base/guid.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/run_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 11 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/autofill/browser/autofill_common_test.h" | 15 #include "components/autofill/browser/autofill_common_test.h" |
| 15 #include "components/autofill/browser/autofill_metrics.h" | 16 #include "components/autofill/browser/autofill_metrics.h" |
| 16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" | 17 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" |
| 17 #include "components/autofill/browser/test_personal_data_manager.h" | 18 #include "components/autofill/browser/test_personal_data_manager.h" |
| 18 #include "components/autofill/browser/wallet/full_wallet.h" | 19 #include "components/autofill/browser/wallet/full_wallet.h" |
| 19 #include "components/autofill/browser/wallet/instrument.h" | 20 #include "components/autofill/browser/wallet/instrument.h" |
| 20 #include "components/autofill/browser/wallet/wallet_address.h" | 21 #include "components/autofill/browser/wallet/wallet_address.h" |
| 21 #include "components/autofill/browser/wallet/wallet_client.h" | 22 #include "components/autofill/browser/wallet/wallet_client.h" |
| 22 #include "components/autofill/browser/wallet/wallet_test_util.h" | 23 #include "components/autofill/browser/wallet/wallet_test_util.h" |
| 23 #include "components/autofill/common/form_data.h" | 24 #include "components/autofill/common/form_data.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "content/public/test/web_contents_tester.h" | 27 #include "content/public/test/web_contents_tester.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 31 #include "ui/base/win/scoped_ole_initializer.h" | 32 #include "ui/base/win/scoped_ole_initializer.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 using testing::_; | 35 using testing::_; |
| 35 | 36 |
| 36 namespace autofill { | 37 namespace autofill { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const char kFakeEmail[] = "user@example.com"; | 41 const char kFakeEmail[] = "user@example.com"; |
| 41 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; | 42 const char kFakeFingerprintEncoded[] = "CgVaAwiACA=="; |
| 42 const char kEditedBillingAddress[] = "123 edited billing address"; | 43 const char kEditedBillingAddress[] = "123 edited billing address"; |
| 43 const char* kFieldsFromPage[] = | 44 const char* kFieldsFromPage[] = |
| 44 { "email", "cc-number", "billing region", "shipping region" }; | 45 { "email", "cc-number", "billing region", "shipping region" }; |
| 45 const char kSettingsOrigin[] = "Chrome settings"; | 46 const char kSettingsOrigin[] = "Chrome settings"; |
| 46 | 47 |
| 47 using content::BrowserThread; | |
| 48 | |
| 49 void SetOutputValue(const DetailInputs& inputs, | 48 void SetOutputValue(const DetailInputs& inputs, |
| 50 DetailOutputMap* outputs, | 49 DetailOutputMap* outputs, |
| 51 AutofillFieldType type, | 50 AutofillFieldType type, |
| 52 const std::string& value) { | 51 const std::string& value) { |
| 53 for (size_t i = 0; i < inputs.size(); ++i) { | 52 for (size_t i = 0; i < inputs.size(); ++i) { |
| 54 const DetailInput& input = inputs[i]; | 53 const DetailInput& input = inputs[i]; |
| 55 (*outputs)[&input] = input.type == type ? | 54 (*outputs)[&input] = input.type == type ? |
| 56 ASCIIToUTF16(value) : | 55 ASCIIToUTF16(value) : |
| 57 input.initial_value; | 56 input.initial_value; |
| 58 } | 57 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 TestPersonalDataManager test_manager_; | 274 TestPersonalDataManager test_manager_; |
| 276 testing::NiceMock<TestWalletClient> test_wallet_client_; | 275 testing::NiceMock<TestWalletClient> test_wallet_client_; |
| 277 bool is_first_run_; | 276 bool is_first_run_; |
| 278 GURL open_tab_url_; | 277 GURL open_tab_url_; |
| 279 DialogType dialog_type_; | 278 DialogType dialog_type_; |
| 280 | 279 |
| 281 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 280 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 282 }; | 281 }; |
| 283 | 282 |
| 284 class AutofillDialogControllerTest : public testing::Test { | 283 class AutofillDialogControllerTest : public testing::Test { |
| 285 public: | 284 protected: |
| 286 AutofillDialogControllerTest() | |
| 287 : ui_thread_(BrowserThread::UI, &loop_), | |
| 288 file_thread_(BrowserThread::FILE), | |
| 289 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | |
| 290 io_thread_(BrowserThread::IO) { | |
| 291 file_thread_.Start(); | |
| 292 file_blocking_thread_.Start(); | |
| 293 io_thread_.StartIOThread(); | |
| 294 } | |
| 295 | |
| 296 virtual ~AutofillDialogControllerTest() {} | |
| 297 | |
| 298 // testing::Test implementation: | 285 // testing::Test implementation: |
| 299 virtual void SetUp() OVERRIDE { | 286 virtual void SetUp() OVERRIDE { |
| 300 FormData form_data; | 287 FormData form_data; |
| 301 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { | 288 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| 302 FormFieldData field; | 289 FormFieldData field; |
| 303 field.autocomplete_attribute = kFieldsFromPage[i]; | 290 field.autocomplete_attribute = kFieldsFromPage[i]; |
| 304 form_data.fields.push_back(field); | 291 form_data.fields.push_back(field); |
| 305 } | 292 } |
| 306 | 293 |
| 307 profile()->CreateRequestContext(); | 294 profile()->CreateRequestContext(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 TestingProfile* profile() { return &profile_; } | 364 TestingProfile* profile() { return &profile_; } |
| 378 | 365 |
| 379 const FormStructure* form_structure() { return form_structure_; } | 366 const FormStructure* form_structure() { return form_structure_; } |
| 380 | 367 |
| 381 private: | 368 private: |
| 382 void FinishedCallback(const FormStructure* form_structure, | 369 void FinishedCallback(const FormStructure* form_structure, |
| 383 const std::string& google_transaction_id) { | 370 const std::string& google_transaction_id) { |
| 384 form_structure_ = form_structure; | 371 form_structure_ = form_structure; |
| 385 } | 372 } |
| 386 | 373 |
| 374 // Must be first member to ensure TestBrowserThreads outlive other objects. |
| 375 content::TestBrowserThreadBundle thread_bundle_; |
| 376 |
| 387 #if defined(OS_WIN) | 377 #if defined(OS_WIN) |
| 388 // http://crbug.com/227221 | 378 // http://crbug.com/227221 |
| 389 ui::ScopedOleInitializer ole_initializer_; | 379 ui::ScopedOleInitializer ole_initializer_; |
| 390 #endif | 380 #endif |
| 391 | 381 |
| 392 // A bunch of threads are necessary for classes like TestWebContents and | |
| 393 // URLRequestContextGetter not to fall over. | |
| 394 base::MessageLoopForUI loop_; | |
| 395 content::TestBrowserThread ui_thread_; | |
| 396 content::TestBrowserThread file_thread_; | |
| 397 content::TestBrowserThread file_blocking_thread_; | |
| 398 content::TestBrowserThread io_thread_; | |
| 399 TestingProfile profile_; | 382 TestingProfile profile_; |
| 400 | 383 |
| 401 // The controller owns itself. | 384 // The controller owns itself. |
| 402 base::WeakPtr<TestAutofillDialogController> controller_; | 385 base::WeakPtr<TestAutofillDialogController> controller_; |
| 403 | 386 |
| 404 scoped_ptr<content::WebContents> test_web_contents_; | 387 scoped_ptr<content::WebContents> test_web_contents_; |
| 405 | 388 |
| 406 // Must outlive the controller. | 389 // Must outlive the controller. |
| 407 AutofillMetrics metric_logger_; | 390 AutofillMetrics metric_logger_; |
| 408 | 391 |
| 409 // Returned when the dialog closes successfully. | 392 // Returned when the dialog closes successfully. |
| 410 const FormStructure* form_structure_; | 393 const FormStructure* form_structure_; |
| 411 | |
| 412 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | |
| 413 }; | 394 }; |
| 414 | 395 |
| 415 } // namespace | 396 } // namespace |
| 416 | 397 |
| 417 // This test makes sure nothing falls over when fields are being validity- | 398 // This test makes sure nothing falls over when fields are being validity- |
| 418 // checked. | 399 // checked. |
| 419 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 400 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
| 420 const DialogSection sections[] = { | 401 const DialogSection sections[] = { |
| 421 SECTION_EMAIL, | 402 SECTION_EMAIL, |
| 422 SECTION_CC, | 403 SECTION_CC, |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 controller()->OnDidGetWalletItems( | 1797 controller()->OnDidGetWalletItems( |
| 1817 wallet::WalletItems::CreateWalletItems(dict).Pass()); | 1798 wallet::WalletItems::CreateWalletItems(dict).Pass()); |
| 1818 | 1799 |
| 1819 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 1800 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
| 1820 // "Same as billing" and "Add address...". | 1801 // "Same as billing" and "Add address...". |
| 1821 EXPECT_EQ( | 1802 EXPECT_EQ( |
| 1822 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 1803 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
| 1823 } | 1804 } |
| 1824 | 1805 |
| 1825 } // namespace autofill | 1806 } // namespace autofill |
| OLD | NEW |