| 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 "components/autofill/browser/autocheckout_manager.h" | 9 #include "components/autofill/browser/autocheckout_manager.h" |
| 9 #include "components/autofill/browser/autofill_common_test.h" | 10 #include "components/autofill/browser/autofill_common_test.h" |
| 10 #include "components/autofill/browser/autofill_manager.h" | 11 #include "components/autofill/browser/autofill_manager.h" |
| 11 #include "components/autofill/browser/form_structure.h" | 12 #include "components/autofill/browser/form_structure.h" |
| 12 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 13 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| 13 #include "components/autofill/common/autofill_messages.h" | 14 #include "components/autofill/common/autofill_messages.h" |
| 14 #include "components/autofill/common/form_data.h" | 15 #include "components/autofill/common/form_data.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/test/mock_render_process_host.h" | 17 #include "content/public/test/mock_render_process_host.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 callback.Run(true); | 231 callback.Run(true); |
| 231 } | 232 } |
| 232 | 233 |
| 233 virtual void HideAutocheckoutBubble() OVERRIDE {} | 234 virtual void HideAutocheckoutBubble() OVERRIDE {} |
| 234 | 235 |
| 235 virtual void ShowRequestAutocompleteDialog( | 236 virtual void ShowRequestAutocompleteDialog( |
| 236 const FormData& form, | 237 const FormData& form, |
| 237 const GURL& source_url, | 238 const GURL& source_url, |
| 238 const AutofillMetrics& metric_logger, | 239 const AutofillMetrics& metric_logger, |
| 239 DialogType dialog_type, | 240 DialogType dialog_type, |
| 240 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { | 241 const base::Callback<void(const FormStructure*, |
| 242 const std::string&)>& callback) OVERRIDE { |
| 241 request_autocomplete_dialog_open_ = true; | 243 request_autocomplete_dialog_open_ = true; |
| 242 callback.Run(user_supplied_data_.get()); | 244 callback.Run(user_supplied_data_.get(), "google_transaction_id"); |
| 243 } | 245 } |
| 244 | 246 |
| 245 MOCK_METHOD1(UpdateProgressBar, void(double value)); | 247 MOCK_METHOD1(UpdateProgressBar, void(double value)); |
| 246 | 248 |
| 247 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { | 249 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { |
| 248 user_supplied_data_.reset(user_supplied_data.release()); | 250 user_supplied_data_.reset(user_supplied_data.release()); |
| 249 } | 251 } |
| 250 | 252 |
| 251 bool autocheckout_bubble_shown() const { | 253 bool autocheckout_bubble_shown() const { |
| 252 return autocheckout_bubble_shown_; | 254 return autocheckout_bubble_shown_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 using AutocheckoutManager::autocheckout_offered; | 292 using AutocheckoutManager::autocheckout_offered; |
| 291 using AutocheckoutManager::MaybeShowAutocheckoutDialog; | 293 using AutocheckoutManager::MaybeShowAutocheckoutDialog; |
| 292 }; | 294 }; |
| 293 | 295 |
| 294 } // namespace | 296 } // namespace |
| 295 | 297 |
| 296 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { | 298 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { |
| 297 public: | 299 public: |
| 298 AutocheckoutManagerTest() | 300 AutocheckoutManagerTest() |
| 299 : ChromeRenderViewHostTestHarness(), | 301 : ChromeRenderViewHostTestHarness(), |
| 300 ui_thread_(BrowserThread::UI, &message_loop_) { | 302 ui_thread_(BrowserThread::UI, &message_loop_), |
| 303 io_thread_(BrowserThread::IO) { |
| 301 } | 304 } |
| 302 | 305 |
| 303 std::vector<FormData> ReadFilledForms() { | 306 std::vector<FormData> ReadFilledForms() { |
| 304 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | 307 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; |
| 305 const IPC::Message* message = | 308 const IPC::Message* message = |
| 306 process()->sink().GetFirstMessageMatching(kMsgID); | 309 process()->sink().GetFirstMessageMatching(kMsgID); |
| 307 AutofillParam autofill_param; | 310 AutofillParam autofill_param; |
| 308 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); | 311 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); |
| 309 return autofill_param.a; | 312 return autofill_param.a; |
| 310 } | 313 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 void HideRequestAutocompleteDialog() { | 351 void HideRequestAutocompleteDialog() { |
| 349 EXPECT_TRUE( | 352 EXPECT_TRUE( |
| 350 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 353 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 351 autofill_manager_delegate_->HideRequestAutocompleteDialog(); | 354 autofill_manager_delegate_->HideRequestAutocompleteDialog(); |
| 352 EXPECT_FALSE( | 355 EXPECT_FALSE( |
| 353 autofill_manager_delegate_->request_autocomplete_dialog_open()); | 356 autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 354 } | 357 } |
| 355 | 358 |
| 356 protected: | 359 protected: |
| 357 content::TestBrowserThread ui_thread_; | 360 content::TestBrowserThread ui_thread_; |
| 361 content::TestBrowserThread io_thread_; |
| 358 scoped_ptr<TestAutofillManager> autofill_manager_; | 362 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 359 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; | 363 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; |
| 360 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; | 364 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; |
| 361 | 365 |
| 362 private: | 366 private: |
| 363 virtual void SetUp() OVERRIDE { | 367 virtual void SetUp() OVERRIDE { |
| 364 ChromeRenderViewHostTestHarness::SetUp(); | 368 ChromeRenderViewHostTestHarness::SetUp(); |
| 369 io_thread_.StartIOThread(); |
| 370 profile()->CreateRequestContext(); |
| 365 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); | 371 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); |
| 366 autofill_manager_.reset(new TestAutofillManager( | 372 autofill_manager_.reset(new TestAutofillManager( |
| 367 web_contents(), | 373 web_contents(), |
| 368 autofill_manager_delegate_.get())); | 374 autofill_manager_delegate_.get())); |
| 369 autocheckout_manager_.reset( | 375 autocheckout_manager_.reset( |
| 370 new TestAutocheckoutManager(autofill_manager_.get())); | 376 new TestAutocheckoutManager(autofill_manager_.get())); |
| 371 } | 377 } |
| 372 | 378 |
| 373 virtual void TearDown() OVERRIDE { | 379 virtual void TearDown() OVERRIDE { |
| 374 autocheckout_manager_.reset(); | 380 autocheckout_manager_.reset(); |
| 375 autofill_manager_delegate_.reset(); | 381 autofill_manager_delegate_.reset(); |
| 376 autofill_manager_.reset(); | 382 autofill_manager_.reset(); |
| 383 profile()->ResetRequestContext(); |
| 377 ChromeRenderViewHostTestHarness::TearDown(); | 384 ChromeRenderViewHostTestHarness::TearDown(); |
| 385 io_thread_.Stop(); |
| 378 } | 386 } |
| 379 | 387 |
| 380 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); | 388 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); |
| 381 }; | 389 }; |
| 382 | 390 |
| 383 TEST_F(AutocheckoutManagerTest, TestFillForms) { | 391 TEST_F(AutocheckoutManagerTest, TestFillForms) { |
| 384 OpenRequestAutocompleteDialog(); | 392 OpenRequestAutocompleteDialog(); |
| 385 | 393 |
| 386 // Test if autocheckout manager can fill the first page. | 394 // Test if autocheckout manager can fill the first page. |
| 387 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | 395 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 UpdateProgressBar(testing::DoubleEq(1))).Times(1); | 559 UpdateProgressBar(testing::DoubleEq(1))).Times(1); |
| 552 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, | 560 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, |
| 553 ssl_status, | 561 ssl_status, |
| 554 true); | 562 true); |
| 555 CheckFillFormsAndClickIpc(); | 563 CheckFillFormsAndClickIpc(); |
| 556 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | 564 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); |
| 557 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | 565 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); |
| 558 } | 566 } |
| 559 | 567 |
| 560 } // namespace autofill | 568 } // namespace autofill |
| OLD | NEW |