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

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

Issue 148413002: Add "previewing on hover" support for single-field autocomplete input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per review comments Created 6 years, 10 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/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 27 matching lines...) Expand all
38 class MockAutofillDriver : public TestAutofillDriver { 38 class MockAutofillDriver : public TestAutofillDriver {
39 public: 39 public:
40 MockAutofillDriver() {} 40 MockAutofillDriver() {}
41 // Mock methods to enable testability. 41 // Mock methods to enable testability.
42 MOCK_METHOD1(SetRendererActionOnFormDataReception, 42 MOCK_METHOD1(SetRendererActionOnFormDataReception,
43 void(RendererFormDataAction action)); 43 void(RendererFormDataAction action));
44 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, 44 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion,
45 void(const base::string16&)); 45 void(const base::string16&));
46 MOCK_METHOD0(RendererShouldClearFilledForm, void()); 46 MOCK_METHOD0(RendererShouldClearFilledForm, void());
47 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); 47 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
48 MOCK_METHOD1(RendererShouldPreviewAutoCompleteNode,
49 void(const base::string16&));
48 MOCK_METHOD1(RendererShouldSetNodeText, void(const base::string16&)); 50 MOCK_METHOD1(RendererShouldSetNodeText, void(const base::string16&));
49 51
50 private: 52 private:
51 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 53 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
52 }; 54 };
53 55
54 class MockAutofillManagerDelegate 56 class MockAutofillManagerDelegate
55 : public autofill::TestAutofillManagerDelegate { 57 : public autofill::TestAutofillManagerDelegate {
56 public: 58 public:
57 MockAutofillManagerDelegate() {} 59 MockAutofillManagerDelegate() {}
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 344 }
343 345
344 // Test that the Autofill delegate doesn't try and fill a form with a 346 // Test that the Autofill delegate doesn't try and fill a form with a
345 // negative unique id. 347 // negative unique id.
346 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 348 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
347 // Ensure it doesn't try to preview the negative id. 349 // Ensure it doesn't try to preview the negative id.
348 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 350 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
349 EXPECT_CALL(*autofill_driver_, 351 EXPECT_CALL(*autofill_driver_,
350 SetRendererActionOnFormDataReception(_)).Times(0); 352 SetRendererActionOnFormDataReception(_)).Times(0);
351 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 353 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
352 external_delegate_->DidSelectSuggestion(-1); 354 external_delegate_->DidSelectSuggestion(-1, ASCIIToUTF16(""));
Ilya Sherman 2014/02/22 05:59:51 nit: Prefer "base::string16()" to "ASCIIToUTF16(""
ziran.sun 2014/02/27 15:38:11 Done.
353 355
354 // Ensure it doesn't try to fill the form in with the negative id. 356 // Ensure it doesn't try to fill the form in with the negative id.
355 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 357 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
356 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); 358 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
357 EXPECT_CALL(*autofill_driver_, 359 EXPECT_CALL(*autofill_driver_,
358 SetRendererActionOnFormDataReception(_)).Times(0); 360 SetRendererActionOnFormDataReception(_)).Times(0);
359 external_delegate_->DidAcceptSuggestion(base::string16(), -1); 361 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
360 } 362 }
361 363
362 // Test that the ClearPreview call is only sent if the form was being previewed 364 // Test that the ClearPreview call is only sent if the form was being previewed
363 // (i.e. it isn't autofilling a password). 365 // (i.e. it isn't autofilling a password).
364 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 366 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
365 // Called by DidSelectSuggestion, add expectation to remove warning. 367 // Called by DidSelectSuggestion, add expectation to remove warning.
366 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); 368 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
367 369
368 // Ensure selecting a new password entries or Autofill entries will 370 // Ensure selecting a new password entries or Autofill entries will
369 // cause any previews to get cleared. 371 // cause any previews to get cleared.
370 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 372 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
371 external_delegate_->DidSelectSuggestion( 373 external_delegate_->DidSelectSuggestion(
372 WebAutofillClient::MenuItemIDPasswordEntry); 374 WebAutofillClient::MenuItemIDPasswordEntry, ASCIIToUTF16("baz foo"));
373 375
374 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 376 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
375 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception( 377 EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception(
376 AutofillDriver::FORM_DATA_ACTION_PREVIEW)); 378 AutofillDriver::FORM_DATA_ACTION_PREVIEW));
377 external_delegate_->DidSelectSuggestion(1); 379 external_delegate_->DidSelectSuggestion(1, ASCIIToUTF16("baz foo"));
380
381 // Ensure selecting an AutoComplete entries will cause any previews to
Ilya Sherman 2014/02/22 05:59:51 nit: "an AutoComplete entries" -> "an autocomplete
ziran.sun 2014/02/27 15:38:11 Done.
382 // get cleared.
383 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
384 external_delegate_->DidSelectSuggestion(
385 WebAutofillClient::MenuItemIDAutocompleteEntry, ASCIIToUTF16("baz foo"));
378 } 386 }
379 387
380 // Test that the popup is hidden once we are done editing the autofill field. 388 // Test that the popup is hidden once we are done editing the autofill field.
381 TEST_F(AutofillExternalDelegateUnitTest, 389 TEST_F(AutofillExternalDelegateUnitTest,
382 ExternalDelegateHidePopupAfterEditing) { 390 ExternalDelegateHidePopupAfterEditing) {
383 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); 391 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _));
384 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 392 autofill::GenerateTestAutofillPopup(external_delegate_.get());
385 393
386 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 394 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
387 external_delegate_->DidEndTextFieldEditing(); 395 external_delegate_->DidEndTextFieldEditing();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 492 EXPECT_CALL(manager_delegate_, HideAutofillPopup());
485 base::string16 dummy_string(ASCIIToUTF16("baz foo")); 493 base::string16 dummy_string(ASCIIToUTF16("baz foo"));
486 EXPECT_CALL(*autofill_driver_, 494 EXPECT_CALL(*autofill_driver_,
487 RendererShouldSetNodeText(dummy_string)); 495 RendererShouldSetNodeText(dummy_string));
488 external_delegate_->DidAcceptSuggestion( 496 external_delegate_->DidAcceptSuggestion(
489 dummy_string, 497 dummy_string,
490 WebAutofillClient::MenuItemIDAutocompleteEntry); 498 WebAutofillClient::MenuItemIDAutocompleteEntry);
491 } 499 }
492 500
493 } // namespace autofill 501 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698