OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "base/tuple.h" | 6 #include "base/tuple.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/autofill_common_test.h" | 9 #include "components/autofill/browser/autofill_common_test.h" |
10 #include "components/autofill/browser/autofill_manager.h" | 10 #include "components/autofill/browser/autofill_manager.h" |
11 #include "components/autofill/browser/autofill_metrics.h" | 11 #include "components/autofill/browser/autofill_metrics.h" |
12 #include "components/autofill/browser/form_structure.h" | 12 #include "components/autofill/browser/form_structure.h" |
| 13 #include "components/autofill/browser/test_autofill_driver.h" |
13 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 14 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
14 #include "components/autofill/common/autofill_messages.h" | 15 #include "components/autofill/common/autofill_messages.h" |
15 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
16 #include "components/autofill/content/browser/autocheckout_manager.h" | 17 #include "components/autofill/content/browser/autocheckout_manager.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
20 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
21 #include "ipc/ipc_test_sink.h" | 22 #include "ipc/ipc_test_sink.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 303 } |
303 | 304 |
304 private: | 305 private: |
305 bool request_autocomplete_dialog_open_; | 306 bool request_autocomplete_dialog_open_; |
306 bool autocheckout_bubble_shown_; | 307 bool autocheckout_bubble_shown_; |
307 scoped_ptr<FormStructure> user_supplied_data_; | 308 scoped_ptr<FormStructure> user_supplied_data_; |
308 }; | 309 }; |
309 | 310 |
310 class TestAutofillManager : public AutofillManager { | 311 class TestAutofillManager : public AutofillManager { |
311 public: | 312 public: |
312 explicit TestAutofillManager(content::WebContents* contents, | 313 explicit TestAutofillManager(AutofillDriver* driver, |
313 AutofillManagerDelegate* delegate) | 314 AutofillManagerDelegate* delegate) |
314 : AutofillManager(contents, delegate, NULL) { | 315 : AutofillManager(driver, delegate, NULL) { |
315 } | 316 } |
316 virtual ~TestAutofillManager() {} | 317 virtual ~TestAutofillManager() {} |
317 | 318 |
318 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { | 319 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { |
319 form_structures()->clear(); | 320 form_structures()->clear(); |
320 form_structures()->push_back(form_structure.release()); | 321 form_structures()->push_back(form_structure.release()); |
321 } | 322 } |
322 }; | 323 }; |
323 | 324 |
324 class MockAutofillMetrics : public AutofillMetrics { | 325 class MockAutofillMetrics : public AutofillMetrics { |
(...skipping 27 matching lines...) Expand all Loading... |
352 | 353 |
353 } // namespace | 354 } // namespace |
354 | 355 |
355 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { | 356 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { |
356 protected: | 357 protected: |
357 virtual void SetUp() OVERRIDE { | 358 virtual void SetUp() OVERRIDE { |
358 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); | 359 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); |
359 ChromeRenderViewHostTestHarness::SetUp(); | 360 ChromeRenderViewHostTestHarness::SetUp(); |
360 profile()->CreateRequestContext(); | 361 profile()->CreateRequestContext(); |
361 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); | 362 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); |
| 363 autofill_driver_.reset(new TestAutofillDriver(web_contents())); |
362 autofill_manager_.reset(new TestAutofillManager( | 364 autofill_manager_.reset(new TestAutofillManager( |
363 web_contents(), | 365 autofill_driver_.get(), |
364 autofill_manager_delegate_.get())); | 366 autofill_manager_delegate_.get())); |
365 autocheckout_manager_.reset( | 367 autocheckout_manager_.reset( |
366 new TestAutocheckoutManager(autofill_manager_.get())); | 368 new TestAutocheckoutManager(autofill_manager_.get())); |
367 } | 369 } |
368 | 370 |
369 virtual void TearDown() OVERRIDE { | 371 virtual void TearDown() OVERRIDE { |
370 autocheckout_manager_.reset(); | 372 autocheckout_manager_.reset(); |
371 autofill_manager_delegate_.reset(); | 373 autofill_manager_delegate_.reset(); |
372 autofill_manager_.reset(); | 374 autofill_manager_.reset(); |
| 375 autofill_driver_.reset(); |
373 profile()->ResetRequestContext(); | 376 profile()->ResetRequestContext(); |
374 ChromeRenderViewHostTestHarness::TearDown(); | 377 ChromeRenderViewHostTestHarness::TearDown(); |
375 } | 378 } |
376 | 379 |
377 std::vector<FormData> ReadFilledForms() { | 380 std::vector<FormData> ReadFilledForms() { |
378 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | 381 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; |
379 const IPC::Message* message = | 382 const IPC::Message* message = |
380 process()->sink().GetFirstMessageMatching(kMsgID); | 383 process()->sink().GetFirstMessageMatching(kMsgID); |
381 AutofillParam autofill_param; | 384 AutofillParam autofill_param; |
382 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); | 385 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 431 |
429 void HideRequestAutocompleteDialog() { | 432 void HideRequestAutocompleteDialog() { |
430 EXPECT_TRUE( | 433 EXPECT_TRUE( |
431 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 434 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
432 autofill_manager_delegate_->HideRequestAutocompleteDialog(); | 435 autofill_manager_delegate_->HideRequestAutocompleteDialog(); |
433 EXPECT_FALSE( | 436 EXPECT_FALSE( |
434 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 437 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
435 } | 438 } |
436 | 439 |
437 protected: | 440 protected: |
| 441 scoped_ptr<TestAutofillDriver> autofill_driver_; |
438 scoped_ptr<TestAutofillManager> autofill_manager_; | 442 scoped_ptr<TestAutofillManager> autofill_manager_; |
439 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; | 443 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; |
440 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; | 444 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; |
441 }; | 445 }; |
442 | 446 |
443 TEST_F(AutocheckoutManagerTest, TestFillForms) { | 447 TEST_F(AutocheckoutManagerTest, TestFillForms) { |
444 OpenRequestAutocompleteDialog(); | 448 OpenRequestAutocompleteDialog(); |
445 | 449 |
446 // Test if autocheckout manager can fill the first page. | 450 // Test if autocheckout manager can fill the first page. |
447 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | 451 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); | 823 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); |
820 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, | 824 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, |
821 ssl_status, | 825 ssl_status, |
822 true); | 826 true); |
823 CheckFillFormsAndClickIpc(); | 827 CheckFillFormsAndClickIpc(); |
824 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | 828 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); |
825 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | 829 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); |
826 } | 830 } |
827 | 831 |
828 } // namespace autofill | 832 } // namespace autofill |
OLD | NEW |