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

Unified Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 11817051: Elide text in the new Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
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..f12086890aaf314c485f895bb39857b8cbc0c969 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,9 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
virtual ~TestAutofillPopupController() {}
// Making protected functions public for testing
+ const std::vector<string16>& names() const {
+ return AutofillPopupControllerImpl::names();
+ }
const std::vector<string16>& subtexts() const {
return AutofillPopupControllerImpl::subtexts();
}
@@ -59,10 +63,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(MaxVisiblePopupWidth, int());
private:
virtual void ShowView() OVERRIDE {}
@@ -258,3 +271,37 @@ 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;
+
+ EXPECT_CALL(*autofill_popup_controller_, MaxVisiblePopupWidth()).WillOnce(
+ testing::Return(popup_max_width));
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698