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/browser/ui/autofill/autofill_popup_view.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 TestingPrefServiceSimple prefs_; | 57 TestingPrefServiceSimple prefs_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
60 }; | 60 }; |
61 | 61 |
62 class TestAutofillPopupController : public AutofillPopupControllerImpl { | 62 class TestAutofillPopupController : public AutofillPopupControllerImpl { |
63 public: | 63 public: |
64 explicit TestAutofillPopupController( | 64 explicit TestAutofillPopupController( |
65 base::WeakPtr<AutofillExternalDelegate> external_delegate, | 65 base::WeakPtr<AutofillExternalDelegate> external_delegate, |
66 const gfx::RectF& element_bounds) | 66 const gfx::RectF& element_bounds) |
67 : AutofillPopupControllerImpl(external_delegate, NULL, element_bounds) {} | 67 : AutofillPopupControllerImpl( |
| 68 external_delegate, NULL, element_bounds, false) {} |
68 virtual ~TestAutofillPopupController() {} | 69 virtual ~TestAutofillPopupController() {} |
69 | 70 |
70 void set_display(const gfx::Display display) { | 71 void set_display(const gfx::Display display) { |
71 display_ = display; | 72 display_ = display; |
72 } | 73 } |
73 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const | 74 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const |
74 OVERRIDE { | 75 OVERRIDE { |
75 return display_; | 76 return display_; |
76 } | 77 } |
77 | 78 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 autofill_popup_controller_->RowWidthWithoutText(3)); | 358 autofill_popup_controller_->RowWidthWithoutText(3)); |
358 } | 359 } |
359 | 360 |
360 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 361 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
361 MockAutofillExternalDelegate delegate( | 362 MockAutofillExternalDelegate delegate( |
362 web_contents(), AutofillManager::FromWebContents(web_contents())); | 363 web_contents(), AutofillManager::FromWebContents(web_contents())); |
363 | 364 |
364 WeakPtr<AutofillPopupControllerImpl> controller = | 365 WeakPtr<AutofillPopupControllerImpl> controller = |
365 AutofillPopupControllerImpl::GetOrCreate( | 366 AutofillPopupControllerImpl::GetOrCreate( |
366 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, | 367 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, |
367 gfx::Rect()); | 368 gfx::Rect(), false); |
368 EXPECT_TRUE(controller.get()); | 369 EXPECT_TRUE(controller.get()); |
369 | 370 |
370 controller->Hide(); | 371 controller->Hide(); |
371 | 372 |
372 controller = AutofillPopupControllerImpl::GetOrCreate( | 373 controller = AutofillPopupControllerImpl::GetOrCreate( |
373 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, | 374 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, |
374 gfx::Rect()); | 375 gfx::Rect(), false); |
375 EXPECT_TRUE(controller.get()); | 376 EXPECT_TRUE(controller.get()); |
376 | 377 |
377 WeakPtr<AutofillPopupControllerImpl> controller2 = | 378 WeakPtr<AutofillPopupControllerImpl> controller2 = |
378 AutofillPopupControllerImpl::GetOrCreate(controller, | 379 AutofillPopupControllerImpl::GetOrCreate(controller, |
379 delegate.GetWeakPtr(), | 380 delegate.GetWeakPtr(), |
380 NULL, | 381 NULL, |
381 gfx::Rect()); | 382 gfx::Rect(), |
| 383 false); |
382 EXPECT_EQ(controller.get(), controller2.get()); | 384 EXPECT_EQ(controller.get(), controller2.get()); |
383 controller->Hide(); | 385 controller->Hide(); |
384 | 386 |
385 testing::NiceMock<TestAutofillPopupController>* test_controller = | 387 testing::NiceMock<TestAutofillPopupController>* test_controller = |
386 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), | 388 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), |
387 gfx::Rect()); | 389 gfx::Rect()); |
388 EXPECT_CALL(*test_controller, Hide()); | 390 EXPECT_CALL(*test_controller, Hide()); |
389 | 391 |
390 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); | 392 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); |
391 base::WeakPtr<AutofillPopupControllerImpl> controller3 = | 393 base::WeakPtr<AutofillPopupControllerImpl> controller3 = |
392 AutofillPopupControllerImpl::GetOrCreate( | 394 AutofillPopupControllerImpl::GetOrCreate( |
393 test_controller->GetWeakPtr(), | 395 test_controller->GetWeakPtr(), |
394 delegate.GetWeakPtr(), | 396 delegate.GetWeakPtr(), |
395 NULL, | 397 NULL, |
396 bounds); | 398 bounds, |
| 399 false); |
397 EXPECT_EQ( | 400 EXPECT_EQ( |
398 bounds, | 401 bounds, |
399 static_cast<AutofillPopupController*>(controller3.get())-> | 402 static_cast<AutofillPopupController*>(controller3.get())-> |
400 element_bounds()); | 403 element_bounds()); |
401 controller3->Hide(); | 404 controller3->Hide(); |
402 | 405 |
403 // Hide the test_controller to delete it. | 406 // Hide the test_controller to delete it. |
404 test_controller->DoHide(); | 407 test_controller->DoHide(); |
405 } | 408 } |
406 | 409 |
407 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 410 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { |
408 std::vector<string16> names(2); | 411 std::vector<string16> names(2); |
409 std::vector<int> ids(2); | 412 std::vector<int> ids(2); |
410 popup_controller()->SetValues(names, names, names, ids); | 413 popup_controller()->SetValues(names, names, names, ids); |
411 popup_controller()->SetSelectedLine(0); | 414 popup_controller()->SetSelectedLine(0); |
412 | 415 |
413 // Now show a new popup with the same controller, but with fewer items. | 416 // Now show a new popup with the same controller, but with fewer items. |
414 WeakPtr<AutofillPopupControllerImpl> controller = | 417 WeakPtr<AutofillPopupControllerImpl> controller = |
415 AutofillPopupControllerImpl::GetOrCreate( | 418 AutofillPopupControllerImpl::GetOrCreate( |
416 popup_controller()->GetWeakPtr(), | 419 popup_controller()->GetWeakPtr(), |
417 delegate()->GetWeakPtr(), | 420 delegate()->GetWeakPtr(), |
418 NULL, | 421 NULL, |
419 gfx::Rect()); | 422 gfx::Rect(), |
| 423 false); |
420 EXPECT_NE(0, controller->selected_line()); | 424 EXPECT_NE(0, controller->selected_line()); |
421 EXPECT_TRUE(controller->names().empty()); | 425 EXPECT_TRUE(controller->names().empty()); |
422 } | 426 } |
423 | 427 |
424 #if !defined(OS_ANDROID) | 428 #if !defined(OS_ANDROID) |
425 TEST_F(AutofillPopupControllerUnitTest, ElideText) { | 429 TEST_F(AutofillPopupControllerUnitTest, ElideText) { |
426 std::vector<string16> names; | 430 std::vector<string16> names; |
427 names.push_back(ASCIIToUTF16("Text that will need to be trimmed")); | 431 names.push_back(ASCIIToUTF16("Text that will need to be trimmed")); |
428 names.push_back(ASCIIToUTF16("Untrimmed")); | 432 names.push_back(ASCIIToUTF16("Untrimmed")); |
429 | 433 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 528 EXPECT_EQ(expected_popup_bounds[i].ToString(), |
525 autofill_popup_controller->popup_bounds().ToString()) << | 529 autofill_popup_controller->popup_bounds().ToString()) << |
526 "Popup bounds failed to match for test " << i; | 530 "Popup bounds failed to match for test " << i; |
527 | 531 |
528 // Hide the controller to delete it. | 532 // Hide the controller to delete it. |
529 autofill_popup_controller->DoHide(); | 533 autofill_popup_controller->DoHide(); |
530 } | 534 } |
531 } | 535 } |
532 | 536 |
533 } // namespace autofill | 537 } // namespace autofill |
OLD | NEW |