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/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 Loading... |
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 void SetPopupBounds(const gfx::Rect& bounds) { |
| 43 AutofillPopupControllerImpl::SetPopupBounds(bounds); |
| 44 } |
| 45 const std::vector<string16>& names() const { |
| 46 return AutofillPopupControllerImpl::names(); |
| 47 } |
41 const std::vector<string16>& subtexts() const { | 48 const std::vector<string16>& subtexts() const { |
42 return AutofillPopupControllerImpl::subtexts(); | 49 return AutofillPopupControllerImpl::subtexts(); |
43 } | 50 } |
44 int selected_line() const { | 51 int selected_line() const { |
45 return AutofillPopupControllerImpl::selected_line(); | 52 return AutofillPopupControllerImpl::selected_line(); |
46 } | 53 } |
47 void SetSelectedLine(size_t selected_line) { | 54 void SetSelectedLine(size_t selected_line) { |
48 AutofillPopupControllerImpl::SetSelectedLine(selected_line); | 55 AutofillPopupControllerImpl::SetSelectedLine(selected_line); |
49 } | 56 } |
50 void SelectNextLine() { | 57 void SelectNextLine() { |
51 AutofillPopupControllerImpl::SelectNextLine(); | 58 AutofillPopupControllerImpl::SelectNextLine(); |
52 } | 59 } |
53 void SelectPreviousLine() { | 60 void SelectPreviousLine() { |
54 AutofillPopupControllerImpl::SelectPreviousLine(); | 61 AutofillPopupControllerImpl::SelectPreviousLine(); |
55 } | 62 } |
56 bool RemoveSelectedLine() { | 63 bool RemoveSelectedLine() { |
57 return AutofillPopupControllerImpl::RemoveSelectedLine(); | 64 return AutofillPopupControllerImpl::RemoveSelectedLine(); |
58 } | 65 } |
59 void DoHide() { | 66 void DoHide() { |
60 AutofillPopupControllerImpl::Hide(); | 67 AutofillPopupControllerImpl::Hide(); |
61 } | 68 } |
| 69 #if !defined(OS_ANDROID) |
| 70 const gfx::Font& name_font() const { |
| 71 return AutofillPopupControllerImpl::name_font(); |
| 72 } |
| 73 const gfx::Font& subtext_font() const { |
| 74 return AutofillPopupControllerImpl::subtext_font(); |
| 75 } |
| 76 #endif |
62 | 77 |
63 MOCK_METHOD1(InvalidateRow, void(size_t)); | 78 MOCK_METHOD1(InvalidateRow, void(size_t)); |
64 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); | 79 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void()); |
65 MOCK_METHOD0(Hide, void()); | 80 MOCK_METHOD0(Hide, void()); |
| 81 MOCK_METHOD0(UpdatePopupBounds, void()); |
66 | 82 |
67 private: | 83 private: |
68 virtual void ShowView() OVERRIDE {} | 84 virtual void ShowView() OVERRIDE {} |
69 }; | 85 }; |
70 | 86 |
71 } // namespace | 87 } // namespace |
72 | 88 |
73 class AutofillPopupControllerUnitTest : public ::testing::Test { | 89 class AutofillPopupControllerUnitTest : public ::testing::Test { |
74 public: | 90 public: |
75 AutofillPopupControllerUnitTest() | 91 AutofillPopupControllerUnitTest() |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 NULL, | 267 NULL, |
252 bounds); | 268 bounds); |
253 EXPECT_EQ( | 269 EXPECT_EQ( |
254 bounds, | 270 bounds, |
255 static_cast<AutofillPopupController*>(controller3)->element_bounds()); | 271 static_cast<AutofillPopupController*>(controller3)->element_bounds()); |
256 controller3->Hide(); | 272 controller3->Hide(); |
257 | 273 |
258 EXPECT_CALL(delegate, ControllerDestroyed()); | 274 EXPECT_CALL(delegate, ControllerDestroyed()); |
259 delete test_controller; | 275 delete test_controller; |
260 } | 276 } |
| 277 |
| 278 #if !defined(OS_ANDROID) |
| 279 TEST_F(AutofillPopupControllerUnitTest, ElideText) { |
| 280 std::vector<string16> names; |
| 281 names.push_back(ASCIIToUTF16("Text that will need to be trimmed")); |
| 282 names.push_back(ASCIIToUTF16("Untrimmed")); |
| 283 |
| 284 std::vector<string16> subtexts; |
| 285 subtexts.push_back(ASCIIToUTF16("Label that will be trimmed")); |
| 286 subtexts.push_back(ASCIIToUTF16("Untrimmed")); |
| 287 |
| 288 std::vector<string16> icons(2, string16()); |
| 289 std::vector<int> autofill_ids(2, 0); |
| 290 |
| 291 // Ensure the popup will be too small to display all of the first row. |
| 292 int popup_max_width = |
| 293 autofill_popup_controller_->name_font().GetStringWidth(names[0]) + |
| 294 autofill_popup_controller_->subtext_font().GetStringWidth(subtexts[0]) - |
| 295 25; |
| 296 gfx::Rect popup_bounds = gfx::Rect(0, 0, popup_max_width, 0); |
| 297 autofill_popup_controller_->SetPopupBounds(popup_bounds); |
| 298 |
| 299 // The popup bounds have already been properly set above. |
| 300 EXPECT_CALL(*autofill_popup_controller_, UpdatePopupBounds()); |
| 301 |
| 302 autofill_popup_controller_->Show(names, subtexts, icons, autofill_ids); |
| 303 |
| 304 // The first element was long so it should have been trimmed. |
| 305 EXPECT_NE(names[0], autofill_popup_controller_->names()[0]); |
| 306 EXPECT_NE(subtexts[0], autofill_popup_controller_->subtexts()[0]); |
| 307 |
| 308 // The second element was shorter so it should be unchanged. |
| 309 EXPECT_EQ(names[1], autofill_popup_controller_->names()[1]); |
| 310 EXPECT_EQ(subtexts[1], autofill_popup_controller_->subtexts()[1]); |
| 311 } |
| 312 #endif |
OLD | NEW |