| 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 class TestAutofillDialogView : public AutofillDialogView { | 46 class TestAutofillDialogView : public AutofillDialogView { |
| 48 public: | 47 public: |
| 49 TestAutofillDialogView() {} | 48 TestAutofillDialogView() {} |
| 50 virtual ~TestAutofillDialogView() {} | 49 virtual ~TestAutofillDialogView() {} |
| 51 | 50 |
| 52 virtual void Show() OVERRIDE {} | 51 virtual void Show() OVERRIDE {} |
| 53 virtual void Hide() OVERRIDE {} | 52 virtual void Hide() OVERRIDE {} |
| 54 virtual void UpdateNotificationArea() OVERRIDE {} | 53 virtual void UpdateNotificationArea() OVERRIDE {} |
| 55 virtual void UpdateAccountChooser() OVERRIDE {} | 54 virtual void UpdateAccountChooser() OVERRIDE {} |
| 56 virtual void UpdateButtonStrip() OVERRIDE {} | 55 virtual void UpdateButtonStrip() OVERRIDE {} |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 TestPersonalDataManager test_manager_; | 236 TestPersonalDataManager test_manager_; |
| 238 testing::NiceMock<TestWalletClient> test_wallet_client_; | 237 testing::NiceMock<TestWalletClient> test_wallet_client_; |
| 239 bool is_first_run_; | 238 bool is_first_run_; |
| 240 GURL open_tab_url_; | 239 GURL open_tab_url_; |
| 241 DialogType dialog_type_; | 240 DialogType dialog_type_; |
| 242 | 241 |
| 243 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 242 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 244 }; | 243 }; |
| 245 | 244 |
| 246 class AutofillDialogControllerTest : public testing::Test { | 245 class AutofillDialogControllerTest : public testing::Test { |
| 247 public: | 246 protected: |
| 248 AutofillDialogControllerTest() | |
| 249 : ui_thread_(BrowserThread::UI, &loop_), | |
| 250 file_thread_(BrowserThread::FILE), | |
| 251 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | |
| 252 io_thread_(BrowserThread::IO) { | |
| 253 file_thread_.Start(); | |
| 254 file_blocking_thread_.Start(); | |
| 255 io_thread_.StartIOThread(); | |
| 256 } | |
| 257 | |
| 258 virtual ~AutofillDialogControllerTest() {} | |
| 259 | |
| 260 // testing::Test implementation: | 247 // testing::Test implementation: |
| 261 virtual void SetUp() OVERRIDE { | 248 virtual void SetUp() OVERRIDE { |
| 262 FormData form_data; | 249 FormData form_data; |
| 263 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { | 250 for (size_t i = 0; i < arraysize(kFieldsFromPage); ++i) { |
| 264 FormFieldData field; | 251 FormFieldData field; |
| 265 field.autocomplete_attribute = kFieldsFromPage[i]; | 252 field.autocomplete_attribute = kFieldsFromPage[i]; |
| 266 form_data.fields.push_back(field); | 253 form_data.fields.push_back(field); |
| 267 } | 254 } |
| 268 | 255 |
| 269 profile()->CreateRequestContext(); | 256 profile()->CreateRequestContext(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 TestingProfile* profile() { return &profile_; } | 323 TestingProfile* profile() { return &profile_; } |
| 337 | 324 |
| 338 const FormStructure* form_structure() { return form_structure_; } | 325 const FormStructure* form_structure() { return form_structure_; } |
| 339 | 326 |
| 340 private: | 327 private: |
| 341 void FinishedCallback(const FormStructure* form_structure, | 328 void FinishedCallback(const FormStructure* form_structure, |
| 342 const std::string& google_transaction_id) { | 329 const std::string& google_transaction_id) { |
| 343 form_structure_ = form_structure; | 330 form_structure_ = form_structure; |
| 344 } | 331 } |
| 345 | 332 |
| 333 // Must be first member to ensure TestBrowserThreads outlive other objects. |
| 334 content::TestBrowserThreadBundle thread_bundle_; |
| 335 |
| 346 #if defined(OS_WIN) | 336 #if defined(OS_WIN) |
| 347 // http://crbug.com/227221 | 337 // http://crbug.com/227221 |
| 348 ui::ScopedOleInitializer ole_initializer_; | 338 ui::ScopedOleInitializer ole_initializer_; |
| 349 #endif | 339 #endif |
| 350 | 340 |
| 351 // A bunch of threads are necessary for classes like TestWebContents and | |
| 352 // URLRequestContextGetter not to fall over. | |
| 353 base::MessageLoopForUI loop_; | |
| 354 content::TestBrowserThread ui_thread_; | |
| 355 content::TestBrowserThread file_thread_; | |
| 356 content::TestBrowserThread file_blocking_thread_; | |
| 357 content::TestBrowserThread io_thread_; | |
| 358 TestingProfile profile_; | 341 TestingProfile profile_; |
| 359 | 342 |
| 360 // The controller owns itself. | 343 // The controller owns itself. |
| 361 base::WeakPtr<TestAutofillDialogController> controller_; | 344 base::WeakPtr<TestAutofillDialogController> controller_; |
| 362 | 345 |
| 363 scoped_ptr<content::WebContents> test_web_contents_; | 346 scoped_ptr<content::WebContents> test_web_contents_; |
| 364 | 347 |
| 365 // Must outlive the controller. | 348 // Must outlive the controller. |
| 366 AutofillMetrics metric_logger_; | 349 AutofillMetrics metric_logger_; |
| 367 | 350 |
| 368 // Returned when the dialog closes successfully. | 351 // Returned when the dialog closes successfully. |
| 369 const FormStructure* form_structure_; | 352 const FormStructure* form_structure_; |
| 370 | |
| 371 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | |
| 372 }; | 353 }; |
| 373 | 354 |
| 374 } // namespace | 355 } // namespace |
| 375 | 356 |
| 376 // This test makes sure nothing falls over when fields are being validity- | 357 // This test makes sure nothing falls over when fields are being validity- |
| 377 // checked. | 358 // checked. |
| 378 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 359 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
| 379 const DialogSection sections[] = { | 360 const DialogSection sections[] = { |
| 380 SECTION_EMAIL, | 361 SECTION_EMAIL, |
| 381 SECTION_CC, | 362 SECTION_CC, |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1191 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 1211 | 1192 |
| 1212 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); | 1193 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); |
| 1213 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); | 1194 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); |
| 1214 | 1195 |
| 1215 profile()->set_incognito(true); | 1196 profile()->set_incognito(true); |
| 1216 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); | 1197 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); |
| 1217 } | 1198 } |
| 1218 | 1199 |
| 1219 } // namespace autofill | 1200 } // namespace autofill |
| OLD | NEW |