| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 30 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 31 public: | 31 public: |
| 32 MockAutofillExternalDelegate(TabContentsWrapper* wrapper, | 32 MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| 33 AutofillManager* autofill_manger) | 33 AutofillManager* autofill_manger) |
| 34 : TestAutofillExternalDelegate(wrapper, autofill_manger) {} | 34 : TestAutofillExternalDelegate(wrapper, autofill_manger) {} |
| 35 ~MockAutofillExternalDelegate() {} | 35 ~MockAutofillExternalDelegate() {} |
| 36 | 36 |
| 37 MOCK_METHOD5(ApplyAutofillSuggestions, void( | 37 MOCK_METHOD4(ApplyAutofillSuggestions, void( |
| 38 const std::vector<string16>& autofill_values, | 38 const std::vector<string16>& autofill_values, |
| 39 const std::vector<string16>& autofill_labels, | 39 const std::vector<string16>& autofill_labels, |
| 40 const std::vector<string16>& autofill_icons, | 40 const std::vector<string16>& autofill_icons, |
| 41 const std::vector<int>& autofill_unique_ids, | 41 const std::vector<int>& autofill_unique_ids)); |
| 42 int separator_index)); | |
| 43 | 42 |
| 44 MOCK_METHOD4(OnQueryPlatformSpecific, | 43 MOCK_METHOD4(OnQueryPlatformSpecific, |
| 45 void(int query_id, | 44 void(int query_id, |
| 46 const webkit::forms::FormData& form, | 45 const webkit::forms::FormData& form, |
| 47 const webkit::forms::FormField& field, | 46 const webkit::forms::FormField& field, |
| 48 const gfx::Rect& bounds)); | 47 const gfx::Rect& bounds)); |
| 49 | 48 |
| 50 MOCK_METHOD0(ClearPreviewedForm, void()); | 49 MOCK_METHOD0(ClearPreviewedForm, void()); |
| 51 | 50 |
| 52 MOCK_METHOD0(HideAutofillPopup, void()); | 51 MOCK_METHOD0(HideAutofillPopup, void()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 field.is_focusable = true; | 103 field.is_focusable = true; |
| 105 field.should_autocomplete = true; | 104 field.should_autocomplete = true; |
| 106 const gfx::Rect bounds; | 105 const gfx::Rect bounds; |
| 107 | 106 |
| 108 EXPECT_CALL(*external_delegate_, | 107 EXPECT_CALL(*external_delegate_, |
| 109 OnQueryPlatformSpecific(kQueryId, form, field, bounds)); | 108 OnQueryPlatformSpecific(kQueryId, form, field, bounds)); |
| 110 | 109 |
| 111 // This should call OnQueryPlatform specific. | 110 // This should call OnQueryPlatform specific. |
| 112 external_delegate_->OnQuery(kQueryId, form, field, bounds, false); | 111 external_delegate_->OnQuery(kQueryId, form, field, bounds, false); |
| 113 | 112 |
| 114 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _, _)); | 113 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); |
| 115 | 114 |
| 116 // This should call ApplyAutofillSuggestions. | 115 // This should call ApplyAutofillSuggestions. |
| 117 std::vector<string16> autofill_item; | 116 std::vector<string16> autofill_item; |
| 118 autofill_item.push_back(string16()); | 117 autofill_item.push_back(string16()); |
| 119 std::vector<int> autofill_ids; | 118 std::vector<int> autofill_ids; |
| 120 autofill_ids.push_back(1); | 119 autofill_ids.push_back(1); |
| 121 external_delegate_->OnSuggestionsReturned(kQueryId, | 120 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 122 autofill_item, | 121 autofill_item, |
| 123 autofill_item, | 122 autofill_item, |
| 124 autofill_item, | 123 autofill_item, |
| 125 autofill_ids); | 124 autofill_ids); |
| 126 | 125 |
| 127 | 126 |
| 128 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 127 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
| 129 | 128 |
| 130 // Called by DidAutofillSuggestions, add expectation to remove warning. | 129 // Called by DidAutofillSuggestions, add expectation to remove warning. |
| 131 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 130 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 132 | 131 |
| 133 // This should trigger a call to hide the popup since | 132 // This should trigger a call to hide the popup since |
| 134 // we've selected an option. | 133 // we've selected an option. |
| 135 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], | 134 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], |
| 136 autofill_ids[0], 0); | 135 autofill_ids[0], 0); |
| 137 } | 136 } |
| 138 | 137 |
| 139 // Test that the Autofill delegate doesn't try and fill a form with a | 138 // Test that the Autofill delegate doesn't try and fill a form with a |
| 140 // negative unique id. | 139 // negative unique id. |
| 141 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 140 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 142 // Ensure it doesn't try to preview the negative id. | 141 // Ensure it doesn't try to preview the negative id. |
| 143 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 142 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 144 external_delegate_->SelectAutofillSuggestionAtIndex(-1, 0); | 143 external_delegate_->SelectAutofillSuggestionAtIndex(-1); |
| 145 | 144 |
| 146 // Ensure it doesn't try to fill the form in with the negative id. | 145 // Ensure it doesn't try to fill the form in with the negative id. |
| 147 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 146 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| 148 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); | 147 external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0); |
| 149 } | 148 } |
| 150 | 149 |
| 151 // Test that the ClearPreview IPC is only sent the form was being previewed | 150 // Test that the ClearPreview IPC is only sent the form was being previewed |
| 152 // (i.e. it isn't autofilling a password). | 151 // (i.e. it isn't autofilling a password). |
| 153 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 152 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
| 154 // Called by SelectAutofillSuggestionAtIndex, add expectation to remove | 153 // Called by SelectAutofillSuggestionAtIndex, add expectation to remove |
| 155 // warning. | 154 // warning. |
| 156 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 155 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 157 | 156 |
| 158 // Ensure selecting a new password entries or Autofill entries will | 157 // Ensure selecting a new password entries or Autofill entries will |
| 159 // cause any previews to get cleared. | 158 // cause any previews to get cleared. |
| 160 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 159 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| 161 external_delegate_->SelectAutofillSuggestionAtIndex( | 160 external_delegate_->SelectAutofillSuggestionAtIndex( |
| 162 WebAutofillClient::MenuItemIDPasswordEntry, | 161 WebAutofillClient::MenuItemIDPasswordEntry); |
| 163 0); | |
| 164 | 162 |
| 165 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 163 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| 166 external_delegate_->SelectAutofillSuggestionAtIndex(1, 0); | 164 external_delegate_->SelectAutofillSuggestionAtIndex(1); |
| 167 } | 165 } |
| OLD | NEW |