| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 28 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 29 public: | 29 public: |
| 30 MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 30 MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| 31 AutofillManager* autofill_manger) | 31 AutofillManager* autofill_manger) |
| 32 : TestAutofillExternalDelegate(wrapper, autofill_manger) {} | 32 : TestAutofillExternalDelegate(wrapper, autofill_manger) {} |
| 33 ~MockAutofillExternalDelegate() {} | 33 ~MockAutofillExternalDelegate() {} |
| 34 | 34 |
| 35 MOCK_METHOD5(ApplyAutofillSuggestions, void( | 35 MOCK_METHOD4(ApplyAutofillSuggestions, void( |
| 36 const std::vector<string16>& autofill_values, | 36 const std::vector<string16>& autofill_values, |
| 37 const std::vector<string16>& autofill_labels, | 37 const std::vector<string16>& autofill_labels, |
| 38 const std::vector<string16>& autofill_icons, | 38 const std::vector<string16>& autofill_icons, |
| 39 const std::vector<int>& autofill_unique_ids, | 39 const std::vector<int>& autofill_unique_ids)); |
| 40 int separator_index)); | |
| 41 | 40 |
| 42 MOCK_METHOD4(OnQueryPlatformSpecific, | 41 MOCK_METHOD4(OnQueryPlatformSpecific, |
| 43 void(int query_id, | 42 void(int query_id, |
| 44 const webkit::forms::FormData& form, | 43 const webkit::forms::FormData& form, |
| 45 const webkit::forms::FormField& field, | 44 const webkit::forms::FormField& field, |
| 46 const gfx::Rect& bounds)); | 45 const gfx::Rect& bounds)); |
| 47 | 46 |
| 48 MOCK_METHOD0(HideAutofillPopup, void()); | 47 MOCK_METHOD0(HideAutofillPopup, void()); |
| 49 | 48 |
| 50 private: | 49 private: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 field.is_focusable = true; | 97 field.is_focusable = true; |
| 99 field.should_autocomplete = true; | 98 field.should_autocomplete = true; |
| 100 const gfx::Rect bounds; | 99 const gfx::Rect bounds; |
| 101 | 100 |
| 102 EXPECT_CALL(*external_delegate_, | 101 EXPECT_CALL(*external_delegate_, |
| 103 OnQueryPlatformSpecific(kQueryId, form, field, bounds)); | 102 OnQueryPlatformSpecific(kQueryId, form, field, bounds)); |
| 104 | 103 |
| 105 // This should call OnQueryPlatform specific. | 104 // This should call OnQueryPlatform specific. |
| 106 external_delegate_->OnQuery(kQueryId, form, field, bounds, false); | 105 external_delegate_->OnQuery(kQueryId, form, field, bounds, false); |
| 107 | 106 |
| 108 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _, _)); | 107 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); |
| 109 | 108 |
| 110 // This should call ApplyAutofillSuggestions. | 109 // This should call ApplyAutofillSuggestions. |
| 111 std::vector<string16> autofill_item; | 110 std::vector<string16> autofill_item; |
| 112 autofill_item.push_back(string16()); | 111 autofill_item.push_back(string16()); |
| 113 std::vector<int> autofill_ids; | 112 std::vector<int> autofill_ids; |
| 114 autofill_ids.push_back(1); | 113 autofill_ids.push_back(1); |
| 115 external_delegate_->OnSuggestionsReturned(kQueryId, | 114 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 116 autofill_item, | 115 autofill_item, |
| 117 autofill_item, | 116 autofill_item, |
| 118 autofill_item, | 117 autofill_item, |
| 119 autofill_ids); | 118 autofill_ids); |
| 120 | 119 |
| 121 | 120 |
| 122 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 121 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
| 123 | 122 |
| 124 // This should trigger a call to hide the popup since | 123 // This should trigger a call to hide the popup since |
| 125 // we've selected an option. | 124 // we've selected an option. |
| 126 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], | 125 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], |
| 127 autofill_ids[0], 0); | 126 autofill_ids[0], 0); |
| 128 } | 127 } |
| 129 | 128 |
| 130 // Test that the Autofill delegate doesn't try and fill a form with a | 129 // Test that the Autofill delegate doesn't try and fill a form with a |
| 131 // negative unique id. | 130 // negative unique id. |
| 132 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 131 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 133 // Ensure it doesn't try to preview the negative id. | 132 // Ensure it doesn't try to preview the negative id. |
| 134 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 133 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 135 external_delegate_->SelectAutofillSuggestionAtIndex(-1, 0); | 134 external_delegate_->SelectAutofillSuggestionAtIndex(-1); |
| 136 | 135 |
| 137 // Ensure it doesn't try to fill the form in with the negative id. | 136 // Ensure it doesn't try to fill the form in with the negative id. |
| 138 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 137 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 139 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); | 138 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); |
| 140 } | 139 } |
| OLD | NEW |