| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 41 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 42 public: | 42 public: |
| 43 MockAutofillExternalDelegate(AutofillManager* autofill_manager, | 43 MockAutofillExternalDelegate(AutofillManager* autofill_manager, |
| 44 AutofillDriver* autofill_driver) | 44 AutofillDriver* autofill_driver) |
| 45 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} | 45 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} |
| 46 ~MockAutofillExternalDelegate() override {} | 46 ~MockAutofillExternalDelegate() override {} |
| 47 | 47 |
| 48 void DidSelectSuggestion(const base::string16& value, | 48 void DidSelectSuggestion(const base::string16& value, |
| 49 int identifier) override {} | 49 int identifier) override {} |
| 50 void RemoveSuggestion(const base::string16& value, int identifier) override {} | 50 bool RemoveSuggestion(const base::string16& value, int identifier) override { |
| 51 return true; |
| 52 } |
| 51 void ClearPreviewedForm() override {} | 53 void ClearPreviewedForm() override {} |
| 52 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() { | 54 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr() { |
| 53 return AutofillExternalDelegate::GetWeakPtr(); | 55 return AutofillExternalDelegate::GetWeakPtr(); |
| 54 } | 56 } |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 class MockAutofillClient : public autofill::TestAutofillClient { | 59 class MockAutofillClient : public autofill::TestAutofillClient { |
| 58 public: | 60 public: |
| 59 MockAutofillClient() : prefs_(autofill::test::PrefServiceForTesting()) {} | 61 MockAutofillClient() : prefs_(autofill::test::PrefServiceForTesting()) {} |
| 60 ~MockAutofillClient() override {} | 62 ~MockAutofillClient() override {} |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 autofill_popup_controller_->Show(suggestions); | 243 autofill_popup_controller_->Show(suggestions); |
| 242 | 244 |
| 243 // Generate a popup, so it can be hidden later. It doesn't matter what the | 245 // Generate a popup, so it can be hidden later. It doesn't matter what the |
| 244 // external_delegate thinks is being shown in the process, since we are just | 246 // external_delegate thinks is being shown in the process, since we are just |
| 245 // testing the popup here. | 247 // testing the popup here. |
| 246 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 248 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 247 | 249 |
| 248 // No line is selected so the removal should fail. | 250 // No line is selected so the removal should fail. |
| 249 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | 251 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); |
| 250 | 252 |
| 251 // Try to remove the last entry and ensure it fails (it is an option). | |
| 252 autofill_popup_controller_->SetSelectedLine( | |
| 253 autofill_popup_controller_->GetLineCount() - 1); | |
| 254 EXPECT_FALSE(autofill_popup_controller_->RemoveSelectedLine()); | |
| 255 EXPECT_LE(0, autofill_popup_controller_->selected_line()); | |
| 256 | |
| 257 // Remove the first entry. The popup should be redrawn since its size has | 253 // Remove the first entry. The popup should be redrawn since its size has |
| 258 // changed. | 254 // changed. |
| 259 EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); | 255 EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup()); |
| 260 autofill_popup_controller_->SetSelectedLine(0); | 256 autofill_popup_controller_->SetSelectedLine(0); |
| 261 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); | 257 EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine()); |
| 262 | 258 |
| 263 // Remove the last entry. The popup should then be hidden since there are | 259 // Remove the last entry. The popup should then be hidden since there are |
| 264 // no Autofill entries left. | 260 // no Autofill entries left. |
| 265 EXPECT_CALL(*autofill_popup_controller_, Hide()); | 261 EXPECT_CALL(*autofill_popup_controller_, Hide()); |
| 266 autofill_popup_controller_->SetSelectedLine(0); | 262 autofill_popup_controller_->SetSelectedLine(0); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 524 |
| 529 // The second element was shorter so it should be unchanged. | 525 // The second element was shorter so it should be unchanged. |
| 530 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, | 526 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).value, |
| 531 autofill_popup_controller_->GetElidedValueAt(1)); | 527 autofill_popup_controller_->GetElidedValueAt(1)); |
| 532 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, | 528 EXPECT_EQ(autofill_popup_controller_->GetSuggestionAt(1).label, |
| 533 autofill_popup_controller_->GetElidedLabelAt(1)); | 529 autofill_popup_controller_->GetElidedLabelAt(1)); |
| 534 } | 530 } |
| 535 #endif | 531 #endif |
| 536 | 532 |
| 537 } // namespace autofill | 533 } // namespace autofill |
| OLD | NEW |