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 23 matching lines...) Expand all Loading... |
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_->DidAcceptAutofillSuggestion(autofill_item[0], |
160 autofill_ids[0], 0); | 160 autofill_ids[0]); |
161 } | 161 } |
162 | 162 |
163 // Test that data list elements for a node will appear in the Autofill popup. | 163 // Test that data list elements for a node will appear in the Autofill popup. |
164 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 164 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
165 IssueOnQuery(kQueryId); | 165 IssueOnQuery(kQueryId); |
166 | 166 |
167 std::vector<string16> data_list_items; | 167 std::vector<string16> data_list_items; |
168 data_list_items.push_back(string16()); | 168 data_list_items.push_back(string16()); |
169 std::vector<int> data_list_ids; | 169 std::vector<int> data_list_ids; |
170 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 170 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // Test that the Autofill delegate doesn't try and fill a form with a | 218 // Test that the Autofill delegate doesn't try and fill a form with a |
219 // negative unique id. | 219 // negative unique id. |
220 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 220 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
221 // Ensure it doesn't try to preview the negative id. | 221 // Ensure it doesn't try to preview the negative id. |
222 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 222 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
223 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 223 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
224 external_delegate_->SelectAutofillSuggestion(-1); | 224 external_delegate_->SelectAutofillSuggestion(-1); |
225 | 225 |
226 // Ensure it doesn't try to fill the form in with the negative id. | 226 // Ensure it doesn't try to fill the form in with the negative id. |
227 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); | 227 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
228 external_delegate_->DidAcceptAutofillSuggestion(string16(), -1, 0); | 228 external_delegate_->DidAcceptAutofillSuggestion(string16(), -1); |
229 } | 229 } |
230 | 230 |
231 // Test that the ClearPreview IPC is only sent the form was being previewed | 231 // Test that the ClearPreview IPC is only sent the form was being previewed |
232 // (i.e. it isn't autofilling a password). | 232 // (i.e. it isn't autofilling a password). |
233 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 233 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
234 // Called by SelectAutofillSuggestion, add expectation to remove | 234 // Called by SelectAutofillSuggestion, add expectation to remove |
235 // warning. | 235 // warning. |
236 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 236 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
237 | 237 |
238 // Ensure selecting a new password entries or Autofill entries will | 238 // Ensure selecting a new password entries or Autofill entries will |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 283 |
284 // Called by DidAutofillSuggestions, add expectation to remove warning. | 284 // Called by DidAutofillSuggestions, add expectation to remove warning. |
285 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | 285 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); |
286 | 286 |
287 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); | 287 EXPECT_CALL(*external_delegate_, HideAutofillPopup()); |
288 | 288 |
289 // This should trigger a call to hide the popup since | 289 // This should trigger a call to hide the popup since |
290 // we've selected an option. | 290 // we've selected an option. |
291 external_delegate_->DidAcceptAutofillSuggestion( | 291 external_delegate_->DidAcceptAutofillSuggestion( |
292 suggestions[0], | 292 suggestions[0], |
293 WebAutofillClient::MenuItemIDPasswordEntry, | 293 WebAutofillClient::MenuItemIDPasswordEntry); |
294 0); | |
295 } | 294 } |
OLD | NEW |