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

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..9e08bc904ffdad38e0894371489b583e6dbd4613 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
@@ -3,11 +3,13 @@
// 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"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
+#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
using ::testing::_;
@@ -34,10 +36,23 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
public:
explicit TestAutofillPopupController(
AutofillExternalDelegate* external_delegate)
- : AutofillPopupControllerImpl(external_delegate, NULL, gfx::Rect()) {}
+ : AutofillPopupControllerImpl(external_delegate, NULL, gfx::Rect()) {
+ ON_CALL(*this, GetDisplayNearestPoint(_)).WillByDefault(
+ testing::Return(gfx::Display()));
+
+ ON_CALL(*this, element_bounds()).WillByDefault(
+ testing::ReturnRef(element_bounds_));
Ilya Sherman 2013/01/15 22:29:55 I think I recall Scott mentioning that gMock shoul
csharp 2013/01/16 20:56:58 Removed the two new mocks I had added.
+ }
virtual ~TestAutofillPopupController() {}
+ void set_element_bounds(const gfx::Rect& element_bounds) {
+ element_bounds_ = element_bounds;
+ }
+
// 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,13 +74,35 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
void DoHide() {
AutofillPopupControllerImpl::Hide();
}
+ const gfx::Rect& popup_bounds() const {
+ return AutofillPopupControllerImpl::popup_bounds();
+ }
+#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
+ int GetDesiredPopupWidth() const {
+ return AutofillPopupControllerImpl::GetDesiredPopupWidth();
+ }
+ int GetDesiredPopupHeight() const {
+ return AutofillPopupControllerImpl::GetDesiredPopupHeight();
+ }
+
Ilya Sherman 2013/01/15 22:29:55 nit: Extra newline.
csharp 2013/01/16 20:56:58 Done.
+ MOCK_CONST_METHOD0(element_bounds, const gfx::Rect&());
MOCK_METHOD1(InvalidateRow, void(size_t));
MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
MOCK_METHOD0(Hide, void());
+ MOCK_CONST_METHOD1(GetDisplayNearestPoint, gfx::Display(const gfx::Point&));
private:
virtual void ShowView() OVERRIDE {}
+
+ gfx::Rect element_bounds_;
};
} // namespace
@@ -239,8 +276,8 @@ TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
EXPECT_EQ(controller, controller2);
controller->Hide();
- TestAutofillPopupController* test_controller =
- new TestAutofillPopupController(&delegate);
+ testing::NiceMock<TestAutofillPopupController>* test_controller =
+ new testing::NiceMock<TestAutofillPopupController>(&delegate);
EXPECT_CALL(*test_controller, Hide());
gfx::Rect bounds(0, 0, 1, 2);
@@ -258,3 +295,84 @@ 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);
+ gfx::Display display(0, popup_bounds);
+ EXPECT_CALL(*autofill_popup_controller_, GetDisplayNearestPoint(_)
+ ).WillRepeatedly(testing::Return(display));
Ilya Sherman 2013/01/15 22:29:55 nit: Closing paren should be on the previous line;
csharp 2013/01/16 20:56:58 Fixed.
+
+ 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
+
+TEST_F(AutofillPopupControllerUnitTest, GrowPopupInSpace) {
+ std::vector<string16> names(1);
+ std::vector<int> autofill_ids(1, 1);
+
+ // Call Show so that GetDesired...() will be able to provide valid values.
+ autofill_popup_controller_->Show(names, names, names, autofill_ids);
+ int desired_width = autofill_popup_controller_->GetDesiredPopupWidth();
+ int desired_height = autofill_popup_controller_->GetDesiredPopupHeight();
+
+ // Setup the visible screen space.
+ gfx::Display display(0, gfx::Rect(0, 0,
+ desired_width * 2, desired_height * 2));
+ EXPECT_CALL(*autofill_popup_controller_, GetDisplayNearestPoint(_)
+ ).WillRepeatedly(testing::Return(display));
+
+ // The popup grows down and to the right.
+ autofill_popup_controller_->set_element_bounds(gfx::Rect(0, 0, 0, 0));
+ autofill_popup_controller_->Show(names, names, names, autofill_ids);
+ EXPECT_EQ(gfx::Rect(0, 0, desired_width, desired_height).ToString(),
+ autofill_popup_controller_->popup_bounds().ToString());
+
+ // The popup grows down and to the left.
+ autofill_popup_controller_->set_element_bounds(
+ gfx::Rect(2 * desired_width, 0, 0, 0));
Ilya Sherman 2013/01/15 22:29:55 Hmm, this puts the element completely off screen,
csharp 2013/01/16 20:56:58 Added two tests for the popup only going partially
+ autofill_popup_controller_->Show(names, names, names, autofill_ids);
+ EXPECT_EQ(gfx::Rect(desired_width, 0,
+ desired_width, desired_height).ToString(),
+ autofill_popup_controller_->popup_bounds().ToString());
+
+ // The popup grows up and to the right.
+ autofill_popup_controller_->set_element_bounds(
+ gfx::Rect(0, 2 * desired_height, 0, 0));
+ autofill_popup_controller_->Show(names, names, names, autofill_ids);
+ EXPECT_EQ(gfx::Rect(0, desired_height,
+ desired_width, desired_height).ToString(),
+ autofill_popup_controller_->popup_bounds().ToString());
+
+ // The popup grows up and to the left.
+ autofill_popup_controller_->set_element_bounds(
+ gfx::Rect(2 * desired_width, 2 * desired_height, 0, 0));
+ autofill_popup_controller_->Show(names, names, names, autofill_ids);
+ EXPECT_EQ(gfx::Rect(desired_width, desired_height,
+ desired_width, desired_height).ToString(),
+ autofill_popup_controller_->popup_bounds().ToString());
+}

Powered by Google App Engine
This is Rietveld 408576698