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/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 ContentAutofillDriverFactory::FromWebContents(web_contents()); | 145 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
146 ContentAutofillDriver* driver = | 146 ContentAutofillDriver* driver = |
147 factory->DriverForFrame(web_contents()->GetMainFrame()); | 147 factory->DriverForFrame(web_contents()->GetMainFrame()); |
148 external_delegate_.reset( | 148 external_delegate_.reset( |
149 new NiceMock<MockAutofillExternalDelegate>( | 149 new NiceMock<MockAutofillExternalDelegate>( |
150 driver->autofill_manager(), | 150 driver->autofill_manager(), |
151 driver)); | 151 driver)); |
152 | 152 |
153 autofill_popup_controller_ = | 153 autofill_popup_controller_ = |
154 new testing::NiceMock<TestAutofillPopupController>( | 154 new testing::NiceMock<TestAutofillPopupController>( |
155 external_delegate_->GetWeakPtr(),gfx::Rect()); | 155 external_delegate_->GetWeakPtr(), gfx::RectF()); |
156 } | 156 } |
157 | 157 |
158 void TearDown() override { | 158 void TearDown() override { |
159 // This will make sure the controller and the view (if any) are both | 159 // This will make sure the controller and the view (if any) are both |
160 // cleaned up. | 160 // cleaned up. |
161 if (autofill_popup_controller_) | 161 if (autofill_popup_controller_) |
162 autofill_popup_controller_->DoHide(); | 162 autofill_popup_controller_->DoHide(); |
163 | 163 |
164 external_delegate_.reset(); | 164 external_delegate_.reset(); |
165 ChromeRenderViewHostTestHarness::TearDown(); | 165 ChromeRenderViewHostTestHarness::TearDown(); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { | 424 TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) { |
425 ContentAutofillDriverFactory* factory = | 425 ContentAutofillDriverFactory* factory = |
426 ContentAutofillDriverFactory::FromWebContents(web_contents()); | 426 ContentAutofillDriverFactory::FromWebContents(web_contents()); |
427 ContentAutofillDriver* driver = | 427 ContentAutofillDriver* driver = |
428 factory->DriverForFrame(web_contents()->GetMainFrame()); | 428 factory->DriverForFrame(web_contents()->GetMainFrame()); |
429 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver); | 429 MockAutofillExternalDelegate delegate(driver->autofill_manager(), driver); |
430 | 430 |
431 WeakPtr<AutofillPopupControllerImpl> controller = | 431 WeakPtr<AutofillPopupControllerImpl> controller = |
432 AutofillPopupControllerImpl::GetOrCreate( | 432 AutofillPopupControllerImpl::GetOrCreate( |
433 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), | 433 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, |
434 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); | 434 NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); |
435 EXPECT_TRUE(controller.get()); | 435 EXPECT_TRUE(controller.get()); |
436 | 436 |
437 controller->Hide(); | 437 controller->Hide(); |
438 | 438 |
439 controller = AutofillPopupControllerImpl::GetOrCreate( | 439 controller = AutofillPopupControllerImpl::GetOrCreate( |
440 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), | 440 WeakPtr<AutofillPopupControllerImpl>(), delegate.GetWeakPtr(), NULL, NULL, |
441 NULL, NULL, gfx::Rect(), base::i18n::UNKNOWN_DIRECTION); | 441 gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); |
442 EXPECT_TRUE(controller.get()); | 442 EXPECT_TRUE(controller.get()); |
443 | 443 |
444 WeakPtr<AutofillPopupControllerImpl> controller2 = | 444 WeakPtr<AutofillPopupControllerImpl> controller2 = |
445 AutofillPopupControllerImpl::GetOrCreate(controller, | 445 AutofillPopupControllerImpl::GetOrCreate( |
446 delegate.GetWeakPtr(), | 446 controller, delegate.GetWeakPtr(), NULL, NULL, gfx::RectF(), |
447 NULL, | 447 base::i18n::UNKNOWN_DIRECTION); |
448 NULL, | |
449 gfx::Rect(), | |
450 base::i18n::UNKNOWN_DIRECTION); | |
451 EXPECT_EQ(controller.get(), controller2.get()); | 448 EXPECT_EQ(controller.get(), controller2.get()); |
452 controller->Hide(); | 449 controller->Hide(); |
453 | 450 |
454 testing::NiceMock<TestAutofillPopupController>* test_controller = | 451 testing::NiceMock<TestAutofillPopupController>* test_controller = |
455 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), | 452 new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(), |
456 gfx::Rect()); | 453 gfx::RectF()); |
457 EXPECT_CALL(*test_controller, Hide()); | 454 EXPECT_CALL(*test_controller, Hide()); |
458 | 455 |
459 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); | 456 gfx::RectF bounds(0.f, 0.f, 1.f, 2.f); |
460 base::WeakPtr<AutofillPopupControllerImpl> controller3 = | 457 base::WeakPtr<AutofillPopupControllerImpl> controller3 = |
461 AutofillPopupControllerImpl::GetOrCreate( | 458 AutofillPopupControllerImpl::GetOrCreate( |
462 test_controller->GetWeakPtr(), | 459 test_controller->GetWeakPtr(), |
463 delegate.GetWeakPtr(), | 460 delegate.GetWeakPtr(), |
464 NULL, | 461 NULL, |
465 NULL, | 462 NULL, |
466 bounds, | 463 bounds, |
(...skipping 11 matching lines...) Expand all Loading... |
478 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { | 475 TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) { |
479 std::vector<Suggestion> suggestions; | 476 std::vector<Suggestion> suggestions; |
480 suggestions.push_back(Suggestion("", "", "", 0)); | 477 suggestions.push_back(Suggestion("", "", "", 0)); |
481 suggestions.push_back(Suggestion("", "", "", 0)); | 478 suggestions.push_back(Suggestion("", "", "", 0)); |
482 popup_controller()->SetValues(suggestions); | 479 popup_controller()->SetValues(suggestions); |
483 popup_controller()->SetSelectedLine(0); | 480 popup_controller()->SetSelectedLine(0); |
484 | 481 |
485 // Now show a new popup with the same controller, but with fewer items. | 482 // Now show a new popup with the same controller, but with fewer items. |
486 WeakPtr<AutofillPopupControllerImpl> controller = | 483 WeakPtr<AutofillPopupControllerImpl> controller = |
487 AutofillPopupControllerImpl::GetOrCreate( | 484 AutofillPopupControllerImpl::GetOrCreate( |
488 popup_controller()->GetWeakPtr(), | 485 popup_controller()->GetWeakPtr(), delegate()->GetWeakPtr(), NULL, |
489 delegate()->GetWeakPtr(), | 486 NULL, gfx::RectF(), base::i18n::UNKNOWN_DIRECTION); |
490 NULL, | |
491 NULL, | |
492 gfx::Rect(), | |
493 base::i18n::UNKNOWN_DIRECTION); | |
494 EXPECT_NE(0, controller->selected_line()); | 487 EXPECT_NE(0, controller->selected_line()); |
495 EXPECT_EQ(0u, controller->GetLineCount()); | 488 EXPECT_EQ(0u, controller->GetLineCount()); |
496 } | 489 } |
497 | 490 |
498 #if !defined(OS_ANDROID) | 491 #if !defined(OS_ANDROID) |
499 TEST_F(AutofillPopupControllerUnitTest, ElideText) { | 492 TEST_F(AutofillPopupControllerUnitTest, ElideText) { |
500 std::vector<Suggestion> suggestions; | 493 std::vector<Suggestion> suggestions; |
501 suggestions.push_back( | 494 suggestions.push_back( |
502 Suggestion("Text that will need to be trimmed", | 495 Suggestion("Text that will need to be trimmed", |
503 "Label that will be trimmed", "genericCC", 0)); | 496 "Label that will be trimmed", "genericCC", 0)); |
(...skipping 24 matching lines...) Expand all Loading... |
528 | 521 |
529 // The second element was shorter so it should be unchanged. | 522 // The second element was shorter so it should be unchanged. |
530 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 523 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, |
531 autofill_popup_controller_->GetElidedValueAt(1)); | 524 autofill_popup_controller_->GetElidedValueAt(1)); |
532 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 525 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, |
533 autofill_popup_controller_->GetElidedLabelAt(1)); | 526 autofill_popup_controller_->GetElidedLabelAt(1)); |
534 } | 527 } |
535 #endif | 528 #endif |
536 | 529 |
537 } // namespace autofill | 530 } // namespace autofill |
OLD | NEW |