Commit 995f8099 authored by Florian Uunk's avatar Florian Uunk Committed by Commit Bot

Make SaveCardBubble browsertest use the sync state

The browsertests used to rely on the save manager being hardcoded to
upload to Google if the observer_for_testing was set. This makes it
impossible to test that the logic for showing the upload prompt works
properly.

BUG=906630, 859761

Change-Id: Id7352a869388aac4ff36e1284750e22ac68c91b3
Reviewed-on: https://chromium-review.googlesource.com/c/1348335
Commit-Queue: Florian Uunk <feuunk@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610866}
parent a03d269c
......@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/ui/autofill/popup_constants.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h"
......@@ -39,6 +40,13 @@
using base::Bucket;
using testing::ElementsAre;
namespace {
const char kCreditCardUploadForm[] =
"/credit_card_upload_form_address_and_cc.html";
const char kCreditCardAndShippingUploadForm[] =
"/credit_card_upload_form_shipping_address.html";
} // namespace
namespace autofill {
class SaveCardBubbleViewsFullFormBrowserTest
......@@ -52,38 +60,6 @@ class SaveCardBubbleViewsFullFormBrowserTest
DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleViewsFullFormBrowserTest);
};
class SaveCardBubbleViewsFullFormWithShippingBrowserTest
: public SaveCardBubbleViewsBrowserTestBase {
protected:
SaveCardBubbleViewsFullFormWithShippingBrowserTest()
: SaveCardBubbleViewsBrowserTestBase(
"/credit_card_upload_form_shipping_address.html") {}
private:
DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleViewsFullFormWithShippingBrowserTest);
};
// Tests the local save bubble. Ensures that local save appears if the RPC to
// Google Payments fails unexpectedly.
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Local_SubmittingFormShowsBubbleIfGetUploadDetailsRpcFails) {
// Set up the Payments RPC.
SetUploadDetailsRpcServerError();
// Submitting the form and having the call to Payments fail should show the
// local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL)->visible());
}
// Tests the local save bubble. Ensures that clicking the [Save] button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
......@@ -92,16 +68,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -132,16 +102,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardImprovedUserConsent);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -166,16 +131,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -202,20 +161,20 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
#endif
// Tests the sign in promo bubble. Ensures that the sign-in promo
// is not shown when the user is signed-in and syncing, even if
// the local save bubble is shown.
// is not shown when the user is signed-in and syncing, even if the local save
// bubble is shown.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_NoSigninPromoShowsWhenUserIsSyncing) {
// Enable the sign-in promo.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
......@@ -223,6 +182,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -249,16 +209,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -290,16 +244,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -337,16 +285,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -390,16 +332,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -457,16 +393,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -516,16 +446,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -565,16 +489,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -619,17 +537,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Disable the updated UI.
scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardImprovedUserConsent);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -645,16 +556,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// https://crbug.com/842577 .
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_SynchronousCloseAfterAsynchronousClose) {
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form without signed in user should show the local save
// bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
......@@ -683,6 +588,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// to Google Payments.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingSaveClosesBubble) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -691,6 +599,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -716,6 +625,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardImprovedUserConsent);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -724,6 +636,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -748,6 +661,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardImprovedUserConsent);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -756,6 +672,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -770,6 +687,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// button successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingCloseClosesBubble) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -778,6 +698,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -792,6 +713,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// cardholder name textfield if it is not needed.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ShouldNotRequestCardholderNameInHappyPath) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
......@@ -804,6 +728,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -823,6 +748,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -832,6 +760,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -843,16 +772,20 @@ IN_PROC_BROWSER_TEST_F(
// Tests the upload save bubble. Ensures that the bubble surfaces a textfield
// requesting cardholder name if cardholder name is conflicting.
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormWithShippingBrowserTest,
SaveCardBubbleViewsFullFormBrowserTest,
Upload_SubmittingFormWithConflictingNamesRequestsCardholderNameIfExpOn) {
// Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Submit first shipping address form with a conflicting name.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingName();
// Submitting the second form should still show the upload save bubble and
......@@ -862,6 +795,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_UPLOAD)->visible());
......@@ -874,6 +808,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_SaveButtonIsDisabledIfNoCardholderNameAndCardholderNameRequested) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
......@@ -887,6 +824,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -915,6 +853,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_EnteringCardholderNameAndClickingSaveClosesBubbleIfCardholderNameRequested) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
......@@ -928,6 +869,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -963,12 +905,14 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.)
......@@ -976,6 +920,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
......@@ -1003,6 +948,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1016,6 +964,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
......@@ -1041,18 +990,21 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
......@@ -1076,18 +1028,21 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
......@@ -1120,12 +1075,14 @@ IN_PROC_BROWSER_TEST_F(
// Disabled
{});
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.)
......@@ -1133,6 +1090,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
......@@ -1154,11 +1112,62 @@ IN_PROC_BROWSER_TEST_F(
// gfx::Range of the link. When/if that can be worked around,
// create an Upload_ClickingTosLinkClosesBubble test.
// Tests the upload save logic. Ensures that Chrome offers a local save when the
// data is complete, even if Payments rejects the data.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldOfferLocalSaveIfPaymentsDeclines) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL)->visible());
}
// Tests the upload save logic. Ensures that Chrome offers a local save when the
// data is complete, even if the Payments upload fails unexpectedly.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldOfferLocalSaveIfPaymentsFails) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcServerError();
// Submitting the form and having the call to Payments fail should show the
// local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL)->visible());
}
// Tests the upload save logic. Ensures that Chrome delegates the offer-to-save
// call to Payments, and offers to upload save the card if Payments allows it.
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Logic_CanOfferToSaveEvenIfNothingFoundIfPaymentsAccepts) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1169,6 +1178,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithCardDetailsOnly();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1182,6 +1192,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldNotOfferToSaveIfNothingFoundAndPaymentsDeclines) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
......@@ -1192,6 +1205,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithCardDetailsOnly();
WaitForObservedEvent();
EXPECT_FALSE(GetSaveCardBubbleViews());
......@@ -1201,9 +1215,13 @@ IN_PROC_BROWSER_TEST_F(
// upload save should be offered, even if CVC is not detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfCvcNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if
// Chrome should offer to save the card to Google, even though CVC is missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutCvc();
WaitForObservedEvent();
}
......@@ -1212,10 +1230,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// upload save should be offered, even if the detected CVC is invalid.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfInvalidCvcFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if
// Chrome should offer to save the card to Google, even though the provided
// CVC is invalid.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithInvalidCvc();
WaitForObservedEvent();
}
......@@ -1225,10 +1247,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfNameNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if
// Chrome should offer to save the card to Google, even though name is
// missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName();
WaitForObservedEvent();
}
......@@ -1236,9 +1262,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Tests the upload save logic. Ensures that Chrome lets Payments decide whether
// upload save should be offered, even if multiple conflicting names are
// detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfNamesConflict) {
// Start sync.
harness_->SetupSync();
// Submit first shipping address form with a conflicting name.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingName();
// Submitting the form should still start the flow of asking Payments if
......@@ -1253,10 +1283,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
// upload save should be offered, even if billing address is not detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfAddressNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if
// Chrome should offer to save the card to Google, even though billing address
// is missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutAddress();
WaitForObservedEvent();
}
......@@ -1264,9 +1298,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Tests the upload save logic. Ensures that Chrome lets Payments decide whether
// upload save should be offered, even if multiple conflicting billing address
// postal codes are detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfPostalCodesConflict) {
// Start sync.
harness_->SetupSync();
// Submit first shipping address form with a conflicting postal code.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingPostalCode();
// Submitting the form should still start the flow of asking Payments if
......@@ -1282,6 +1320,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1291,6 +1332,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1316,6 +1358,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1326,6 +1371,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1348,6 +1394,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1358,6 +1407,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithExpiredExpirationDate();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1382,6 +1432,7 @@ IN_PROC_BROWSER_TEST_F(
// The credit card will not be imported if the expiration date is expired and
// experiment is off.
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithExpiredExpirationDate();
EXPECT_FALSE(GetSaveCardBubbleViews());
}
......@@ -1397,6 +1448,7 @@ IN_PROC_BROWSER_TEST_F(
// The credit card will not be imported if there is no expiration date and
// experiment is off.
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate();
EXPECT_FALSE(GetSaveCardBubbleViews());
}
......@@ -1409,6 +1461,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1417,6 +1472,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1440,6 +1496,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1450,6 +1509,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent();
EXPECT_TRUE(
......@@ -1499,6 +1559,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -1509,6 +1572,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent();
EXPECT_TRUE(
......
......@@ -10,11 +10,10 @@
#include <utility>
#include "base/bind.h"
#include "chrome/browser/signin/account_fetcher_service_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_account_fetcher_service_builder.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h"
......@@ -30,14 +29,19 @@
#include "components/autofill/core/browser/credit_card_save_manager.h"
#include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/payments/payments_client.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_account_fetcher_service.h"
#include "components/sync/test/fake_server/fake_server.h"
#include "components/sync/test/fake_server/fake_server_network_resources.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h"
......@@ -71,21 +75,38 @@ const double kFakeGeolocationLongitude = 4.56;
SaveCardBubbleViewsBrowserTestBase::SaveCardBubbleViewsBrowserTestBase(
const std::string& test_file_path)
: test_file_path_(test_file_path) {}
: SyncTest(SINGLE_CLIENT), test_file_path_(test_file_path) {}
SaveCardBubbleViewsBrowserTestBase::~SaveCardBubbleViewsBrowserTestBase() {}
void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() {
SyncTest::SetUpOnMainThread();
// Set up the HTTPS server (uses the embedded_test_server).
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
embedded_test_server()->ServeFilesFromSourceDirectory(
"components/test/data/autofill");
embedded_test_server()->StartAcceptingConnections();
// Set up the URL fetcher. By providing an Impl, unexpected calls (sync, etc.)
// won't cause the test to crash.
url_fetcher_factory_ = std::make_unique<net::FakeURLFetcherFactory>(
new net::URLFetcherImplFactory());
ProfileSyncServiceFactory::GetForProfile(browser()->profile())
->OverrideNetworkResourcesForTest(
std::make_unique<fake_server::FakeServerNetworkResources>(
GetFakeServer()->AsWeakPtr()));
std::string username;
#if defined(OS_CHROMEOS)
// In ChromeOS browser tests, the profile may already by authenticated with
// stub account |user_manager::kStubUserEmail|.
AccountInfo info = IdentityManagerFactory::GetForProfile(browser()->profile())
->GetPrimaryAccountInfo();
username = info.email;
#endif
if (username.empty())
username = "user@gmail.com";
harness_ = ProfileSyncServiceHarness::Create(
browser()->profile(), username, "password",
ProfileSyncServiceHarness::SigninType::FAKE_SIGNIN);
// Set up the URL loader factory for the payments client so we can intercept
// those network requests too.
......@@ -112,8 +133,6 @@ void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() {
// Set up the fake geolocation data.
geolocation_overrider_ = std::make_unique<device::ScopedGeolocationOverrider>(
kFakeGeolocationLatitude, kFakeGeolocationLongitude);
NavigateTo(test_file_path_);
}
void SaveCardBubbleViewsBrowserTestBase::NavigateTo(
......@@ -171,54 +190,13 @@ void SaveCardBubbleViewsBrowserTestBase::OnSCBCStrikeChangeComplete() {
event_waiter_->OnEvent(DialogEvent::STRIKE_CHANGE_COMPLETE);
}
void SaveCardBubbleViewsBrowserTestBase::SetUpInProcessBrowserTestFixture() {
will_create_browser_context_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterWillCreateBrowserContextServicesCallbackForTesting(
base::BindRepeating(&SaveCardBubbleViewsBrowserTestBase::
OnWillCreateBrowserContextServices,
base::Unretained(this)));
}
void SaveCardBubbleViewsBrowserTestBase::OnWillCreateBrowserContextServices(
content::BrowserContext* context) {
// Replace the signin manager and account fetcher service with fakes.
SigninManagerFactory::GetInstance()->SetTestingFactory(
context, base::BindRepeating(&BuildFakeSigninManagerForTesting));
AccountFetcherServiceFactory::GetInstance()->SetTestingFactory(
context,
base::BindRepeating(&FakeAccountFetcherServiceBuilder::BuildForTests));
}
void SaveCardBubbleViewsBrowserTestBase::SignInWithFullName(
void SaveCardBubbleViewsBrowserTestBase::SetAccountFullName(
const std::string& full_name) {
// TODO(crbug.com/859761): Can this function be used to remove the
// observer_for_testing_ hack in
// CreditCardSaveManager::IsCreditCardUploadEnabled()?
FakeSigninManagerForTesting* signin_manager =
static_cast<FakeSigninManagerForTesting*>(
SigninManagerFactory::GetInstance()->GetForProfile(
browser()->profile()));
// Note: Chrome OS tests seem to rely on these specific login values, so
// changing them is probably not recommended.
constexpr char kTestEmail[] = "stub-user@example.com";
constexpr char kTestGaiaId[] = "stub-user@example.com";
#if !defined(OS_CHROMEOS)
signin_manager->SignIn(kTestGaiaId, kTestEmail, "password");
#else
AccountTrackerService* account_tracker_service =
AccountTrackerServiceFactory::GetForProfile(browser()->profile());
signin_manager->SignIn(account_tracker_service->PickAccountIdForAccount(
kTestGaiaId, kTestEmail));
#endif
FakeAccountFetcherService* account_fetcher_service =
static_cast<FakeAccountFetcherService*>(
AccountFetcherServiceFactory::GetForProfile(browser()->profile()));
account_fetcher_service->FakeUserInfoFetchSuccess(
signin_manager->GetAuthenticatedAccountId(), kTestEmail, kTestGaiaId,
AccountTrackerService::kNoHostedDomainFound, full_name,
/*given_name=*/std::string(), "locale", "avatar.jpg");
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(browser()->profile());
AccountInfo info = identity_manager->GetPrimaryAccountInfo();
info.full_name = full_name;
identity::UpdateAccountInfoForAccount(identity_manager, info);
}
void SaveCardBubbleViewsBrowserTestBase::SubmitForm() {
......
......@@ -13,6 +13,7 @@
#include "base/command_line.h"
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/views/autofill/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
......@@ -37,7 +38,7 @@ namespace autofill {
// Base class for any interactive SaveCardBubbleViews browser test that will
// need to show and interact with the offer-to-save bubble.
class SaveCardBubbleViewsBrowserTestBase
: public InProcessBrowserTest,
: public SyncTest,
public CreditCardSaveManager::ObserverForTest,
public SaveCardBubbleControllerImpl::ObserverForTest {
public:
......@@ -77,14 +78,8 @@ class SaveCardBubbleViewsBrowserTestBase
void OnBubbleClosed() override;
void OnSCBCStrikeChangeComplete() override;
// BrowserTestBase:
void SetUpInProcessBrowserTestFixture() override;
// Sets up the ability to sign in the user.
void OnWillCreateBrowserContextServices(content::BrowserContext* context);
// Signs in the user with the provided |full_name|.
void SignInWithFullName(const std::string& full_name);
// Sets the full name of the signed-in account to the provided |full_name|.
void SetAccountFullName(const std::string& full_name);
// Will call JavaScript to fill and submit the form in different ways.
void SubmitForm();
......@@ -163,6 +158,8 @@ class SaveCardBubbleViewsBrowserTestBase
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<ProfileSyncServiceHarness> harness_;
private:
std::unique_ptr<autofill::EventWaiter<DialogEvent>> event_waiter_;
std::unique_ptr<net::FakeURLFetcherFactory> url_fetcher_factory_;
......
......@@ -100,10 +100,13 @@ bool IsCreditCardUploadEnabled(const PrefService* pref_service,
// If the "allow all email domains" flag is off, restrict credit card upload
// only to Google Accounts with @googlemail, @gmail, @google, or @chromium
// domains.
// example.com is on the list because ChromeOS tests rely on using this. That
// should be fine, since example.com is an IANA reserved domain.
if (!base::FeatureList::IsEnabled(
features::kAutofillUpstreamAllowAllEmailDomains) &&
!(domain == "googlemail.com" || domain == "gmail.com" ||
domain == "google.com" || domain == "chromium.org")) {
domain == "google.com" || domain == "chromium.org" ||
domain == "example.com")) {
return false;
}
......
......@@ -251,10 +251,14 @@ void CreditCardSaveManager::AttemptToOfferCardUploadSave(
}
bool CreditCardSaveManager::IsCreditCardUploadEnabled() {
#if defined(OS_IOS)
// If observer_for_testing_ is set, assume we are in a browsertest and
// credit card upload should be enabled by default.
return observer_for_testing_ ||
::autofill::IsCreditCardUploadEnabled(
// TODO(crbug.com/859761): Remove dependency from iOS tests on this behavior.
if (observer_for_testing_)
return true;
#endif // defined(OS_IOS)
return ::autofill::IsCreditCardUploadEnabled(
client_->GetPrefs(), client_->GetSyncService(),
personal_data_manager_->GetAccountInfoForPaymentsServer().email);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment