| OLD | NEW |
| 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 Loading... |
| 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, autofill_driver) {} |
| 42 autofill_driver) {} | |
| 43 virtual ~MockAutofillExternalDelegate() {} | 41 virtual ~MockAutofillExternalDelegate() {} |
| 44 | 42 |
| 45 virtual void DidSelectSuggestion(int identifier) OVERRIDE {} | 43 virtual void DidSelectSuggestion(int identifier) OVERRIDE {} |
| 46 virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE | 44 virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE |
| 47 {} | 45 {} |
| 48 virtual void ClearPreviewedForm() OVERRIDE {} | 46 virtual void ClearPreviewedForm() OVERRIDE {} |
| 49 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() { | 47 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() { |
| 50 return AutofillExternalDelegate::GetWeakPtr(); | 48 return AutofillExternalDelegate::GetWeakPtr(); |
| 51 } | 49 } |
| 52 }; | 50 }; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 132 |
| 135 AutofillDriverImpl::CreateForWebContentsAndDelegate( | 133 AutofillDriverImpl::CreateForWebContentsAndDelegate( |
| 136 web_contents(), | 134 web_contents(), |
| 137 manager_delegate_.get(), | 135 manager_delegate_.get(), |
| 138 "en-US", | 136 "en-US", |
| 139 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); | 137 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); |
| 140 AutofillDriverImpl* driver = | 138 AutofillDriverImpl* driver = |
| 141 AutofillDriverImpl::FromWebContents(web_contents()); | 139 AutofillDriverImpl::FromWebContents(web_contents()); |
| 142 external_delegate_.reset( | 140 external_delegate_.reset( |
| 143 new NiceMock<MockAutofillExternalDelegate>( | 141 new NiceMock<MockAutofillExternalDelegate>( |
| 144 web_contents(), | |
| 145 driver->autofill_manager(), | 142 driver->autofill_manager(), |
| 146 driver)); | 143 driver)); |
| 147 | 144 |
| 148 autofill_popup_controller_ = | 145 autofill_popup_controller_ = |
| 149 new testing::NiceMock<TestAutofillPopupController>( | 146 new testing::NiceMock<TestAutofillPopupController>( |
| 150 external_delegate_->GetWeakPtr(),gfx::Rect()); | 147 external_delegate_->GetWeakPtr(),gfx::Rect()); |
| 151 } | 148 } |
| 152 | 149 |
| 153 virtual void TearDown() OVERRIDE { | 150 virtual void TearDown() OVERRIDE { |
| 154 // This will make sure the controller and the view (if any) are both | 151 // 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 Loading... |
| 424 // Clear datalist values and check that the popup becomes hidden. | 421 // Clear datalist values and check that the popup becomes hidden. |
| 425 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 422 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 426 data_list_values.clear(); | 423 data_list_values.clear(); |
| 427 autofill_popup_controller_->UpdateDataListValues(data_list_values, | 424 autofill_popup_controller_->UpdateDataListValues(data_list_values, |
| 428 data_list_values); | 425 data_list_values); |
| 429 } | 426 } |
| 430 | 427 |
| 431 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 428 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
| 432 AutofillDriverImpl* driver = | 429 AutofillDriverImpl* driver = |
| 433 AutofillDriverImpl::FromWebContents(web_contents()); | 430 AutofillDriverImpl::FromWebContents(web_contents()); |
| 434 MockAutofillExternalDelegate delegate( | 431 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver); |
| 435 web_contents(), driver->autofill_manager(), driver); | |
| 436 | 432 |
| 437 WeakPtr<AutofillPopupControllerImpl> controller = | 433 WeakPtr<AutofillPopupControllerImpl> controller = |
| 438 AutofillPopupControllerImpl::GetOrCreate( | 434 AutofillPopupControllerImpl::GetOrCreate( |
| 439 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), | 435 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), |
| 440 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); | 436 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); |
| 441 EXPECT_TRUE(controller.get()); | 437 EXPECT_TRUE(controller.get()); |
| 442 | 438 |
| 443 controller->Hide(); | 439 controller->Hide(); |
| 444 | 440 |
| 445 controller = AutofillPopupControllerImpl::GetOrCreate( | 441 controller = AutofillPopupControllerImpl::GetOrCreate( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 element_bounds.push_back( | 583 element_bounds.push_back( |
| 588 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); | 584 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); |
| 589 expected_popup_bounds.push_back( | 585 expected_popup_bounds.push_back( |
| 590 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, | 586 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, |
| 591 desired_width, desired_height)); | 587 desired_width, desired_height)); |
| 592 | 588 |
| 593 for (size_t i = 0; i < element_bounds.size(); ++i) { | 589 for (size_t i = 0; i < element_bounds.size(); ++i) { |
| 594 AutofillDriverImpl* driver = | 590 AutofillDriverImpl* driver = |
| 595 AutofillDriverImpl::FromWebContents(web_contents()); | 591 AutofillDriverImpl::FromWebContents(web_contents()); |
| 596 NiceMock<MockAutofillExternalDelegate> external_delegate( | 592 NiceMock<MockAutofillExternalDelegate> external_delegate( |
| 597 web_contents(), driver->autofill_manager(), driver); | 593 driver->autofill_manager(), driver); |
| 598 TestAutofillPopupController* autofill_popup_controller = | 594 TestAutofillPopupController* autofill_popup_controller = |
| 599 new TestAutofillPopupController(external_delegate.GetWeakPtr(), | 595 new TestAutofillPopupController(external_delegate.GetWeakPtr(), |
| 600 element_bounds[i]); | 596 element_bounds[i]); |
| 601 | 597 |
| 602 autofill_popup_controller->set_display(display); | 598 autofill_popup_controller->set_display(display); |
| 603 autofill_popup_controller->Show(names, names, names, autofill_ids); | 599 autofill_popup_controller->Show(names, names, names, autofill_ids); |
| 604 | 600 |
| 605 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 601 EXPECT_EQ(expected_popup_bounds[i].ToString(), |
| 606 autofill_popup_controller->popup_bounds().ToString()) << | 602 autofill_popup_controller->popup_bounds().ToString()) << |
| 607 "Popup bounds failed to match for test " << i; | 603 "Popup bounds failed to match for test " << i; |
| 608 | 604 |
| 609 // Hide the controller to delete it. | 605 // Hide the controller to delete it. |
| 610 autofill_popup_controller->DoHide(); | 606 autofill_popup_controller->DoHide(); |
| 611 } | 607 } |
| 612 } | 608 } |
| 613 | 609 |
| 614 } // namespace autofill | 610 } // namespace autofill |
| OLD | NEW |