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

Side by Side 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 unified diff | Download patch
OLDNEW
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/utf_string_conversions.h"
6 #include "chrome/browser/autofill/test_autofill_external_delegate.h" 7 #include "chrome/browser/autofill/test_autofill_external_delegate.h"
7 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 8 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
11 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
12 13
13 using ::testing::_; 14 using ::testing::_;
14 using ::testing::AtLeast; 15 using ::testing::AtLeast;
15 using WebKit::WebAutofillClient; 16 using WebKit::WebAutofillClient;
(...skipping 15 matching lines...) Expand all
31 }; 32 };
32 33
33 class TestAutofillPopupController : public AutofillPopupControllerImpl { 34 class TestAutofillPopupController : public AutofillPopupControllerImpl {
34 public: 35 public:
35 explicit TestAutofillPopupController( 36 explicit TestAutofillPopupController(
36 AutofillExternalDelegate* external_delegate) 37 AutofillExternalDelegate* external_delegate)
37 : AutofillPopupControllerImpl(external_delegate, NULL, gfx::Rect()) {} 38 : AutofillPopupControllerImpl(external_delegate, NULL, gfx::Rect()) {}
38 virtual ~TestAutofillPopupController() {} 39 virtual ~TestAutofillPopupController() {}
39 40
40 // Making protected functions public for testing 41 // Making protected functions public for testing
42 const std::vector<string16>& names() const {
43 return AutofillPopupControllerImpl::names();
44 }
41 const std::vector<string16>& subtexts() const { 45 const std::vector<string16>& subtexts() const {
42 return AutofillPopupControllerImpl::subtexts(); 46 return AutofillPopupControllerImpl::subtexts();
43 } 47 }
44 int selected_line() const { 48 int selected_line() const {
45 return AutofillPopupControllerImpl::selected_line(); 49 return AutofillPopupControllerImpl::selected_line();
46 } 50 }
47 void SetSelectedLine(size_t selected_line) { 51 void SetSelectedLine(size_t selected_line) {
48 AutofillPopupControllerImpl::SetSelectedLine(selected_line); 52 AutofillPopupControllerImpl::SetSelectedLine(selected_line);
49 } 53 }
50 void SelectNextLine() { 54 void SelectNextLine() {
51 AutofillPopupControllerImpl::SelectNextLine(); 55 AutofillPopupControllerImpl::SelectNextLine();
52 } 56 }
53 void SelectPreviousLine() { 57 void SelectPreviousLine() {
54 AutofillPopupControllerImpl::SelectPreviousLine(); 58 AutofillPopupControllerImpl::SelectPreviousLine();
55 } 59 }
56 bool RemoveSelectedLine() { 60 bool RemoveSelectedLine() {
57 return AutofillPopupControllerImpl::RemoveSelectedLine(); 61 return AutofillPopupControllerImpl::RemoveSelectedLine();
58 } 62 }
59 void DoHide() { 63 void DoHide() {
60 AutofillPopupControllerImpl::Hide(); 64 AutofillPopupControllerImpl::Hide();
61 } 65 }
66 #if !defined(OS_ANDROID)
67 const gfx::Font& name_font() const {
68 return AutofillPopupControllerImpl::name_font();
69 }
70 const gfx::Font& subtext_font() const {
71 return AutofillPopupControllerImpl::subtext_font();
72 }
73 #endif
62 74
63 MOCK_METHOD1(InvalidateRow, void(size_t)); 75 MOCK_METHOD1(InvalidateRow, void(size_t));
64 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); 76 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
65 MOCK_METHOD0(Hide, void()); 77 MOCK_METHOD0(Hide, void());
78 MOCK_METHOD0(MaxVisiblePopupWidth, int());
66 79
67 private: 80 private:
68 virtual void ShowView() OVERRIDE {} 81 virtual void ShowView() OVERRIDE {}
69 }; 82 };
70 83
71 } // namespace 84 } // namespace
72 85
73 class AutofillPopupControllerUnitTest : public ::testing::Test { 86 class AutofillPopupControllerUnitTest : public ::testing::Test {
74 public: 87 public:
75 AutofillPopupControllerUnitTest() 88 AutofillPopupControllerUnitTest()
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 NULL, 264 NULL,
252 bounds); 265 bounds);
253 EXPECT_EQ( 266 EXPECT_EQ(
254 bounds, 267 bounds,
255 static_cast<AutofillPopupController*>(controller3)->element_bounds()); 268 static_cast<AutofillPopupController*>(controller3)->element_bounds());
256 controller3->Hide(); 269 controller3->Hide();
257 270
258 EXPECT_CALL(delegate, ControllerDestroyed()); 271 EXPECT_CALL(delegate, ControllerDestroyed());
259 delete test_controller; 272 delete test_controller;
260 } 273 }
274
275 #if !defined(OS_ANDROID)
276 TEST_F(AutofillPopupControllerUnitTest, ElideText) {
277 std::vector<string16> names;
278 names.push_back(ASCIIToUTF16("Text that will need to be trimmed"));
279 names.push_back(ASCIIToUTF16("Untrimmed"));
280
281 std::vector<string16> subtexts;
282 subtexts.push_back(ASCIIToUTF16("Label that will be trimmed"));
283 subtexts.push_back(ASCIIToUTF16("Untrimmed"));
284
285 std::vector<string16> icons(2, string16());
286 std::vector<int> autofill_ids(2, 0);
287
288 // Ensure the popup will be too small to display all of the first row.
289 int popup_max_width =
290 autofill_popup_controller_->name_font().GetStringWidth(names[0]) +
291 autofill_popup_controller_->subtext_font().GetStringWidth(subtexts[0]) -
292 25;
293
294 EXPECT_CALL(*autofill_popup_controller_, MaxVisiblePopupWidth()).WillOnce(
295 testing::Return(popup_max_width));
296
297 autofill_popup_controller_->Show(names, subtexts, icons, autofill_ids);
298
299 // The first element was long so it should have been trimmed.
300 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]);
301 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]);
302
303 // The second element was shorter so it should be unchanged.
304 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]);
305 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]);
306 }
307 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698