| 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/testing_pref_service.h" | 7 #include "base/prefs/testing_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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 void set_display(const gfx::Display display) { | 75 void set_display(const gfx::Display display) { |
| 76 display_ = display; | 76 display_ = display; |
| 77 } | 77 } |
| 78 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const | 78 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const |
| 79 OVERRIDE { | 79 OVERRIDE { |
| 80 return display_; | 80 return display_; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Making protected functions public for testing | 83 // Making protected functions public for testing |
| 84 void SetPopupBounds(const gfx::Rect& bounds) { | 84 void SetPopupBounds(const gfx::RectF& bounds) { |
| 85 AutofillPopupControllerImpl::SetPopupBounds(bounds); | 85 AutofillPopupControllerImpl::SetPopupBounds(bounds); |
| 86 } | 86 } |
| 87 const std::vector<string16>& names() const { | 87 const std::vector<string16>& names() const { |
| 88 return AutofillPopupControllerImpl::names(); | 88 return AutofillPopupControllerImpl::names(); |
| 89 } | 89 } |
| 90 const std::vector<string16>& subtexts() const { | 90 const std::vector<string16>& subtexts() const { |
| 91 return AutofillPopupControllerImpl::subtexts(); | 91 return AutofillPopupControllerImpl::subtexts(); |
| 92 } | 92 } |
| 93 const std::vector<int>& identifiers() const { | 93 const std::vector<int>& identifiers() const { |
| 94 return AutofillPopupControllerImpl::identifiers(); | 94 return AutofillPopupControllerImpl::identifiers(); |
| 95 } | 95 } |
| 96 int selected_line() const { | 96 int selected_line() const { |
| 97 return AutofillPopupControllerImpl::selected_line(); | 97 return AutofillPopupControllerImpl::selected_line(); |
| 98 } | 98 } |
| 99 void SetSelectedLine(size_t selected_line) { | 99 void SetSelectedLine(size_t selected_line) { |
| 100 AutofillPopupControllerImpl::SetSelectedLine(selected_line); | 100 AutofillPopupControllerImpl::SetSelectedLine(selected_line); |
| 101 } | 101 } |
| 102 void SelectNextLine() { | 102 void SelectNextLine() { |
| 103 AutofillPopupControllerImpl::SelectNextLine(); | 103 AutofillPopupControllerImpl::SelectNextLine(); |
| 104 } | 104 } |
| 105 void SelectPreviousLine() { | 105 void SelectPreviousLine() { |
| 106 AutofillPopupControllerImpl::SelectPreviousLine(); | 106 AutofillPopupControllerImpl::SelectPreviousLine(); |
| 107 } | 107 } |
| 108 bool RemoveSelectedLine() { | 108 bool RemoveSelectedLine() { |
| 109 return AutofillPopupControllerImpl::RemoveSelectedLine(); | 109 return AutofillPopupControllerImpl::RemoveSelectedLine(); |
| 110 } | 110 } |
| 111 void DoHide() { | 111 void DoHide() { |
| 112 AutofillPopupControllerImpl::Hide(); | 112 AutofillPopupControllerImpl::Hide(); |
| 113 } | 113 } |
| 114 const gfx::Rect& popup_bounds() const { | 114 const gfx::RectF& popup_bounds() const { |
| 115 return AutofillPopupControllerImpl::popup_bounds(); | 115 return AutofillPopupControllerImpl::popup_bounds(); |
| 116 } | 116 } |
| 117 const gfx::RectF& element_bounds() const { | 117 const gfx::RectF& element_bounds() const { |
| 118 return AutofillPopupControllerImpl::element_bounds(); | 118 return AutofillPopupControllerImpl::element_bounds(); |
| 119 } | 119 } |
| 120 #if !defined(OS_ANDROID) | 120 #if !defined(OS_ANDROID) |
| 121 const gfx::Font& GetNameFontForRow(size_t index) const { | 121 const gfx::Font& GetNameFontForRow(size_t index) const { |
| 122 return AutofillPopupControllerImpl::GetNameFontForRow(index); | 122 return AutofillPopupControllerImpl::GetNameFontForRow(index); |
| 123 } | 123 } |
| 124 const gfx::Font& subtext_font() const { | 124 const gfx::Font& subtext_font() const { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 199 } |
| 200 | 200 |
| 201 protected: | 201 protected: |
| 202 scoped_ptr<MockAutofillManagerDelegate> manager_delegate_; | 202 scoped_ptr<MockAutofillManagerDelegate> manager_delegate_; |
| 203 scoped_ptr<NiceMock<MockAutofillExternalDelegate> > external_delegate_; | 203 scoped_ptr<NiceMock<MockAutofillExternalDelegate> > external_delegate_; |
| 204 testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_; | 204 testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_; |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 TEST_F(AutofillPopupControllerUnitTest, SetBounds) { | 207 TEST_F(AutofillPopupControllerUnitTest, SetBounds) { |
| 208 // Ensure the popup size can be set and causes a redraw. | 208 // Ensure the popup size can be set and causes a redraw. |
| 209 gfx::Rect popup_bounds(10, 10, 100, 100); | 209 gfx::RectF popup_bounds(10, 10, 100, 100); |
| 210 | 210 |
| 211 EXPECT_CALL(*autofill_popup_controller_, | 211 EXPECT_CALL(*autofill_popup_controller_, |
| 212 UpdateBoundsAndRedrawPopup()); | 212 UpdateBoundsAndRedrawPopup()); |
| 213 | 213 |
| 214 popup_controller()->SetPopupBounds(popup_bounds); | 214 popup_controller()->SetPopupBounds(popup_bounds); |
| 215 | 215 |
| 216 EXPECT_EQ(popup_bounds, popup_controller()->popup_bounds()); | 216 EXPECT_EQ(popup_bounds, popup_controller()->popup_bounds()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { | 219 TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) { |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 int desired_width = autofill_popup_controller_->GetDesiredPopupWidth(); | 569 int desired_width = autofill_popup_controller_->GetDesiredPopupWidth(); |
| 570 int desired_height = autofill_popup_controller_->GetDesiredPopupHeight(); | 570 int desired_height = autofill_popup_controller_->GetDesiredPopupHeight(); |
| 571 | 571 |
| 572 // Set up the visible screen space. | 572 // Set up the visible screen space. |
| 573 gfx::Display display(0, | 573 gfx::Display display(0, |
| 574 gfx::Rect(0, 0, desired_width * 2, desired_height * 2)); | 574 gfx::Rect(0, 0, desired_width * 2, desired_height * 2)); |
| 575 | 575 |
| 576 // Store the possible element bounds and the popup bounds they should result | 576 // Store the possible element bounds and the popup bounds they should result |
| 577 // in. | 577 // in. |
| 578 std::vector<gfx::RectF> element_bounds; | 578 std::vector<gfx::RectF> element_bounds; |
| 579 std::vector<gfx::Rect> expected_popup_bounds; | 579 std::vector<gfx::RectF> expected_popup_bounds; |
| 580 | 580 |
| 581 // The popup grows down and to the right. | 581 // The popup grows down and to the right. |
| 582 element_bounds.push_back(gfx::RectF(0, 0, 0, 0)); | 582 element_bounds.push_back(gfx::RectF(0, 0, 0, 0)); |
| 583 expected_popup_bounds.push_back( | 583 expected_popup_bounds.push_back( |
| 584 gfx::Rect(0, 0, desired_width, desired_height)); | 584 gfx::RectF(0, 0, desired_width, desired_height)); |
| 585 | 585 |
| 586 // The popup grows down and to the left. | 586 // The popup grows down and to the left. |
| 587 element_bounds.push_back(gfx::RectF(2 * desired_width, 0, 0, 0)); | 587 element_bounds.push_back(gfx::RectF(2 * desired_width, 0, 0, 0)); |
| 588 expected_popup_bounds.push_back( | 588 expected_popup_bounds.push_back( |
| 589 gfx::Rect(desired_width, 0, desired_width, desired_height)); | 589 gfx::RectF(desired_width, 0, desired_width, desired_height)); |
| 590 | 590 |
| 591 // The popup grows up and to the right. | 591 // The popup grows up and to the right. |
| 592 element_bounds.push_back(gfx::RectF(0, 2 * desired_height, 0, 0)); | 592 element_bounds.push_back(gfx::RectF(0, 2 * desired_height, 0, 0)); |
| 593 expected_popup_bounds.push_back( | 593 expected_popup_bounds.push_back( |
| 594 gfx::Rect(0, desired_height, desired_width, desired_height)); | 594 gfx::RectF(0, desired_height, desired_width, desired_height)); |
| 595 | 595 |
| 596 // The popup grows up and to the left. | 596 // The popup grows up and to the left. |
| 597 element_bounds.push_back( | 597 element_bounds.push_back( |
| 598 gfx::RectF(2 * desired_width, 2 * desired_height, 0, 0)); | 598 gfx::RectF(2 * desired_width, 2 * desired_height, 0, 0)); |
| 599 expected_popup_bounds.push_back( | 599 expected_popup_bounds.push_back( |
| 600 gfx::Rect(desired_width, desired_height, desired_width, desired_height)); | 600 gfx::RectF(desired_width, desired_height, desired_width, desired_height)); |
| 601 | 601 |
| 602 // The popup would be partial off the top and left side of the screen. | 602 // The popup would be partial off the top and left side of the screen. |
| 603 element_bounds.push_back( | 603 element_bounds.push_back( |
| 604 gfx::RectF(-desired_width / 2, -desired_height / 2, 0, 0)); | 604 gfx::RectF(-desired_width / 2, -desired_height / 2, 0, 0)); |
| 605 expected_popup_bounds.push_back( | 605 expected_popup_bounds.push_back( |
| 606 gfx::Rect(0, 0, desired_width, desired_height)); | 606 gfx::RectF(0, 0, desired_width, desired_height)); |
| 607 | 607 |
| 608 // The popup would be partially off the bottom and the right side of | 608 // The popup would be partially off the bottom and the right side of |
| 609 // the screen. | 609 // the screen. |
| 610 element_bounds.push_back( | 610 element_bounds.push_back( |
| 611 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); | 611 gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); |
| 612 expected_popup_bounds.push_back( | 612 expected_popup_bounds.push_back( |
| 613 gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, | 613 gfx::RectF((desired_width + 1) / 2, (desired_height + 1) / 2, |
| 614 desired_width, desired_height)); | 614 desired_width, desired_height)); |
| 615 | 615 |
| 616 for (size_t i = 0; i < element_bounds.size(); ++i) { | 616 for (size_t i = 0; i < element_bounds.size(); ++i) { |
| 617 AutofillDriverImpl* driver = | 617 AutofillDriverImpl* driver = |
| 618 AutofillDriverImpl::FromWebContents(web_contents()); | 618 AutofillDriverImpl::FromWebContents(web_contents()); |
| 619 NiceMock<MockAutofillExternalDelegate> external_delegate( | 619 NiceMock<MockAutofillExternalDelegate> external_delegate( |
| 620 web_contents(), driver->autofill_manager(), driver); | 620 web_contents(), driver->autofill_manager(), driver); |
| 621 TestAutofillPopupController* autofill_popup_controller = | 621 TestAutofillPopupController* autofill_popup_controller = |
| 622 new TestAutofillPopupController(external_delegate.GetWeakPtr(), | 622 new TestAutofillPopupController(external_delegate.GetWeakPtr(), |
| 623 element_bounds[i]); | 623 element_bounds[i]); |
| 624 | 624 |
| 625 autofill_popup_controller->set_display(display); | 625 autofill_popup_controller->set_display(display); |
| 626 autofill_popup_controller->Show(names, names, names, autofill_ids); | 626 autofill_popup_controller->Show(names, names, names, autofill_ids); |
| 627 | 627 |
| 628 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 628 EXPECT_EQ(expected_popup_bounds[i].ToString(), |
| 629 autofill_popup_controller->popup_bounds().ToString()) << | 629 autofill_popup_controller->popup_bounds().ToString()) << |
| 630 "Popup bounds failed to match for test " << i; | 630 "Popup bounds failed to match for test " << i; |
| 631 | 631 |
| 632 // Hide the controller to delete it. | 632 // Hide the controller to delete it. |
| 633 autofill_popup_controller->DoHide(); | 633 autofill_popup_controller->DoHide(); |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 } // namespace autofill | 637 } // namespace autofill |
| OLD | NEW |