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/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/prefs/testing_pref_service.h" | 7 #include "base/prefs/testing_pref_service.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
12 #include "components/autofill/browser/autofill_external_delegate.h" | 13 #include "components/autofill/browser/autofill_external_delegate.h" |
13 #include "components/autofill/browser/autofill_manager.h" | 14 #include "components/autofill/browser/autofill_manager.h" |
14 #include "components/autofill/browser/test_autofill_external_delegate.h" | 15 #include "components/autofill/browser/test_autofill_external_delegate.h" |
15 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 16 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const gfx::RectF& element_bounds() const { | 103 const gfx::RectF& element_bounds() const { |
103 return AutofillPopupControllerImpl::element_bounds(); | 104 return AutofillPopupControllerImpl::element_bounds(); |
104 } | 105 } |
105 #if !defined(OS_ANDROID) | 106 #if !defined(OS_ANDROID) |
106 const gfx::Font& GetNameFontForRow(size_t index) const { | 107 const gfx::Font& GetNameFontForRow(size_t index) const { |
107 return AutofillPopupControllerImpl::GetNameFontForRow(index); | 108 return AutofillPopupControllerImpl::GetNameFontForRow(index); |
108 } | 109 } |
109 const gfx::Font& subtext_font() const { | 110 const gfx::Font& subtext_font() const { |
110 return AutofillPopupControllerImpl::subtext_font(); | 111 return AutofillPopupControllerImpl::subtext_font(); |
111 } | 112 } |
| 113 int RowWidthWithoutText(int row) const { |
| 114 return AutofillPopupControllerImpl::RowWidthWithoutText(row); |
| 115 } |
112 #endif | 116 #endif |
113 int GetDesiredPopupWidth() const { | 117 int GetDesiredPopupWidth() const { |
114 return AutofillPopupControllerImpl::GetDesiredPopupWidth(); | 118 return AutofillPopupControllerImpl::GetDesiredPopupWidth(); |
115 } | 119 } |
116 int GetDesiredPopupHeight() const { | 120 int GetDesiredPopupHeight() const { |
117 return AutofillPopupControllerImpl::GetDesiredPopupHeight(); | 121 return AutofillPopupControllerImpl::GetDesiredPopupHeight(); |
118 } | 122 } |
119 | 123 |
120 WeakPtr<AutofillPopupControllerImpl> GetWeakPtr() { | 124 WeakPtr<AutofillPopupControllerImpl> GetWeakPtr() { |
121 return AutofillPopupControllerImpl::GetWeakPtr(); | 125 return AutofillPopupControllerImpl::GetWeakPtr(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 283 |
280 // Make sure next skips the unselectable separator. | 284 // Make sure next skips the unselectable separator. |
281 autofill_popup_controller_->SelectNextLine(); | 285 autofill_popup_controller_->SelectNextLine(); |
282 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); | 286 EXPECT_EQ(2, autofill_popup_controller_->selected_line()); |
283 | 287 |
284 // Make sure previous skips the unselectable separator. | 288 // Make sure previous skips the unselectable separator. |
285 autofill_popup_controller_->SelectPreviousLine(); | 289 autofill_popup_controller_->SelectPreviousLine(); |
286 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); | 290 EXPECT_EQ(0, autofill_popup_controller_->selected_line()); |
287 } | 291 } |
288 | 292 |
| 293 TEST_F(AutofillPopupControllerUnitTest, RowWidthWithoutText) { |
| 294 std::vector<string16> names(4); |
| 295 std::vector<string16> subtexts(4); |
| 296 std::vector<string16> icons(4); |
| 297 std::vector<int> ids(4); |
| 298 |
| 299 // Set up some visible display so the text values are kept. |
| 300 gfx::Display display(0, gfx::Rect(0, 0, 100, 100)); |
| 301 autofill_popup_controller_->set_display(display); |
| 302 |
| 303 // Give elements 1 and 3 subtexts and elements 2 and 3 icons, to ensure |
| 304 // all combinations of subtexts and icons. |
| 305 subtexts[1] = ASCIIToUTF16("x"); |
| 306 subtexts[3] = ASCIIToUTF16("x"); |
| 307 icons[2] = ASCIIToUTF16("x"); |
| 308 icons[3] = ASCIIToUTF16("x"); |
| 309 autofill_popup_controller_->Show(names, subtexts, icons, ids); |
| 310 |
| 311 int base_size = AutofillPopupView::kEndPadding * 2; |
| 312 int subtext_increase = AutofillPopupView::kNamePadding; |
| 313 int icon_increase = AutofillPopupView::kIconPadding + |
| 314 AutofillPopupView::kAutofillIconWidth; |
| 315 |
| 316 EXPECT_EQ(base_size, autofill_popup_controller_->RowWidthWithoutText(0)); |
| 317 EXPECT_EQ(base_size + subtext_increase, |
| 318 autofill_popup_controller_->RowWidthWithoutText(1)); |
| 319 EXPECT_EQ(base_size + icon_increase, |
| 320 autofill_popup_controller_->RowWidthWithoutText(2)); |
| 321 EXPECT_EQ(base_size + subtext_increase + icon_increase, |
| 322 autofill_popup_controller_->RowWidthWithoutText(3)); |
| 323 } |
| 324 |
289 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 325 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
290 MockAutofillExternalDelegate delegate( | 326 MockAutofillExternalDelegate delegate( |
291 web_contents(), AutofillManager::FromWebContents(web_contents())); | 327 web_contents(), AutofillManager::FromWebContents(web_contents())); |
292 | 328 |
293 WeakPtr<AutofillPopupControllerImpl> controller = | 329 WeakPtr<AutofillPopupControllerImpl> controller = |
294 AutofillPopupControllerImpl::GetOrCreate( | 330 AutofillPopupControllerImpl::GetOrCreate( |
295 WeakPtr<AutofillPopupControllerImpl>(), &delegate, NULL, gfx::Rect()); | 331 WeakPtr<AutofillPopupControllerImpl>(), &delegate, NULL, gfx::Rect()); |
296 EXPECT_TRUE(controller); | 332 EXPECT_TRUE(controller); |
297 | 333 |
298 controller->Hide(); | 334 controller->Hide(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 466 EXPECT_EQ(expected_popup_bounds[i].ToString(), |
431 autofill_popup_controller->popup_bounds().ToString()) << | 467 autofill_popup_controller->popup_bounds().ToString()) << |
432 "Popup bounds failed to match for test " << i; | 468 "Popup bounds failed to match for test " << i; |
433 | 469 |
434 // Hide the controller to delete it. | 470 // Hide the controller to delete it. |
435 autofill_popup_controller->DoHide(); | 471 autofill_popup_controller->DoHide(); |
436 } | 472 } |
437 } | 473 } |
438 | 474 |
439 } // namespace autofill | 475 } // namespace autofill |
OLD | NEW |