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

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate_unittest.cc

Issue 18693005: Move AutofillMsg_ClearPreviewedForm IPC send to AutofillDriverImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 7 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
(...skipping 24 matching lines...) Expand all
35 const int kAutofillProfileId = 1; 35 const int kAutofillProfileId = 1;
36 36
37 class MockAutofillDriver : public TestAutofillDriver { 37 class MockAutofillDriver : public TestAutofillDriver {
38 public: 38 public:
39 explicit MockAutofillDriver(content::WebContents* web_contents) 39 explicit MockAutofillDriver(content::WebContents* web_contents)
40 : TestAutofillDriver(web_contents) {} 40 : TestAutofillDriver(web_contents) {}
41 41
42 // Mock methods to enable testability. 42 // Mock methods to enable testability.
43 MOCK_METHOD1(SetRendererActionOnFormDataReception, 43 MOCK_METHOD1(SetRendererActionOnFormDataReception,
44 void(RendererFormDataAction action)); 44 void(RendererFormDataAction action));
45 MOCK_METHOD0(RendererShouldClearForm, void()); 45 MOCK_METHOD0(RendererShouldClearFilledForm, void());
46 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
46 47
47 private: 48 private:
48 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 49 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
49 }; 50 };
50 51
51 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
52 public:
53 MockAutofillExternalDelegate(content::WebContents* web_contents,
54 AutofillManager* autofill_manger,
55 AutofillDriver* autofill_driver)
56 : AutofillExternalDelegate(web_contents, autofill_manger,
57 autofill_driver) {}
58
59 ~MockAutofillExternalDelegate() {}
60
61 MOCK_METHOD0(ClearPreviewedForm, void());
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
65 };
66
67 class MockAutofillManagerDelegate 52 class MockAutofillManagerDelegate
68 : public autofill::TestAutofillManagerDelegate { 53 : public autofill::TestAutofillManagerDelegate {
69 public: 54 public:
70 MockAutofillManagerDelegate() {} 55 MockAutofillManagerDelegate() {}
71 56
72 MOCK_METHOD7(ShowAutofillPopup, 57 MOCK_METHOD7(ShowAutofillPopup,
73 void(const gfx::RectF& element_bounds, 58 void(const gfx::RectF& element_bounds,
74 base::i18n::TextDirection text_direction, 59 base::i18n::TextDirection text_direction,
75 const std::vector<base::string16>& values, 60 const std::vector<base::string16>& values,
76 const std::vector<base::string16>& labels, 61 const std::vector<base::string16>& labels,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 class AutofillExternalDelegateUnitTest 94 class AutofillExternalDelegateUnitTest
110 : public ChromeRenderViewHostTestHarness { 95 : public ChromeRenderViewHostTestHarness {
111 protected: 96 protected:
112 virtual void SetUp() OVERRIDE { 97 virtual void SetUp() OVERRIDE {
113 ChromeRenderViewHostTestHarness::SetUp(); 98 ChromeRenderViewHostTestHarness::SetUp();
114 autofill_driver_.reset(new MockAutofillDriver(web_contents())); 99 autofill_driver_.reset(new MockAutofillDriver(web_contents()));
115 autofill_manager_.reset( 100 autofill_manager_.reset(
116 new MockAutofillManager(autofill_driver_.get(), 101 new MockAutofillManager(autofill_driver_.get(),
117 &manager_delegate_)); 102 &manager_delegate_));
118 external_delegate_.reset( 103 external_delegate_.reset(
119 new testing::NiceMock<MockAutofillExternalDelegate>( 104 new AutofillExternalDelegate(
120 web_contents(), 105 web_contents(),
121 autofill_manager_.get(), autofill_driver_.get())); 106 autofill_manager_.get(), autofill_driver_.get()));
122 } 107 }
123 108
124 virtual void TearDown() OVERRIDE { 109 virtual void TearDown() OVERRIDE {
125 // Order of destruction is important as AutofillManager relies on 110 // Order of destruction is important as AutofillManager relies on
126 // PersonalDataManager to be around when it gets destroyed. Also, a real 111 // PersonalDataManager to be around when it gets destroyed. Also, a real
127 // AutofillManager is tied to the lifetime of the WebContents, so it must 112 // AutofillManager is tied to the lifetime of the WebContents, so it must
128 // be destroyed at the destruction of the WebContents. 113 // be destroyed at the destruction of the WebContents.
129 autofill_manager_.reset(); 114 autofill_manager_.reset();
130 external_delegate_.reset(); 115 external_delegate_.reset();
131 autofill_driver_.reset(); 116 autofill_driver_.reset();
132 ChromeRenderViewHostTestHarness::TearDown(); 117 ChromeRenderViewHostTestHarness::TearDown();
133 } 118 }
134 119
135 // Issue an OnQuery call with the given |query_id|. 120 // Issue an OnQuery call with the given |query_id|.
136 void IssueOnQuery(int query_id) { 121 void IssueOnQuery(int query_id) {
137 const FormData form; 122 const FormData form;
138 FormFieldData field; 123 FormFieldData field;
139 field.is_focusable = true; 124 field.is_focusable = true;
140 field.should_autocomplete = true; 125 field.should_autocomplete = true;
141 const gfx::RectF element_bounds; 126 const gfx::RectF element_bounds;
142 127
143 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); 128 external_delegate_->OnQuery(query_id, form, field, element_bounds, true);
144 } 129 }
145 130
146 MockAutofillManagerDelegate manager_delegate_; 131 MockAutofillManagerDelegate manager_delegate_;
147 scoped_ptr<MockAutofillDriver> autofill_driver_; 132 scoped_ptr<MockAutofillDriver> autofill_driver_;
148 scoped_ptr<MockAutofillManager> autofill_manager_; 133 scoped_ptr<MockAutofillManager> autofill_manager_;
149 scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> > 134 scoped_ptr<AutofillExternalDelegate> external_delegate_;
150 external_delegate_;
151 }; 135 };
152 136
153 // Test that our external delegate called the virtual methods at the right time. 137 // Test that our external delegate called the virtual methods at the right time.
154 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 138 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
155 IssueOnQuery(kQueryId); 139 IssueOnQuery(kQueryId);
156 140
157 // The enums must be cast to ints to prevent compile errors on linux_rel. 141 // The enums must be cast to ints to prevent compile errors on linux_rel.
158 EXPECT_CALL(manager_delegate_, 142 EXPECT_CALL(manager_delegate_,
159 ShowAutofillPopup( 143 ShowAutofillPopup(
160 _, _, _, _, _, 144 _, _, _, _, _,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 autofill_ids); 287 autofill_ids);
304 } 288 }
305 289
306 // Test that the Autofill delegate doesn't try and fill a form with a 290 // Test that the Autofill delegate doesn't try and fill a form with a
307 // negative unique id. 291 // negative unique id.
308 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 292 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
309 // Ensure it doesn't try to preview the negative id. 293 // Ensure it doesn't try to preview the negative id.
310 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 294 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
311 EXPECT_CALL(*autofill_driver_, 295 EXPECT_CALL(*autofill_driver_,
312 SetRendererActionOnFormDataReception(_)).Times(0); 296 SetRendererActionOnFormDataReception(_)).Times(0);
313 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 297 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
314 external_delegate_->DidSelectSuggestion(-1); 298 external_delegate_->DidSelectSuggestion(-1);
315 299
316 // Ensure it doesn't try to fill the form in with the negative id. 300 // Ensure it doesn't try to fill the form in with the negative id.
317 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 301 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
318 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 302 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
319 EXPECT_CALL(*autofill_driver_, 303 EXPECT_CALL(*autofill_driver_,
320 SetRendererActionOnFormDataReception(_)).Times(0); 304 SetRendererActionOnFormDataReception(_)).Times(0);
321 external_delegate_->DidAcceptSuggestion(base::string16(), -1); 305 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
322 } 306 }
323 307
324 // Test that the ClearPreview IPC is only sent the form was being previewed 308 // Test that the ClearPreview call is only sent if the form was being previewed
325 // (i.e. it isn't autofilling a password). 309 // (i.e. it isn't autofilling a password).
326 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 310 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
327 // Called by DidSelectSuggestion, add expectation to remove warning. 311 // Called by DidSelectSuggestion, add expectation to remove warning.
328 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 312 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
329 313
330 // Ensure selecting a new password entries or Autofill entries will 314 // Ensure selecting a new password entries or Autofill entries will
331 // cause any previews to get cleared. 315 // cause any previews to get cleared.
332 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 316 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
333 external_delegate_->DidSelectSuggestion( 317 external_delegate_->DidSelectSuggestion(
334 WebAutofillClient::MenuItemIDPasswordEntry); 318 WebAutofillClient::MenuItemIDPasswordEntry);
335 319
336 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); 320 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
337 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception( 321 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception(
338 AutofillDriver::FORM_DATA_ACTION_PREVIEW)); 322 AutofillDriver::FORM_DATA_ACTION_PREVIEW));
339 external_delegate_->DidSelectSuggestion(1); 323 external_delegate_->DidSelectSuggestion(1);
340 } 324 }
341 325
342 // Test that the popup is hidden once we are done editing the autofill field. 326 // Test that the popup is hidden once we are done editing the autofill field.
343 TEST_F(AutofillExternalDelegateUnitTest, 327 TEST_F(AutofillExternalDelegateUnitTest,
344 ExternalDelegateHidePopupAfterEditing) { 328 ExternalDelegateHidePopupAfterEditing) {
345 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); 329 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _));
346 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 330 autofill::GenerateTestAutofillPopup(external_delegate_.get());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // we've selected an option. 374 // we've selected an option.
391 external_delegate_->DidAcceptSuggestion( 375 external_delegate_->DidAcceptSuggestion(
392 suggestions[0], 376 suggestions[0],
393 WebAutofillClient::MenuItemIDPasswordEntry); 377 WebAutofillClient::MenuItemIDPasswordEntry);
394 } 378 }
395 379
396 // Test that the driver is directed to clear the form after being notified that 380 // Test that the driver is directed to clear the form after being notified that
397 // the user accepted the suggestion to clear the form. 381 // the user accepted the suggestion to clear the form.
398 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) { 382 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) {
399 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 383 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
400 EXPECT_CALL(*autofill_driver_, RendererShouldClearForm()); 384 EXPECT_CALL(*autofill_driver_, RendererShouldClearFilledForm());
401 385
402 external_delegate_->DidAcceptSuggestion( 386 external_delegate_->DidAcceptSuggestion(
403 base::string16(), 387 base::string16(),
404 WebAutofillClient::MenuItemIDClearForm); 388 WebAutofillClient::MenuItemIDClearForm);
405 } 389 }
406 390
407 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { 391 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) {
408 // Set up a field that shouldn't get autocompleted or display warnings. 392 // Set up a field that shouldn't get autocompleted or display warnings.
409 const FormData form; 393 const FormData form;
410 FormFieldData field; 394 FormFieldData field;
(...skipping 13 matching lines...) Expand all
424 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 408 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
425 409
426 external_delegate_->OnSuggestionsReturned(kQueryId, 410 external_delegate_->OnSuggestionsReturned(kQueryId,
427 autofill_items, 411 autofill_items,
428 autofill_items, 412 autofill_items,
429 autofill_items, 413 autofill_items,
430 autofill_ids); 414 autofill_ids);
431 } 415 }
432 416
433 } // namespace autofill 417 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698