Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate_unittest.cc

Issue 11636040: AutofillPopupController clarifications + simplifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new workstation Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
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 MOCK_METHOD4(ApplyAutofillSuggestions, void( 43 MOCK_METHOD4(ApplyAutofillSuggestions, void(
44 const std::vector<string16>& autofill_values, 44 const std::vector<string16>& labels,
45 const std::vector<string16>& autofill_labels, 45 const std::vector<string16>& sub_labels,
46 const std::vector<string16>& autofill_icons, 46 const std::vector<string16>& icons,
47 const std::vector<int>& autofill_unique_ids)); 47 const std::vector<int>& identifiers));
48 48
49 MOCK_METHOD0(ClearPreviewedForm, void()); 49 MOCK_METHOD0(ClearPreviewedForm, void());
50 50
51 MOCK_METHOD1(EnsurePopupForElement, void(const gfx::Rect& element_bounds)); 51 MOCK_METHOD1(EnsurePopupForElement, void(const gfx::Rect& element_bounds));
52 52
53 MOCK_METHOD0(HideAutofillPopup, void()); 53 MOCK_METHOD0(HideAutofillPopup, void());
54 }; 54 };
55 55
56 class MockAutofillManager : public AutofillManager { 56 class MockAutofillManager : public AutofillManager {
57 public: 57 public:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 autofill_item, 149 autofill_item,
150 autofill_ids); 150 autofill_ids);
151 151
152 // Called by DidAutofillSuggestions, add expectation to remove warning. 152 // Called by DidAutofillSuggestions, add expectation to remove warning.
153 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 153 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
154 154
155 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); 155 EXPECT_CALL(*external_delegate_, HideAutofillPopup());
156 156
157 // This should trigger a call to hide the popup since 157 // This should trigger a call to hide the popup since
158 // we've selected an option. 158 // we've selected an option.
159 external_delegate_->DidAcceptAutofillSuggestion(autofill_item[0], 159 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]);
160 autofill_ids[0], 0);
161 } 160 }
162 161
163 // Test that data list elements for a node will appear in the Autofill popup. 162 // Test that data list elements for a node will appear in the Autofill popup.
164 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { 163 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
165 IssueOnQuery(kQueryId); 164 IssueOnQuery(kQueryId);
166 165
167 std::vector<string16> data_list_items; 166 std::vector<string16> data_list_items;
168 data_list_items.push_back(string16()); 167 data_list_items.push_back(string16());
169 std::vector<int> data_list_ids; 168 std::vector<int> data_list_ids;
170 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); 169 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 autofill_item, 213 autofill_item,
215 autofill_ids); 214 autofill_ids);
216 } 215 }
217 216
218 // Test that the Autofill delegate doesn't try and fill a form with a 217 // Test that the Autofill delegate doesn't try and fill a form with a
219 // negative unique id. 218 // negative unique id.
220 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 219 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
221 // Ensure it doesn't try to preview the negative id. 220 // Ensure it doesn't try to preview the negative id.
222 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 221 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
223 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 222 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
224 external_delegate_->SelectAutofillSuggestion(-1); 223 external_delegate_->DidSelectSuggestion(-1);
225 224
226 // Ensure it doesn't try to fill the form in with the negative id. 225 // Ensure it doesn't try to fill the form in with the negative id.
227 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 226 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
228 external_delegate_->DidAcceptAutofillSuggestion(string16(), -1, 0); 227 external_delegate_->DidAcceptSuggestion(string16(), -1);
229 } 228 }
230 229
231 // Test that the ClearPreview IPC is only sent the form was being previewed 230 // Test that the ClearPreview IPC is only sent the form was being previewed
232 // (i.e. it isn't autofilling a password). 231 // (i.e. it isn't autofilling a password).
233 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 232 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
234 // Called by SelectAutofillSuggestion, add expectation to remove 233 // Called by DidSelectSuggestion, add expectation to remove
235 // warning. 234 // warning.
236 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 235 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
237 236
238 // Ensure selecting a new password entries or Autofill entries will 237 // Ensure selecting a new password entries or Autofill entries will
239 // cause any previews to get cleared. 238 // cause any previews to get cleared.
240 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 239 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
241 external_delegate_->SelectAutofillSuggestion( 240 external_delegate_->DidSelectSuggestion(
242 WebAutofillClient::MenuItemIDPasswordEntry); 241 WebAutofillClient::MenuItemIDPasswordEntry);
243 242
244 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 243 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
245 external_delegate_->SelectAutofillSuggestion(1); 244 external_delegate_->DidSelectSuggestion(1);
246 } 245 }
247 246
248 // Test that the popup is hidden once we are done editing the autofill field. 247 // Test that the popup is hidden once we are done editing the autofill field.
249 TEST_F(AutofillExternalDelegateUnitTest, 248 TEST_F(AutofillExternalDelegateUnitTest,
250 ExternalDelegateHidePopupAfterEditing) { 249 ExternalDelegateHidePopupAfterEditing) {
251 EXPECT_CALL(*external_delegate_, EnsurePopupForElement(_)); 250 EXPECT_CALL(*external_delegate_, EnsurePopupForElement(_));
252 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); 251 EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _));
253 252
254 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 253 autofill::GenerateTestAutofillPopup(external_delegate_.get());
255 254
(...skipping 25 matching lines...) Expand all
281 field, 280 field,
282 element_bounds); 281 element_bounds);
283 282
284 // Called by DidAutofillSuggestions, add expectation to remove warning. 283 // Called by DidAutofillSuggestions, add expectation to remove warning.
285 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 284 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
286 285
287 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); 286 EXPECT_CALL(*external_delegate_, HideAutofillPopup());
288 287
289 // This should trigger a call to hide the popup since 288 // This should trigger a call to hide the popup since
290 // we've selected an option. 289 // we've selected an option.
291 external_delegate_->DidAcceptAutofillSuggestion( 290 external_delegate_->DidAcceptSuggestion(
292 suggestions[0], 291 suggestions[0],
293 WebAutofillClient::MenuItemIDPasswordEntry, 292 WebAutofillClient::MenuItemIDPasswordEntry);
294 0);
295 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698