| 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/test_personal_data_manager.h" | 17 #include "components/autofill/browser/test_personal_data_manager.h" |
| 17 #include "components/autofill/browser/wallet/full_wallet.h" | 18 #include "components/autofill/browser/wallet/full_wallet.h" |
| 18 #include "components/autofill/browser/wallet/instrument.h" | 19 #include "components/autofill/browser/wallet/instrument.h" |
| 19 #include "components/autofill/browser/wallet/wallet_address.h" | 20 #include "components/autofill/browser/wallet/wallet_address.h" |
| 20 #include "components/autofill/browser/wallet/wallet_client.h" | 21 #include "components/autofill/browser/wallet/wallet_client.h" |
| 21 #include "components/autofill/browser/wallet/wallet_test_util.h" | 22 #include "components/autofill/browser/wallet/wallet_test_util.h" |
| 22 #include "components/autofill/common/form_data.h" | 23 #include "components/autofill/common/form_data.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 25 #include "content/public/test/web_contents_tester.h" | 26 #include "content/public/test/web_contents_tester.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 #include "ui/base/win/scoped_ole_initializer.h" | 31 #include "ui/base/win/scoped_ole_initializer.h" |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 using testing::_; | 34 using testing::_; |
| 34 | 35 |
| 35 namespace autofill { | 36 namespace autofill { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 const char kFakeEmail[] = "user@example.com"; | 40 const char kFakeEmail[] = "user@example.com"; |
| 40 const char kEditedBillingAddress[] = "123 edited billing address"; | 41 const char kEditedBillingAddress[] = "123 edited billing address"; |
| 41 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region", | 42 const char* kFieldsFromPage[] = { "email", "cc-number", "billing region", |
| 42 "shipping region" }; | 43 "shipping region" }; |
| 43 const char kSettingsOrigin[] = "Chrome settings"; | 44 const char kSettingsOrigin[] = "Chrome settings"; |
| 44 | 45 |
| 45 using content::BrowserThread; | |
| 46 | |
| 47 void SetOutputValue(const DetailInputs& inputs, | 46 void SetOutputValue(const DetailInputs& inputs, |
| 48 DetailOutputMap* outputs, | 47 DetailOutputMap* outputs, |
| 49 AutofillFieldType type, | 48 AutofillFieldType type, |
| 50 const std::string& value) { | 49 const std::string& value) { |
| 51 for (size_t i = 0; i < inputs.size(); ++i) { | 50 for (size_t i = 0; i < inputs.size(); ++i) { |
| 52 const DetailInput& input = inputs[i]; | 51 const DetailInput& input = inputs[i]; |
| 53 (*outputs)[&input] = input.type == type ? | 52 (*outputs)[&input] = input.type == type ? |
| 54 ASCIIToUTF16(value) : | 53 ASCIIToUTF16(value) : |
| 55 input.initial_value; | 54 input.initial_value; |
| 56 } | 55 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 TestPersonalDataManager test_manager_; | 248 TestPersonalDataManager test_manager_; |
| 250 testing::NiceMock<TestWalletClient> test_wallet_client_; | 249 testing::NiceMock<TestWalletClient> test_wallet_client_; |
| 251 bool is_first_run_; | 250 bool is_first_run_; |
| 252 GURL open_tab_url_; | 251 GURL open_tab_url_; |
| 253 DialogType dialog_type_; | 252 DialogType dialog_type_; |
| 254 | 253 |
| 255 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 254 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 256 }; | 255 }; |
| 257 | 256 |
| 258 class AutofillDialogControllerTest : public testing::Test { | 257 class AutofillDialogControllerTest : public testing::Test { |
| 259 public: | 258 protected: |
| 260 AutofillDialogControllerTest() | |
| 261 : ui_thread_(BrowserThread::UI, &loop_), | |
| 262 file_thread_(BrowserThread::FILE), | |
| 263 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | |
| 264 io_thread_(BrowserThread::IO) { | |
| 265 file_thread_.Start(); | |
| 266 file_blocking_thread_.Start(); | |
| 267 io_thread_.StartIOThread(); | |
| 268 } | |
| 269 | |
| 270 virtual ~AutofillDialogControllerTest() {} | |
| 271 | |
| 272 // testing::Test implementation: | 259 // testing::Test implementation: |
| 273 virtual void SetUp() OVERRIDE { | 260 virtual void SetUp() OVERRIDE { |
| 274 FormData form_data; | 261 FormData form_data; |
| 275 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { | 262 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| 276 FormFieldData field; | 263 FormFieldData field; |
| 277 field.autocomplete_attribute = kFieldsFromPage[i]; | 264 field.autocomplete_attribute = kFieldsFromPage[i]; |
| 278 form_data.fields.push_back(field); | 265 form_data.fields.push_back(field); |
| 279 } | 266 } |
| 280 | 267 |
| 281 profile()->CreateRequestContext(); | 268 profile()->CreateRequestContext(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 TestingProfile* profile() { return &profile_; } | 335 TestingProfile* profile() { return &profile_; } |
| 349 | 336 |
| 350 const FormStructure* form_structure() { return form_structure_; } | 337 const FormStructure* form_structure() { return form_structure_; } |
| 351 | 338 |
| 352 private: | 339 private: |
| 353 void FinishedCallback(const FormStructure* form_structure, | 340 void FinishedCallback(const FormStructure* form_structure, |
| 354 const std::string& google_transaction_id) { | 341 const std::string& google_transaction_id) { |
| 355 form_structure_ = form_structure; | 342 form_structure_ = form_structure; |
| 356 } | 343 } |
| 357 | 344 |
| 345 // Must be first member to ensure TestBrowserThreads outlive other objects. |
| 346 content::TestBrowserThreadBundle thread_bundle_; |
| 347 |
| 358 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
| 359 // http://crbug.com/227221 | 349 // http://crbug.com/227221 |
| 360 ui::ScopedOleInitializer ole_initializer_; | 350 ui::ScopedOleInitializer ole_initializer_; |
| 361 #endif | 351 #endif |
| 362 | 352 |
| 363 // A bunch of threads are necessary for classes like TestWebContents and | |
| 364 // URLRequestContextGetter not to fall over. | |
| 365 base::MessageLoopForUI loop_; | |
| 366 content::TestBrowserThread ui_thread_; | |
| 367 content::TestBrowserThread file_thread_; | |
| 368 content::TestBrowserThread file_blocking_thread_; | |
| 369 content::TestBrowserThread io_thread_; | |
| 370 TestingProfile profile_; | 353 TestingProfile profile_; |
| 371 | 354 |
| 372 // The controller owns itself. | 355 // The controller owns itself. |
| 373 base::WeakPtr<TestAutofillDialogController> controller_; | 356 base::WeakPtr<TestAutofillDialogController> controller_; |
| 374 | 357 |
| 375 scoped_ptr<content::WebContents> test_web_contents_; | 358 scoped_ptr<content::WebContents> test_web_contents_; |
| 376 | 359 |
| 377 // Must outlive the controller. | 360 // Must outlive the controller. |
| 378 AutofillMetrics metric_logger_; | 361 AutofillMetrics metric_logger_; |
| 379 | 362 |
| 380 // Returned when the dialog closes successfully. | 363 // Returned when the dialog closes successfully. |
| 381 const FormStructure* form_structure_; | 364 const FormStructure* form_structure_; |
| 382 | |
| 383 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | |
| 384 }; | 365 }; |
| 385 | 366 |
| 386 } // namespace | 367 } // namespace |
| 387 | 368 |
| 388 // This test makes sure nothing falls over when fields are being validity- | 369 // This test makes sure nothing falls over when fields are being validity- |
| 389 // checked. | 370 // checked. |
| 390 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 371 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
| 391 const DialogSection sections[] = { | 372 const DialogSection sections[] = { |
| 392 SECTION_EMAIL, | 373 SECTION_EMAIL, |
| 393 SECTION_CC, | 374 SECTION_CC, |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1287 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 1307 | 1288 |
| 1308 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 1289 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
| 1309 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 1290 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
| 1310 | 1291 |
| 1311 profile()->set_incognito(true); | 1292 profile()->set_incognito(true); |
| 1312 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1293 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 1313 } | 1294 } |
| 1314 | 1295 |
| 1315 } // namespace autofill | 1296 } // namespace autofill |
| OLD | NEW |