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

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

Issue 2422363002: Trigger HTTP-bad warning when querying credit card autofill (Closed)
Patch Set: add missing blank line Created 4 years, 2 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 "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 const base::string16& prefix, 464 const base::string16& prefix,
465 const std::string& form_control_type)); 465 const std::string& form_control_type));
466 MOCK_METHOD1(OnWillSubmitForm, void(const FormData& form)); 466 MOCK_METHOD1(OnWillSubmitForm, void(const FormData& form));
467 467
468 private: 468 private:
469 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); 469 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager);
470 }; 470 };
471 471
472 class MockAutofillDriver : public TestAutofillDriver { 472 class MockAutofillDriver : public TestAutofillDriver {
473 public: 473 public:
474 MockAutofillDriver() : is_off_the_record_(false) {} 474 MockAutofillDriver()
475 : is_off_the_record_(false), did_interact_with_credit_card_form_(false) {}
475 476
476 // Mock methods to enable testability. 477 // Mock methods to enable testability.
477 MOCK_METHOD3(SendFormDataToRenderer, void(int query_id, 478 MOCK_METHOD3(SendFormDataToRenderer, void(int query_id,
478 RendererFormDataAction action, 479 RendererFormDataAction action,
479 const FormData& data)); 480 const FormData& data));
480 481
481 void SetIsOffTheRecord(bool is_off_the_record) { 482 void SetIsOffTheRecord(bool is_off_the_record) {
482 is_off_the_record_ = is_off_the_record; 483 is_off_the_record_ = is_off_the_record;
483 } 484 }
484 485
485 bool IsOffTheRecord() const override { return is_off_the_record_; } 486 bool IsOffTheRecord() const override { return is_off_the_record_; }
486 487
488 void DidInteractWithCreditCardForm() override {
489 did_interact_with_credit_card_form_ = true;
490 };
491
492 void ClearDidInteractWithCreditCardForm() {
493 did_interact_with_credit_card_form_ = false;
494 };
495
496 bool did_interact_with_credit_card_form() const {
497 return did_interact_with_credit_card_form_;
498 }
499
487 private: 500 private:
488 bool is_off_the_record_; 501 bool is_off_the_record_;
502 bool did_interact_with_credit_card_form_;
489 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 503 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
490 }; 504 };
491 505
492 class TestAutofillManager : public AutofillManager { 506 class TestAutofillManager : public AutofillManager {
493 public: 507 public:
494 TestAutofillManager(AutofillDriver* driver, 508 TestAutofillManager(AutofillDriver* driver,
495 AutofillClient* client, 509 AutofillClient* client,
496 TestPersonalDataManager* personal_data) 510 TestPersonalDataManager* personal_data)
497 : AutofillManager(driver, client, personal_data), 511 : AutofillManager(driver, client, personal_data),
498 personal_data_(personal_data), 512 personal_data_(personal_data),
(...skipping 4741 matching lines...) Expand 10 before | Expand all | Expand 10 after
5240 std::vector<FormData> mixed_forms(1, mixed_form); 5254 std::vector<FormData> mixed_forms(1, mixed_form);
5241 FormsSeen(mixed_forms); 5255 FormsSeen(mixed_forms);
5242 5256
5243 // Suggestions should always be displayed. 5257 // Suggestions should always be displayed.
5244 for (const FormFieldData& field : mixed_form.fields) { 5258 for (const FormFieldData& field : mixed_form.fields) {
5245 GetAutofillSuggestions(mixed_form, field); 5259 GetAutofillSuggestions(mixed_form, field);
5246 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 5260 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5247 } 5261 }
5248 } 5262 }
5249 5263
5264 // Tests that querying for credit card field suggestions notifies the
5265 // driver of an interaction with a credit card field.
5266 TEST_F(AutofillManagerTest, NotifyDriverOfCreditCardInteraction) {
5267 // Set up a credit card form.
5268 FormData form;
5269 form.name = ASCIIToUTF16("MyForm");
5270 form.origin = GURL("https://myform.com/form.html");
5271 form.action = GURL("https://myform.com/submit.html");
5272 FormFieldData field;
5273 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
5274 field.should_autocomplete = false;
5275 form.fields.push_back(field);
5276 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
5277 field.should_autocomplete = true;
5278 form.fields.push_back(field);
5279 test::CreateTestFormField("Expiration Month", "ccexpiresmonth", "", "text",
5280 &field);
5281 field.should_autocomplete = false;
5282 form.fields.push_back(field);
5283 form.fields.push_back(field);
5284 std::vector<FormData> forms(1, form);
5285 FormsSeen(forms);
5286 EXPECT_FALSE(autofill_driver_->did_interact_with_credit_card_form());
5287
5288 // The driver should always be notified.
5289 for (const FormFieldData& field : form.fields) {
5290 GetAutofillSuggestions(form, field);
5291 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5292 autofill_driver_->ClearDidInteractWithCreditCardForm();
5293 }
5294 }
5295
5250 } // namespace autofill 5296 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/test_autofill_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698