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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 326 } |
328 | 327 |
329 using AutocheckoutManager::in_autocheckout_flow; | 328 using AutocheckoutManager::in_autocheckout_flow; |
330 using AutocheckoutManager::autocheckout_offered; | 329 using AutocheckoutManager::autocheckout_offered; |
331 using AutocheckoutManager::MaybeShowAutocheckoutDialog; | 330 using AutocheckoutManager::MaybeShowAutocheckoutDialog; |
332 }; | 331 }; |
333 | 332 |
334 } // namespace | 333 } // namespace |
335 | 334 |
336 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { | 335 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { |
337 public: | 336 protected: |
338 AutocheckoutManagerTest() | 337 virtual void SetUp() OVERRIDE { |
339 : ChromeRenderViewHostTestHarness(), | 338 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); |
340 ui_thread_(BrowserThread::UI, &message_loop_), | 339 ChromeRenderViewHostTestHarness::SetUp(); |
341 io_thread_(BrowserThread::IO) { | 340 profile()->CreateRequestContext(); |
| 341 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); |
| 342 autofill_manager_.reset(new TestAutofillManager( |
| 343 web_contents(), |
| 344 autofill_manager_delegate_.get())); |
| 345 autocheckout_manager_.reset( |
| 346 new TestAutocheckoutManager(autofill_manager_.get())); |
| 347 } |
| 348 |
| 349 virtual void TearDown() OVERRIDE { |
| 350 autocheckout_manager_.reset(); |
| 351 autofill_manager_delegate_.reset(); |
| 352 autofill_manager_.reset(); |
| 353 profile()->ResetRequestContext(); |
| 354 ChromeRenderViewHostTestHarness::TearDown(); |
342 } | 355 } |
343 | 356 |
344 std::vector<FormData> ReadFilledForms() { | 357 std::vector<FormData> ReadFilledForms() { |
345 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | 358 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; |
346 const IPC::Message* message = | 359 const IPC::Message* message = |
347 process()->sink().GetFirstMessageMatching(kMsgID); | 360 process()->sink().GetFirstMessageMatching(kMsgID); |
348 AutofillParam autofill_param; | 361 AutofillParam autofill_param; |
349 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); | 362 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); |
350 return autofill_param.a; | 363 return autofill_param.a; |
351 } | 364 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 407 |
395 void HideRequestAutocompleteDialog() { | 408 void HideRequestAutocompleteDialog() { |
396 EXPECT_TRUE( | 409 EXPECT_TRUE( |
397 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 410 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
398 autofill_manager_delegate_->HideRequestAutocompleteDialog(); | 411 autofill_manager_delegate_->HideRequestAutocompleteDialog(); |
399 EXPECT_FALSE( | 412 EXPECT_FALSE( |
400 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 413 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
401 } | 414 } |
402 | 415 |
403 protected: | 416 protected: |
404 content::TestBrowserThread ui_thread_; | |
405 content::TestBrowserThread io_thread_; | |
406 scoped_ptr<TestAutofillManager> autofill_manager_; | 417 scoped_ptr<TestAutofillManager> autofill_manager_; |
407 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; | 418 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; |
408 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; | 419 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; |
409 | |
410 private: | |
411 virtual void SetUp() OVERRIDE { | |
412 ChromeRenderViewHostTestHarness::SetUp(); | |
413 io_thread_.StartIOThread(); | |
414 profile()->CreateRequestContext(); | |
415 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); | |
416 autofill_manager_.reset(new TestAutofillManager( | |
417 web_contents(), | |
418 autofill_manager_delegate_.get())); | |
419 autocheckout_manager_.reset( | |
420 new TestAutocheckoutManager(autofill_manager_.get())); | |
421 } | |
422 | |
423 virtual void TearDown() OVERRIDE { | |
424 autocheckout_manager_.reset(); | |
425 autofill_manager_delegate_.reset(); | |
426 autofill_manager_.reset(); | |
427 profile()->ResetRequestContext(); | |
428 ChromeRenderViewHostTestHarness::TearDown(); | |
429 io_thread_.Stop(); | |
430 } | |
431 | |
432 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); | |
433 }; | 420 }; |
434 | 421 |
435 TEST_F(AutocheckoutManagerTest, TestFillForms) { | 422 TEST_F(AutocheckoutManagerTest, TestFillForms) { |
436 OpenRequestAutocompleteDialog(); | 423 OpenRequestAutocompleteDialog(); |
437 | 424 |
438 // Test if autocheckout manager can fill the first page. | 425 // Test if autocheckout manager can fill the first page. |
439 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | 426 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); |
440 | 427 |
441 autocheckout_manager_->FillForms(); | 428 autocheckout_manager_->FillForms(); |
442 | 429 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); | 682 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); |
696 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, | 683 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, |
697 ssl_status, | 684 ssl_status, |
698 true); | 685 true); |
699 CheckFillFormsAndClickIpc(); | 686 CheckFillFormsAndClickIpc(); |
700 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | 687 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); |
701 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | 688 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); |
702 } | 689 } |
703 | 690 |
704 } // namespace autofill | 691 } // namespace autofill |
OLD | NEW |