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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 79103002: Abstracted AcceptPasswordAutofillSuggestion IPC out of core Autofill code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
(...skipping 17 matching lines...) Expand all
28 using ::testing::AtLeast; 28 using ::testing::AtLeast;
29 using ::testing::NiceMock; 29 using ::testing::NiceMock;
30 using base::WeakPtr; 30 using base::WeakPtr;
31 using blink::WebAutofillClient; 31 using blink::WebAutofillClient;
32 32
33 namespace autofill { 33 namespace autofill {
34 namespace { 34 namespace {
35 35
36 class MockAutofillExternalDelegate : public AutofillExternalDelegate { 36 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
37 public: 37 public:
38 MockAutofillExternalDelegate(content::WebContents* web_contents, 38 MockAutofillExternalDelegate(AutofillManager* autofill_manager,
39 AutofillManager* autofill_manager,
40 AutofillDriver* autofill_driver) 39 AutofillDriver* autofill_driver)
41 : AutofillExternalDelegate(web_contents, autofill_manager, 40 : AutofillExternalDelegate(autofill_manager,
42 autofill_driver) {} 41 autofill_driver) {}
Ilya Sherman 2013/11/22 00:26:29 nit: Looks like this can fit on the previous line.
jif-google 2013/11/22 12:21:44 Done.
43 virtual ~MockAutofillExternalDelegate() {} 42 virtual ~MockAutofillExternalDelegate() {}
44 43
45 virtual void DidSelectSuggestion(int identifier) OVERRIDE {} 44 virtual void DidSelectSuggestion(int identifier) OVERRIDE {}
46 virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE 45 virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE
47 {} 46 {}
48 virtual void ClearPreviewedForm() OVERRIDE {} 47 virtual void ClearPreviewedForm() OVERRIDE {}
49 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() { 48 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() {
50 return AutofillExternalDelegate::GetWeakPtr(); 49 return AutofillExternalDelegate::GetWeakPtr();
51 } 50 }
52 }; 51 };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 133
135 AutofillDriverImpl::CreateForWebContentsAndDelegate( 134 AutofillDriverImpl::CreateForWebContentsAndDelegate(
136 web_contents(), 135 web_contents(),
137 manager_delegate_.get(), 136 manager_delegate_.get(),
138 "en-US", 137 "en-US",
139 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); 138 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
140 AutofillDriverImpl* driver = 139 AutofillDriverImpl* driver =
141 AutofillDriverImpl::FromWebContents(web_contents()); 140 AutofillDriverImpl::FromWebContents(web_contents());
142 external_delegate_.reset( 141 external_delegate_.reset(
143 new NiceMock<MockAutofillExternalDelegate>( 142 new NiceMock<MockAutofillExternalDelegate>(
144 web_contents(),
145 driver->autofill_manager(), 143 driver->autofill_manager(),
146 driver)); 144 driver));
147 145
148 autofill_popup_controller_ = 146 autofill_popup_controller_ =
149 new testing::NiceMock<TestAutofillPopupController>( 147 new testing::NiceMock<TestAutofillPopupController>(
150 external_delegate_->GetWeakPtr(),gfx::Rect()); 148 external_delegate_->GetWeakPtr(),gfx::Rect());
151 } 149 }
152 150
153 virtual void TearDown() OVERRIDE { 151 virtual void TearDown() OVERRIDE {
154 // This will make sure the controller and the view (if any) are both 152 // This will make sure the controller and the view (if any) are both
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // Clear datalist values and check that the popup becomes hidden. 422 // Clear datalist values and check that the popup becomes hidden.
425 EXPECT_CALL(*autofill_popup_controller_, Hide()); 423 EXPECT_CALL(*autofill_popup_controller_, Hide());
426 data_list_values.clear(); 424 data_list_values.clear();
427 autofill_popup_controller_->UpdateDataListValues(data_list_values, 425 autofill_popup_controller_->UpdateDataListValues(data_list_values,
428 data_list_values); 426 data_list_values);
429 } 427 }
430 428
431 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { 429 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
432 AutofillDriverImpl* driver = 430 AutofillDriverImpl* driver =
433 AutofillDriverImpl::FromWebContents(web_contents()); 431 AutofillDriverImpl::FromWebContents(web_contents());
434 MockAutofillExternalDelegate delegate( 432 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver);
435 web_contents(), driver->autofill_manager(), driver);
436 433
437 WeakPtr<AutofillPopupControllerImpl> controller = 434 WeakPtr<AutofillPopupControllerImpl> controller =
438 AutofillPopupControllerImpl::GetOrCreate( 435 AutofillPopupControllerImpl::GetOrCreate(
439 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), 436 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(),
440 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); 437 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION);
441 EXPECT_TRUE(controller.get()); 438 EXPECT_TRUE(controller.get());
442 439
443 controller->Hide(); 440 controller->Hide();
444 441
445 controller = AutofillPopupControllerImpl::GetOrCreate( 442 controller = AutofillPopupControllerImpl::GetOrCreate(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 element_bounds.push_back( 584 element_bounds.push_back(
588 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); 585 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0));
589 expected_popup_bounds.push_back( 586 expected_popup_bounds.push_back(
590 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, 587 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2,
591 desired_width, desired_height)); 588 desired_width, desired_height));
592 589
593 for (size_t i = 0; i < element_bounds.size(); ++i) { 590 for (size_t i = 0; i < element_bounds.size(); ++i) {
594 AutofillDriverImpl* driver = 591 AutofillDriverImpl* driver =
595 AutofillDriverImpl::FromWebContents(web_contents()); 592 AutofillDriverImpl::FromWebContents(web_contents());
596 NiceMock<MockAutofillExternalDelegate> external_delegate( 593 NiceMock<MockAutofillExternalDelegate> external_delegate(
597 web_contents(), driver->autofill_manager(), driver); 594 driver->autofill_manager(), driver);
598 TestAutofillPopupController* autofill_popup_controller = 595 TestAutofillPopupController* autofill_popup_controller =
599 new TestAutofillPopupController(external_delegate.GetWeakPtr(), 596 new TestAutofillPopupController(external_delegate.GetWeakPtr(),
600 element_bounds[i]); 597 element_bounds[i]);
601 598
602 autofill_popup_controller->set_display(display); 599 autofill_popup_controller->set_display(display);
603 autofill_popup_controller->Show(names, names, names, autofill_ids); 600 autofill_popup_controller->Show(names, names, names, autofill_ids);
604 601
605 EXPECT_EQ(expected_popup_bounds[i].ToString(), 602 EXPECT_EQ(expected_popup_bounds[i].ToString(),
606 autofill_popup_controller->popup_bounds().ToString()) << 603 autofill_popup_controller->popup_bounds().ToString()) <<
607 "Popup bounds failed to match for test " << i; 604 "Popup bounds failed to match for test " << i;
608 605
609 // Hide the controller to delete it. 606 // Hide the controller to delete it.
610 autofill_popup_controller->DoHide(); 607 autofill_popup_controller->DoHide();
611 } 608 }
612 } 609 }
613 610
614 } // namespace autofill 611 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698