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 22 matching lines...) Expand all Loading... |
33 const int kAutofillProfileId = 1; | 33 const int kAutofillProfileId = 1; |
34 | 34 |
35 class MockAutofillExternalDelegate : | 35 class MockAutofillExternalDelegate : |
36 public autofill::TestAutofillExternalDelegate { | 36 public autofill::TestAutofillExternalDelegate { |
37 public: | 37 public: |
38 MockAutofillExternalDelegate(content::WebContents* web_contents, | 38 MockAutofillExternalDelegate(content::WebContents* web_contents, |
39 AutofillManager* autofill_manger) | 39 AutofillManager* autofill_manger) |
40 : TestAutofillExternalDelegate(web_contents, autofill_manger) {} | 40 : TestAutofillExternalDelegate(web_contents, autofill_manger) {} |
41 ~MockAutofillExternalDelegate() {} | 41 ~MockAutofillExternalDelegate() {} |
42 | 42 |
| 43 bool popup_visible() { |
| 44 return autofill::TestAutofillExternalDelegate::popup_visible(); |
| 45 } |
| 46 |
43 MOCK_METHOD4(ApplyAutofillSuggestions, void( | 47 MOCK_METHOD4(ApplyAutofillSuggestions, void( |
44 const std::vector<string16>& autofill_values, | 48 const std::vector<string16>& autofill_values, |
45 const std::vector<string16>& autofill_labels, | 49 const std::vector<string16>& autofill_labels, |
46 const std::vector<string16>& autofill_icons, | 50 const std::vector<string16>& autofill_icons, |
47 const std::vector<int>& autofill_unique_ids)); | 51 const std::vector<int>& autofill_unique_ids)); |
48 | 52 |
49 MOCK_METHOD0(ClearPreviewedForm, void()); | 53 MOCK_METHOD0(ClearPreviewedForm, void()); |
50 | 54 |
51 MOCK_METHOD0(HideAutofillPopup, void()); | |
52 | |
53 MOCK_METHOD1(SetBounds, void(const gfx::Rect& bounds)); | 55 MOCK_METHOD1(SetBounds, void(const gfx::Rect& bounds)); |
54 | 56 |
55 private: | 57 private: |
56 virtual void HideAutofillPopupInternal() {}; | 58 virtual void HideAutofillPopupInternal() {}; |
57 }; | 59 }; |
58 | 60 |
59 class MockAutofillManager : public AutofillManager { | 61 class MockAutofillManager : public AutofillManager { |
60 public: | 62 public: |
61 explicit MockAutofillManager(content::WebContents* web_contents, | 63 explicit MockAutofillManager(content::WebContents* web_contents, |
62 autofill::AutofillManagerDelegate* delegate) | 64 autofill::AutofillManagerDelegate* delegate) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // This should call ApplyAutofillSuggestions. | 144 // This should call ApplyAutofillSuggestions. |
143 std::vector<string16> autofill_item; | 145 std::vector<string16> autofill_item; |
144 autofill_item.push_back(string16()); | 146 autofill_item.push_back(string16()); |
145 std::vector<int> autofill_ids; | 147 std::vector<int> autofill_ids; |
146 autofill_ids.push_back(kAutofillProfileId); | 148 autofill_ids.push_back(kAutofillProfileId); |
147 external_delegate_->OnSuggestionsReturned(kQueryId, | 149 external_delegate_->OnSuggestionsReturned(kQueryId, |
148 autofill_item, | 150 autofill_item, |
149 autofill_item, | 151 autofill_item, |
150 autofill_item, | 152 autofill_item, |
151 autofill_ids); | 153 autofill_ids); |
| 154 EXPECT_TRUE(external_delegate_->popup_visible()); |
152 | 155 |
153 | 156 // Called when hiding the popup. |
154 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 157 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()); |
155 | 158 |
156 // Called by DidAutofillSuggestions, add expectation to remove warning. | 159 // Called by DidAutofillSuggestions, add expectation to remove warning. |
157 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 160 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
158 | 161 |
159 // This should trigger a call to hide the popup since | 162 // This should trigger a call to hide the popup since |
160 // we've selected an option. | 163 // we've selected an option. |
161 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], | 164 external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0], |
162 autofill_ids[0], 0); | 165 autofill_ids[0], 0); |
| 166 EXPECT_FALSE(external_delegate_->popup_visible()); |
163 } | 167 } |
164 | 168 |
165 // Test that data list elements for a node will appear in the Autofill popup. | 169 // Test that data list elements for a node will appear in the Autofill popup. |
166 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 170 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
167 IssueOnQuery(kQueryId); | 171 IssueOnQuery(kQueryId); |
168 | 172 |
169 std::vector<string16> data_list_items; | 173 std::vector<string16> data_list_items; |
170 data_list_items.push_back(string16()); | 174 data_list_items.push_back(string16()); |
171 std::vector<int> data_list_ids; | 175 std::vector<int> data_list_ids; |
172 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 176 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 external_delegate_->SelectAutofillSuggestionAtIndex( | 247 external_delegate_->SelectAutofillSuggestionAtIndex( |
244 WebAutofillClient::MenuItemIDPasswordEntry); | 248 WebAutofillClient::MenuItemIDPasswordEntry); |
245 | 249 |
246 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 250 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
247 external_delegate_->SelectAutofillSuggestionAtIndex(1); | 251 external_delegate_->SelectAutofillSuggestionAtIndex(1); |
248 } | 252 } |
249 | 253 |
250 // Test that the popup is hidden once we are done editing the autofill field. | 254 // Test that the popup is hidden once we are done editing the autofill field. |
251 TEST_F(AutofillExternalDelegateUnitTest, | 255 TEST_F(AutofillExternalDelegateUnitTest, |
252 ExternalDelegateHidePopupAfterEditing) { | 256 ExternalDelegateHidePopupAfterEditing) { |
253 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 257 EXPECT_CALL(*external_delegate_, SetBounds(_)); |
| 258 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); |
| 259 |
| 260 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 261 EXPECT_TRUE(external_delegate_->popup_visible()); |
| 262 |
| 263 // Called when hiding the popup. |
| 264 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()); |
254 | 265 |
255 external_delegate_->DidEndTextFieldEditing(); | 266 external_delegate_->DidEndTextFieldEditing(); |
| 267 |
| 268 EXPECT_FALSE(external_delegate_->popup_visible()); |
256 } | 269 } |
| 270 |
| 271 // Test that the popup is marked as visible after recieving password |
| 272 // suggestions. |
| 273 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { |
| 274 std::vector<string16> suggestions; |
| 275 suggestions.push_back(string16()); |
| 276 |
| 277 FormFieldData field; |
| 278 field.is_focusable = true; |
| 279 field.should_autocomplete = true; |
| 280 const gfx::Rect bounds; |
| 281 |
| 282 EXPECT_CALL(*external_delegate_, SetBounds(bounds)); |
| 283 |
| 284 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 285 EXPECT_CALL(*external_delegate_, |
| 286 ApplyAutofillSuggestions(_, _, _, testing::ElementsAre( |
| 287 static_cast<int>( |
| 288 WebAutofillClient::MenuItemIDPasswordEntry)))); |
| 289 |
| 290 external_delegate_->OnShowPasswordSuggestions(suggestions, |
| 291 field, |
| 292 bounds); |
| 293 EXPECT_TRUE(external_delegate_->popup_visible()); |
| 294 |
| 295 // Called by DidAutofillSuggestions, add expectation to remove warning. |
| 296 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
| 297 |
| 298 // Called when hiding the popup. |
| 299 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()); |
| 300 |
| 301 // This should trigger a call to hide the popup since |
| 302 // we've selected an option. |
| 303 external_delegate_->DidAcceptAutofillSuggestions( |
| 304 suggestions[0], |
| 305 WebAutofillClient::MenuItemIDPasswordEntry, |
| 306 0); |
| 307 EXPECT_FALSE(external_delegate_->popup_visible()); |
| 308 } |
OLD | NEW |