| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/tuple.h" | 5 #include "base/tuple.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "components/autofill/browser/autocheckout_manager.h" | 9 #include "components/autofill/browser/autocheckout_manager.h" |
| 10 #include "components/autofill/browser/autofill_common_test.h" | 10 #include "components/autofill/browser/autofill_common_test.h" |
| 11 #include "components/autofill/browser/autofill_manager.h" | 11 #include "components/autofill/browser/autofill_manager.h" |
| 12 #include "components/autofill/browser/autofill_metrics.h" | 12 #include "components/autofill/browser/autofill_metrics.h" |
| 13 #include "components/autofill/browser/form_structure.h" | 13 #include "components/autofill/browser/form_structure.h" |
| 14 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 14 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| 15 #include "components/autofill/common/autofill_messages.h" | 15 #include "components/autofill/common/autofill_messages.h" |
| 16 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/test/mock_render_process_host.h" | 18 #include "content/public/test/mock_render_process_host.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 20 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 21 #include "ipc/ipc_test_sink.h" | 21 #include "ipc/ipc_test_sink.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 | |
| 26 using content::BrowserThread; | 25 using content::BrowserThread; |
| 27 | 26 |
| 28 namespace autofill { | 27 namespace autofill { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 typedef Tuple2<std::vector<FormData>, WebElementDescriptor> AutofillParam; | 31 typedef Tuple2<std::vector<FormData>, WebElementDescriptor> AutofillParam; |
| 33 | 32 |
| 34 FormFieldData BuildFieldWithValue( | 33 FormFieldData BuildFieldWithValue( |
| 35 const std::string& autocomplete_attribute, | 34 const std::string& autocomplete_attribute, |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 325 } |
| 327 | 326 |
| 328 using AutocheckoutManager::in_autocheckout_flow; | 327 using AutocheckoutManager::in_autocheckout_flow; |
| 329 using AutocheckoutManager::autocheckout_offered; | 328 using AutocheckoutManager::autocheckout_offered; |
| 330 using AutocheckoutManager::MaybeShowAutocheckoutDialog; | 329 using AutocheckoutManager::MaybeShowAutocheckoutDialog; |
| 331 }; | 330 }; |
| 332 | 331 |
| 333 } // namespace | 332 } // namespace |
| 334 | 333 |
| 335 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { | 334 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { |
| 336 public: | 335 protected: |
| 337 AutocheckoutManagerTest() | 336 virtual void SetUp() OVERRIDE { |
| 338 : ChromeRenderViewHostTestHarness(), | 337 SetRealThreadMask(content::TestBrowserThreadBundle::REAL_IO_THREAD); |
| 339 ui_thread_(BrowserThread::UI, &message_loop_), | 338 ChromeRenderViewHostTestHarness::SetUp(); |
| 340 io_thread_(BrowserThread::IO) { | 339 profile()->CreateRequestContext(); |
| 340 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); |
| 341 autofill_manager_.reset(new TestAutofillManager( |
| 342 web_contents(), |
| 343 autofill_manager_delegate_.get())); |
| 344 autocheckout_manager_.reset( |
| 345 new TestAutocheckoutManager(autofill_manager_.get())); |
| 346 } |
| 347 |
| 348 virtual void TearDown() OVERRIDE { |
| 349 autocheckout_manager_.reset(); |
| 350 autofill_manager_delegate_.reset(); |
| 351 autofill_manager_.reset(); |
| 352 profile()->ResetRequestContext(); |
| 353 ChromeRenderViewHostTestHarness::TearDown(); |
| 341 } | 354 } |
| 342 | 355 |
| 343 std::vector<FormData> ReadFilledForms() { | 356 std::vector<FormData> ReadFilledForms() { |
| 344 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | 357 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; |
| 345 const IPC::Message* message = | 358 const IPC::Message* message = |
| 346 process()->sink().GetFirstMessageMatching(kMsgID); | 359 process()->sink().GetFirstMessageMatching(kMsgID); |
| 347 AutofillParam autofill_param; | 360 AutofillParam autofill_param; |
| 348 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); | 361 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); |
| 349 return autofill_param.a; | 362 return autofill_param.a; |
| 350 } | 363 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 406 |
| 394 void HideRequestAutocompleteDialog() { | 407 void HideRequestAutocompleteDialog() { |
| 395 EXPECT_TRUE( | 408 EXPECT_TRUE( |
| 396 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 409 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 397 autofill_manager_delegate_->HideRequestAutocompleteDialog(); | 410 autofill_manager_delegate_->HideRequestAutocompleteDialog(); |
| 398 EXPECT_FALSE( | 411 EXPECT_FALSE( |
| 399 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 412 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 400 } | 413 } |
| 401 | 414 |
| 402 protected: | 415 protected: |
| 403 content::TestBrowserThread ui_thread_; | |
| 404 content::TestBrowserThread io_thread_; | |
| 405 scoped_ptr<TestAutofillManager> autofill_manager_; | 416 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 406 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; | 417 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; |
| 407 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; | 418 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; |
| 408 | |
| 409 private: | |
| 410 virtual void SetUp() OVERRIDE { | |
| 411 ChromeRenderViewHostTestHarness::SetUp(); | |
| 412 io_thread_.StartIOThread(); | |
| 413 profile()->CreateRequestContext(); | |
| 414 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); | |
| 415 autofill_manager_.reset(new TestAutofillManager( | |
| 416 web_contents(), | |
| 417 autofill_manager_delegate_.get())); | |
| 418 autocheckout_manager_.reset( | |
| 419 new TestAutocheckoutManager(autofill_manager_.get())); | |
| 420 } | |
| 421 | |
| 422 virtual void TearDown() OVERRIDE { | |
| 423 autocheckout_manager_.reset(); | |
| 424 autofill_manager_delegate_.reset(); | |
| 425 autofill_manager_.reset(); | |
| 426 profile()->ResetRequestContext(); | |
| 427 ChromeRenderViewHostTestHarness::TearDown(); | |
| 428 io_thread_.Stop(); | |
| 429 } | |
| 430 | |
| 431 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); | |
| 432 }; | 419 }; |
| 433 | 420 |
| 434 TEST_F(AutocheckoutManagerTest, TestFillForms) { | 421 TEST_F(AutocheckoutManagerTest, TestFillForms) { |
| 435 OpenRequestAutocompleteDialog(); | 422 OpenRequestAutocompleteDialog(); |
| 436 | 423 |
| 437 // Test if autocheckout manager can fill the first page. | 424 // Test if autocheckout manager can fill the first page. |
| 438 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | 425 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); |
| 439 | 426 |
| 440 autocheckout_manager_->FillForms(); | 427 autocheckout_manager_->FillForms(); |
| 441 | 428 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); | 674 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); |
| 688 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, | 675 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, |
| 689 ssl_status, | 676 ssl_status, |
| 690 true); | 677 true); |
| 691 CheckFillFormsAndClickIpc(); | 678 CheckFillFormsAndClickIpc(); |
| 692 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | 679 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); |
| 693 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | 680 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 694 } | 681 } |
| 695 | 682 |
| 696 } // namespace autofill | 683 } // namespace autofill |
| OLD | NEW |