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 |
(...skipping 21 matching lines...) Expand all Loading... |
62 "shipping name", | 63 "shipping name", |
63 "shipping address-line1", | 64 "shipping address-line1", |
64 "shipping locality", | 65 "shipping locality", |
65 "shipping region", | 66 "shipping region", |
66 "shipping postal-code", | 67 "shipping postal-code", |
67 "shipping country", | 68 "shipping country", |
68 "shipping tel", | 69 "shipping tel", |
69 }; | 70 }; |
70 const char kSettingsOrigin[] = "Chrome settings"; | 71 const char kSettingsOrigin[] = "Chrome settings"; |
71 | 72 |
72 using content::BrowserThread; | |
73 | |
74 void SetOutputValue(const DetailInputs& inputs, | 73 void SetOutputValue(const DetailInputs& inputs, |
75 DetailOutputMap* outputs, | 74 DetailOutputMap* outputs, |
76 AutofillFieldType type, | 75 AutofillFieldType type, |
77 const std::string& value) { | 76 const std::string& value) { |
78 for (size_t i = 0; i < inputs.size(); ++i) { | 77 for (size_t i = 0; i < inputs.size(); ++i) { |
79 const DetailInput& input = inputs[i]; | 78 const DetailInput& input = inputs[i]; |
80 (*outputs)[&input] = input.type == type ? | 79 (*outputs)[&input] = input.type == type ? |
81 ASCIIToUTF16(value) : | 80 ASCIIToUTF16(value) : |
82 input.initial_value; | 81 input.initial_value; |
83 } | 82 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 const AutofillMetrics& metric_logger_; | 293 const AutofillMetrics& metric_logger_; |
295 TestPersonalDataManager test_manager_; | 294 TestPersonalDataManager test_manager_; |
296 testing::NiceMock<TestWalletClient> test_wallet_client_; | 295 testing::NiceMock<TestWalletClient> test_wallet_client_; |
297 GURL open_tab_url_; | 296 GURL open_tab_url_; |
298 DialogType dialog_type_; | 297 DialogType dialog_type_; |
299 | 298 |
300 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 299 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
301 }; | 300 }; |
302 | 301 |
303 class AutofillDialogControllerTest : public testing::Test { | 302 class AutofillDialogControllerTest : public testing::Test { |
304 public: | 303 protected: |
305 AutofillDialogControllerTest() | 304 AutofillDialogControllerTest() |
306 : ui_thread_(BrowserThread::UI, &loop_), | 305 : form_structure_(NULL) { |
307 file_thread_(BrowserThread::FILE), | |
308 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), | |
309 io_thread_(BrowserThread::IO), | |
310 form_structure_(NULL) { | |
311 file_thread_.Start(); | |
312 file_blocking_thread_.Start(); | |
313 io_thread_.StartIOThread(); | |
314 } | 306 } |
315 | 307 |
316 virtual ~AutofillDialogControllerTest() {} | |
317 | |
318 // testing::Test implementation: | 308 // testing::Test implementation: |
319 virtual void SetUp() OVERRIDE { | 309 virtual void SetUp() OVERRIDE { |
320 profile()->CreateRequestContext(); | 310 profile()->CreateRequestContext(); |
321 test_web_contents_.reset( | 311 test_web_contents_.reset( |
322 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); | 312 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); |
323 | 313 |
324 SetUpControllerWithFormData(DefaultFormData()); | 314 SetUpControllerWithFormData(DefaultFormData()); |
325 } | 315 } |
326 | 316 |
327 virtual void TearDown() OVERRIDE { | 317 virtual void TearDown() OVERRIDE { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 const FormStructure* form_structure() { return form_structure_; } | 396 const FormStructure* form_structure() { return form_structure_; } |
407 | 397 |
408 private: | 398 private: |
409 void FinishedCallback(const FormStructure* form_structure, | 399 void FinishedCallback(const FormStructure* form_structure, |
410 const std::string& google_transaction_id) { | 400 const std::string& google_transaction_id) { |
411 form_structure_ = form_structure; | 401 form_structure_ = form_structure; |
412 if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) | 402 if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) |
413 EXPECT_TRUE(controller()->AutocheckoutIsRunning()); | 403 EXPECT_TRUE(controller()->AutocheckoutIsRunning()); |
414 } | 404 } |
415 | 405 |
| 406 // Must be first member to ensure TestBrowserThreads outlive other objects. |
| 407 content::TestBrowserThreadBundle thread_bundle_; |
| 408 |
416 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
417 // http://crbug.com/227221 | 410 // http://crbug.com/227221 |
418 ui::ScopedOleInitializer ole_initializer_; | 411 ui::ScopedOleInitializer ole_initializer_; |
419 #endif | 412 #endif |
420 | 413 |
421 // A bunch of threads are necessary for classes like TestWebContents and | |
422 // URLRequestContextGetter not to fall over. | |
423 base::MessageLoopForUI loop_; | |
424 content::TestBrowserThread ui_thread_; | |
425 content::TestBrowserThread file_thread_; | |
426 content::TestBrowserThread file_blocking_thread_; | |
427 content::TestBrowserThread io_thread_; | |
428 TestingProfile profile_; | 414 TestingProfile profile_; |
429 | 415 |
430 // The controller owns itself. | 416 // The controller owns itself. |
431 base::WeakPtr<TestAutofillDialogController> controller_; | 417 base::WeakPtr<TestAutofillDialogController> controller_; |
432 | 418 |
433 scoped_ptr<content::WebContents> test_web_contents_; | 419 scoped_ptr<content::WebContents> test_web_contents_; |
434 | 420 |
435 // Must outlive the controller. | 421 // Must outlive the controller. |
436 AutofillMetrics metric_logger_; | 422 AutofillMetrics metric_logger_; |
437 | 423 |
438 // Returned when the dialog closes successfully. | 424 // Returned when the dialog closes successfully. |
439 const FormStructure* form_structure_; | 425 const FormStructure* form_structure_; |
440 | |
441 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | |
442 }; | 426 }; |
443 | 427 |
444 } // namespace | 428 } // namespace |
445 | 429 |
446 // This test makes sure nothing falls over when fields are being validity- | 430 // This test makes sure nothing falls over when fields are being validity- |
447 // checked. | 431 // checked. |
448 TEST_F(AutofillDialogControllerTest, ValidityCheck) { | 432 TEST_F(AutofillDialogControllerTest, ValidityCheck) { |
449 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 433 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
450 DialogSection section = static_cast<DialogSection>(i); | 434 DialogSection section = static_cast<DialogSection>(i); |
451 const DetailInputs& shipping_inputs = | 435 const DetailInputs& shipping_inputs = |
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 CreateFullWallet("choose_another_instrument_or_address")); | 1969 CreateFullWallet("choose_another_instrument_or_address")); |
1986 EXPECT_EQ(1U, NotificationsOfType( | 1970 EXPECT_EQ(1U, NotificationsOfType( |
1987 DialogNotification::REQUIRED_ACTION).size()); | 1971 DialogNotification::REQUIRED_ACTION).size()); |
1988 | 1972 |
1989 controller()->OnAccept(); | 1973 controller()->OnAccept(); |
1990 EXPECT_EQ(0U, NotificationsOfType( | 1974 EXPECT_EQ(0U, NotificationsOfType( |
1991 DialogNotification::REQUIRED_ACTION).size()); | 1975 DialogNotification::REQUIRED_ACTION).size()); |
1992 } | 1976 } |
1993 | 1977 |
1994 } // namespace autofill | 1978 } // namespace autofill |
OLD | NEW |