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

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

Issue 2676513007: Do not show Scan or Sign In options when credit card form is non-secure (Closed)
Patch Set: Add unit tests Created 3 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
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5343 matching lines...) Expand 10 before | Expand all | Expand 10 after
5354 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()) 5354 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo())
5355 .WillOnce(testing::Return(false)); 5355 .WillOnce(testing::Return(false));
5356 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field)); 5356 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
5357 5357
5358 // Number of impressions stay the same. 5358 // Number of impressions stay the same.
5359 EXPECT_EQ(kCreditCardSigninPromoImpressionLimit, 5359 EXPECT_EQ(kCreditCardSigninPromoImpressionLimit,
5360 autofill_client_.GetPrefs()->GetInteger( 5360 autofill_client_.GetPrefs()->GetInteger(
5361 prefs::kAutofillCreditCardSigninPromoImpressionCount)); 5361 prefs::kAutofillCreditCardSigninPromoImpressionCount));
5362 } 5362 }
5363 5363
5364 // Test that ShouldShowCreditCardSigninPromo behaves as expected for a credit
5365 // card form on a non-secure page.
5366 TEST_F(AutofillManagerTest,
5367 ShouldShowCreditCardSigninPromo_CreditCardField_NonSecureContext) {
5368 // Set up our form data.
5369 FormData form;
5370 CreateTestCreditCardFormData(&form, false, false);
5371 form.origin = GURL("http://myform.com/form.html");
5372 form.action = GURL("https://myform.com/submit.html");
5373 std::vector<FormData> forms(1, form);
5374 FormsSeen(forms);
5375
5376 FormFieldData field;
5377 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
5378
5379 // Both calls will now return false, regardless of the mock implementation of
5380 // ShouldShowSigninPromo().
5381 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo())
5382 .WillOnce(testing::Return(true));
5383 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
5384
5385 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo())
5386 .WillOnce(testing::Return(false));
5387 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
5388
5389 // Number of impressions should remain at zero.
5390 EXPECT_EQ(0, autofill_client_.GetPrefs()->GetInteger(
5391 prefs::kAutofillCreditCardSigninPromoImpressionCount));
5392 }
5393
5394 // Test that ShouldShowCreditCardSigninPromo behaves as expected for a credit
5395 // card form targeting a non-secure page.
5396 TEST_F(AutofillManagerTest,
5397 ShouldShowCreditCardSigninPromo_CreditCardField_NonSecureAction) {
5398 // Set up our form data.
5399 FormData form;
5400 CreateTestCreditCardFormData(&form, false, false);
5401 form.origin = GURL("https://myform.com/form.html");
5402 form.action = GURL("http://myform.com/submit.html");
5403 std::vector<FormData> forms(1, form);
5404 FormsSeen(forms);
5405
5406 FormFieldData field;
5407 test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field);
5408
5409 // Both calls will now return false, regardless of the mock implementation of
5410 // ShouldShowSigninPromo().
5411 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo())
5412 .WillOnce(testing::Return(true));
5413 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
5414
5415 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo())
5416 .WillOnce(testing::Return(false));
5417 EXPECT_FALSE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
5418
5419 // Number of impressions should remain at zero.
5420 EXPECT_EQ(0, autofill_client_.GetPrefs()->GetInteger(
5421 prefs::kAutofillCreditCardSigninPromoImpressionCount));
5422 }
5423
5364 // Test that ShouldShowCreditCardSigninPromo behaves as expected for an address 5424 // Test that ShouldShowCreditCardSigninPromo behaves as expected for an address
5365 // form. 5425 // form.
5366 TEST_F(AutofillManagerTest, ShouldShowCreditCardSigninPromo_AddressField) { 5426 TEST_F(AutofillManagerTest, ShouldShowCreditCardSigninPromo_AddressField) {
5367 // Set up our form data. 5427 // Set up our form data.
5368 FormData form; 5428 FormData form;
5369 test::CreateTestAddressFormData(&form); 5429 test::CreateTestAddressFormData(&form);
5370 std::vector<FormData> forms(1, form); 5430 std::vector<FormData> forms(1, form);
5371 FormsSeen(forms); 5431 FormsSeen(forms);
5372 5432
5373 FormFieldData field; 5433 FormFieldData field;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
5581 5641
5582 // The driver should always be notified. 5642 // The driver should always be notified.
5583 for (const FormFieldData& field : form.fields) { 5643 for (const FormFieldData& field : form.fields) {
5584 GetAutofillSuggestions(form, field); 5644 GetAutofillSuggestions(form, field);
5585 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5645 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5586 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5646 autofill_driver_->ClearDidInteractWithCreditCardForm();
5587 } 5647 }
5588 } 5648 }
5589 5649
5590 } // namespace autofill 5650 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698