| Index: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
|
| diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
|
| index 37975e8b1e7733a584b0f8c92053f803fb0b03a1..cf892a7b0ab4cceaa209749b7b83a7417d94762a 100644
|
| --- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
|
| @@ -3,6 +3,7 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/utf_string_conversions.h"
|
| #include "chrome/browser/autofill/test_autofill_external_delegate.h"
|
| #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -38,6 +39,12 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
|
| virtual ~TestAutofillPopupController() {}
|
|
|
| // Making protected functions public for testing
|
| + void SetPopupBounds(const gfx::Rect& bounds) {
|
| + AutofillPopupControllerImpl::SetPopupBounds(bounds);
|
| + }
|
| + const std::vector<string16>& names() const {
|
| + return AutofillPopupControllerImpl::names();
|
| + }
|
| const std::vector<string16>& subtexts() const {
|
| return AutofillPopupControllerImpl::subtexts();
|
| }
|
| @@ -59,10 +66,19 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
|
| void DoHide() {
|
| AutofillPopupControllerImpl::Hide();
|
| }
|
| +#if !defined(OS_ANDROID)
|
| + const gfx::Font& name_font() const {
|
| + return AutofillPopupControllerImpl::name_font();
|
| + }
|
| + const gfx::Font& subtext_font() const {
|
| + return AutofillPopupControllerImpl::subtext_font();
|
| + }
|
| +#endif
|
|
|
| MOCK_METHOD1(InvalidateRow, void(size_t));
|
| MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
|
| MOCK_METHOD0(Hide, void());
|
| + MOCK_METHOD0(UpdatePopupBounds, void());
|
|
|
| private:
|
| virtual void ShowView() OVERRIDE {}
|
| @@ -258,3 +274,39 @@ TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
|
| EXPECT_CALL(delegate, ControllerDestroyed());
|
| delete test_controller;
|
| }
|
| +
|
| +#if !defined(OS_ANDROID)
|
| +TEST_F(AutofillPopupControllerUnitTest, ElideText) {
|
| + std::vector<string16> names;
|
| + names.push_back(ASCIIToUTF16("Text that will need to be trimmed"));
|
| + names.push_back(ASCIIToUTF16("Untrimmed"));
|
| +
|
| + std::vector<string16> subtexts;
|
| + subtexts.push_back(ASCIIToUTF16("Label that will be trimmed"));
|
| + subtexts.push_back(ASCIIToUTF16("Untrimmed"));
|
| +
|
| + std::vector<string16> icons(2, string16());
|
| + std::vector<int> autofill_ids(2, 0);
|
| +
|
| + // Ensure the popup will be too small to display all of the first row.
|
| + int popup_max_width =
|
| + autofill_popup_controller_->name_font().GetStringWidth(names[0]) +
|
| + autofill_popup_controller_->subtext_font().GetStringWidth(subtexts[0]) -
|
| + 25;
|
| + gfx::Rect popup_bounds = gfx::Rect(0, 0, popup_max_width, 0);
|
| + autofill_popup_controller_->SetPopupBounds(popup_bounds);
|
| +
|
| + // The popup bounds have already been properly set above.
|
| + EXPECT_CALL(*autofill_popup_controller_, UpdatePopupBounds());
|
| +
|
| + autofill_popup_controller_->Show(names, subtexts, icons, autofill_ids);
|
| +
|
| + // The first element was long so it should have been trimmed.
|
| + EXPECT_NE(names[0], autofill_popup_controller_->names()[0]);
|
| + EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]);
|
| +
|
| + // The second element was shorter so it should be unchanged.
|
| + EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]);
|
| + EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]);
|
| +}
|
| +#endif
|
|
|