Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: components/autofill/browser/autocheckout_manager_unittest.cc

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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/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_driver.h"
14 #include "components/autofill/browser/test_autofill_manager_delegate.h" 15 #include "components/autofill/browser/test_autofill_manager_delegate.h"
15 #include "components/autofill/common/autofill_messages.h" 16 #include "components/autofill/common/autofill_messages.h"
16 #include "components/autofill/common/form_data.h" 17 #include "components/autofill/common/form_data.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"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 26 matching lines...) Expand all
351 352
352 } // namespace 353 } // namespace
353 354
354 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { 355 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness {
355 protected: 356 protected:
356 virtual void SetUp() OVERRIDE { 357 virtual void SetUp() OVERRIDE {
357 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); 358 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
358 ChromeRenderViewHostTestHarness::SetUp(); 359 ChromeRenderViewHostTestHarness::SetUp();
359 profile()->CreateRequestContext(); 360 profile()->CreateRequestContext();
360 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); 361 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate());
362 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
361 autofill_manager_.reset(new TestAutofillManager( 363 autofill_manager_.reset(new TestAutofillManager(
362 web_contents(), 364 autofill_driver_.get(),
363 autofill_manager_delegate_.get())); 365 autofill_manager_delegate_.get()));
364 autocheckout_manager_.reset( 366 autocheckout_manager_.reset(
365 new TestAutocheckoutManager(autofill_manager_.get())); 367 new TestAutocheckoutManager(autofill_manager_.get()));
366 } 368 }
367 369
368 virtual void TearDown() OVERRIDE { 370 virtual void TearDown() OVERRIDE {
369 autocheckout_manager_.reset(); 371 autocheckout_manager_.reset();
370 autofill_manager_delegate_.reset(); 372 autofill_manager_delegate_.reset();
371 autofill_manager_.reset(); 373 autofill_manager_.reset();
374 autofill_driver_.reset();
372 profile()->ResetRequestContext(); 375 profile()->ResetRequestContext();
373 ChromeRenderViewHostTestHarness::TearDown(); 376 ChromeRenderViewHostTestHarness::TearDown();
374 } 377 }
375 378
376 std::vector<FormData> ReadFilledForms() { 379 std::vector<FormData> ReadFilledForms() {
377 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; 380 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID;
378 const IPC::Message* message = 381 const IPC::Message* message =
379 process()->sink().GetFirstMessageMatching(kMsgID); 382 process()->sink().GetFirstMessageMatching(kMsgID);
380 AutofillParam autofill_param; 383 AutofillParam autofill_param;
381 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); 384 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 430
428 void HideRequestAutocompleteDialog() { 431 void HideRequestAutocompleteDialog() {
429 EXPECT_TRUE( 432 EXPECT_TRUE(
430 autofill_manager_delegate_->request_autocomplete_dialog_open()); 433 autofill_manager_delegate_->request_autocomplete_dialog_open());
431 autofill_manager_delegate_->HideRequestAutocompleteDialog(); 434 autofill_manager_delegate_->HideRequestAutocompleteDialog();
432 EXPECT_FALSE( 435 EXPECT_FALSE(
433 autofill_manager_delegate_->request_autocomplete_dialog_open()); 436 autofill_manager_delegate_->request_autocomplete_dialog_open());
434 } 437 }
435 438
436 protected: 439 protected:
440 scoped_ptr<TestAutofillDriver> autofill_driver_;
437 scoped_ptr<TestAutofillManager> autofill_manager_; 441 scoped_ptr<TestAutofillManager> autofill_manager_;
438 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; 442 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_;
439 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; 443 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_;
440 }; 444 };
441 445
442 TEST_F(AutocheckoutManagerTest, TestFillForms) { 446 TEST_F(AutocheckoutManagerTest, TestFillForms) {
443 OpenRequestAutocompleteDialog(); 447 OpenRequestAutocompleteDialog();
444 448
445 // Test if autocheckout manager can fill the first page. 449 // Test if autocheckout manager can fill the first page.
446 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); 450 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure());
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); 799 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1);
796 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url, 800 autocheckout_manager_->MaybeShowAutocheckoutDialog(frame_url,
797 ssl_status, 801 ssl_status,
798 true); 802 true);
799 CheckFillFormsAndClickIpc(); 803 CheckFillFormsAndClickIpc();
800 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); 804 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow());
801 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); 805 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open());
802 } 806 }
803 807
804 } // namespace autofill 808 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698