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 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_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/popup_constants.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -39,6 +40,13 @@ ...@@ -39,6 +40,13 @@
using base::Bucket; using base::Bucket;
using testing::ElementsAre; 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 { namespace autofill {
class SaveCardBubbleViewsFullFormBrowserTest class SaveCardBubbleViewsFullFormBrowserTest
...@@ -52,38 +60,6 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -52,38 +60,6 @@ class SaveCardBubbleViewsFullFormBrowserTest
DISALLOW_COPY_AND_ASSIGN(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 // Tests the local save bubble. Ensures that clicking the [Save] button
// successfully causes the bubble to go away. // successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
...@@ -92,16 +68,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -92,16 +68,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndDisableFeature( scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -132,16 +102,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -132,16 +102,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardImprovedUserConsent); features::kAutofillSaveCardImprovedUserConsent);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should // Submitting the form and having Payments decline offering to save should
// show the local save bubble. // show the local save bubble.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
{DialogEvent::REQUESTED_UPLOAD_SAVE, NavigateTo(kCreditCardUploadForm);
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -166,16 +131,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -166,16 +131,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -202,20 +161,20 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -202,20 +161,20 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
#endif #endif
// Tests the sign in promo bubble. Ensures that the sign-in promo // 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 // is not shown when the user is signed-in and syncing, even if the local save
// the local save bubble is shown. // bubble is shown.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_NoSigninPromoShowsWhenUserIsSyncing) { Local_NoSigninPromoShowsWhenUserIsSyncing) {
// Enable the sign-in promo. // Enable the sign-in promo.
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines(); SetUploadDetailsRpcPaymentsDeclines();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form and having Payments decline offering to save should // Submitting the form and having Payments decline offering to save should
// show the local save bubble. // show the local save bubble.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
...@@ -223,6 +182,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -223,6 +182,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE, DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE}); DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -249,16 +209,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -249,16 +209,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -290,16 +244,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -290,16 +244,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -337,16 +285,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -337,16 +285,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -390,16 +332,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -390,16 +332,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -457,16 +393,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -457,16 +393,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -516,16 +446,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -516,16 +446,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -565,16 +489,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -565,16 +489,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardSignInAfterLocalSave); features::kAutofillSaveCardSignInAfterLocalSave);
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -619,17 +537,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -619,17 +537,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Disable the updated UI. // Disable the updated UI.
scoped_feature_list_.InitAndDisableFeature( scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardImprovedUserConsent); features::kAutofillSaveCardImprovedUserConsent);
// Submitting the form without signed in user should show the local save
// Set up the Payments RPC. // bubble.
SetUploadDetailsRpcPaymentsDeclines(); ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
NavigateTo(kCreditCardUploadForm);
// 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});
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -645,16 +556,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -645,16 +556,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// https://crbug.com/842577 . // https://crbug.com/842577 .
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_SynchronousCloseAfterAsynchronousClose) { Local_SynchronousCloseAfterAsynchronousClose) {
// Set up the Payments RPC. // Submitting the form without signed in user should show the local save
SetUploadDetailsRpcPaymentsDeclines(); // bubble.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE});
// Submitting the form and having Payments decline offering to save should NavigateTo(kCreditCardUploadForm);
// 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(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -683,6 +588,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -683,6 +588,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// to Google Payments. // to Google Payments.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingSaveClosesBubble) { Upload_ClickingSaveClosesBubble) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -691,6 +599,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -691,6 +599,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -716,6 +625,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -716,6 +625,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillSaveCardImprovedUserConsent); features::kAutofillSaveCardImprovedUserConsent);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -724,6 +636,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -724,6 +636,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -748,6 +661,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -748,6 +661,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndDisableFeature( scoped_feature_list_.InitAndDisableFeature(
features::kAutofillSaveCardImprovedUserConsent); features::kAutofillSaveCardImprovedUserConsent);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -756,6 +672,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -756,6 +672,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -770,6 +687,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -770,6 +687,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// button successfully causes the bubble to go away. // button successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingCloseClosesBubble) { Upload_ClickingCloseClosesBubble) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -778,6 +698,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -778,6 +698,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -792,6 +713,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -792,6 +713,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// cardholder name textfield if it is not needed. // cardholder name textfield if it is not needed.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ShouldNotRequestCardholderNameInHappyPath) { Upload_ShouldNotRequestCardholderNameInHappyPath) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment. // Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
...@@ -804,6 +728,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -804,6 +728,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -823,6 +748,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -823,6 +748,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -832,6 +760,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -832,6 +760,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -843,16 +772,20 @@ IN_PROC_BROWSER_TEST_F( ...@@ -843,16 +772,20 @@ IN_PROC_BROWSER_TEST_F(
// Tests the upload save bubble. Ensures that the bubble surfaces a textfield // Tests the upload save bubble. Ensures that the bubble surfaces a textfield
// requesting cardholder name if cardholder name is conflicting. // requesting cardholder name if cardholder name is conflicting.
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormWithShippingBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Upload_SubmittingFormWithConflictingNamesRequestsCardholderNameIfExpOn) { Upload_SubmittingFormWithConflictingNamesRequestsCardholderNameIfExpOn) {
// Enable the EditableCardholderName experiment. // Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
// Submit first shipping address form with a conflicting name. // Submit first shipping address form with a conflicting name.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingName(); FillAndSubmitFormWithConflictingName();
// Submitting the second form should still show the upload save bubble and // Submitting the second form should still show the upload save bubble and
...@@ -862,6 +795,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -862,6 +795,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_UPLOAD)->visible()); FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_UPLOAD)->visible());
...@@ -874,6 +808,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -874,6 +808,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Upload_SaveButtonIsDisabledIfNoCardholderNameAndCardholderNameRequested) { Upload_SaveButtonIsDisabledIfNoCardholderNameAndCardholderNameRequested) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment. // Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
...@@ -887,6 +824,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -887,6 +824,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -915,6 +853,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -915,6 +853,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Upload_EnteringCardholderNameAndClickingSaveClosesBubbleIfCardholderNameRequested) { Upload_EnteringCardholderNameAndClickingSaveClosesBubbleIfCardholderNameRequested) {
// Start sync.
harness_->SetupSync();
// Enable the EditableCardholderName experiment. // Enable the EditableCardholderName experiment.
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
...@@ -928,6 +869,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -928,6 +869,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -963,12 +905,14 @@ IN_PROC_BROWSER_TEST_F( ...@@ -963,12 +905,14 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a // Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name. // textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
...@@ -976,6 +920,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -976,6 +920,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD)); EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
...@@ -1003,6 +948,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1003,6 +948,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1016,6 +964,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1016,6 +964,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD)); EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
...@@ -1041,18 +990,21 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1041,18 +990,21 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a // Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name. // textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD)); EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
...@@ -1076,18 +1028,21 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1076,18 +1028,21 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableCardholderName); features::kAutofillUpstreamEditableCardholderName);
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a // Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name. // textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD)); EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
...@@ -1120,12 +1075,14 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1120,12 +1075,14 @@ IN_PROC_BROWSER_TEST_F(
// Disabled // Disabled
{}); {});
// Start sync.
harness_->SetupSync();
// Set the user's full name.
SetAccountFullName("John Smith");
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
// Sign the user in.
SignInWithFullName("John Smith");
// Submitting the form should show the upload save bubble, along with a // Submitting the form should show the upload save bubble, along with a
// textfield specifically requesting the cardholder name. // textfield specifically requesting the cardholder name.
// (Must wait for response from Payments before accessing the controller.) // (Must wait for response from Payments before accessing the controller.)
...@@ -1133,6 +1090,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1133,6 +1090,7 @@ IN_PROC_BROWSER_TEST_F(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD)); EXPECT_TRUE(FindViewInBubbleById(DialogViewId::CARDHOLDER_NAME_TEXTFIELD));
...@@ -1154,11 +1112,62 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1154,11 +1112,62 @@ IN_PROC_BROWSER_TEST_F(
// gfx::Range of the link. When/if that can be worked around, // gfx::Range of the link. When/if that can be worked around,
// create an Upload_ClickingTosLinkClosesBubble test. // 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 // 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. // call to Payments, and offers to upload save the card if Payments allows it.
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Logic_CanOfferToSaveEvenIfNothingFoundIfPaymentsAccepts) { Logic_CanOfferToSaveEvenIfNothingFoundIfPaymentsAccepts) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1169,6 +1178,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1169,6 +1178,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithCardDetailsOnly(); FillAndSubmitFormWithCardDetailsOnly();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1182,6 +1192,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1182,6 +1192,9 @@ IN_PROC_BROWSER_TEST_F(
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldNotOfferToSaveIfNothingFoundAndPaymentsDeclines) { Logic_ShouldNotOfferToSaveIfNothingFoundAndPaymentsDeclines) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines(); SetUploadDetailsRpcPaymentsDeclines();
...@@ -1192,6 +1205,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1192,6 +1205,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithCardDetailsOnly(); FillAndSubmitFormWithCardDetailsOnly();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_FALSE(GetSaveCardBubbleViews()); EXPECT_FALSE(GetSaveCardBubbleViews());
...@@ -1201,9 +1215,13 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1201,9 +1215,13 @@ IN_PROC_BROWSER_TEST_F(
// upload save should be offered, even if CVC is not detected. // upload save should be offered, even if CVC is not detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfCvcNotFound) { Logic_ShouldAttemptToOfferToSaveIfCvcNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if // 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. // Chrome should offer to save the card to Google, even though CVC is missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE}); ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutCvc(); FillAndSubmitFormWithoutCvc();
WaitForObservedEvent(); WaitForObservedEvent();
} }
...@@ -1212,10 +1230,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1212,10 +1230,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// upload save should be offered, even if the detected CVC is invalid. // upload save should be offered, even if the detected CVC is invalid.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfInvalidCvcFound) { Logic_ShouldAttemptToOfferToSaveIfInvalidCvcFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if // 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 // Chrome should offer to save the card to Google, even though the provided
// CVC is invalid. // CVC is invalid.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE}); ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithInvalidCvc(); FillAndSubmitFormWithInvalidCvc();
WaitForObservedEvent(); WaitForObservedEvent();
} }
...@@ -1225,10 +1247,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1225,10 +1247,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// detected. // detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfNameNotFound) { Logic_ShouldAttemptToOfferToSaveIfNameNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if // 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 // Chrome should offer to save the card to Google, even though name is
// missing. // missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE}); ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutName(); FillAndSubmitFormWithoutName();
WaitForObservedEvent(); WaitForObservedEvent();
} }
...@@ -1236,9 +1262,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1236,9 +1262,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Tests the upload save logic. Ensures that Chrome lets Payments decide whether // Tests the upload save logic. Ensures that Chrome lets Payments decide whether
// upload save should be offered, even if multiple conflicting names are // upload save should be offered, even if multiple conflicting names are
// detected. // detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfNamesConflict) { Logic_ShouldAttemptToOfferToSaveIfNamesConflict) {
// Start sync.
harness_->SetupSync();
// Submit first shipping address form with a conflicting name. // Submit first shipping address form with a conflicting name.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingName(); FillAndSubmitFormWithConflictingName();
// Submitting the form should still start the flow of asking Payments if // Submitting the form should still start the flow of asking Payments if
...@@ -1253,10 +1283,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest, ...@@ -1253,10 +1283,14 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
// upload save should be offered, even if billing address is not detected. // upload save should be offered, even if billing address is not detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfAddressNotFound) { Logic_ShouldAttemptToOfferToSaveIfAddressNotFound) {
// Start sync.
harness_->SetupSync();
// Submitting the form should still start the flow of asking Payments if // 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 // Chrome should offer to save the card to Google, even though billing address
// is missing. // is missing.
ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE}); ResetEventWaiterForSequence({DialogEvent::REQUESTED_UPLOAD_SAVE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutAddress(); FillAndSubmitFormWithoutAddress();
WaitForObservedEvent(); WaitForObservedEvent();
} }
...@@ -1264,9 +1298,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1264,9 +1298,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Tests the upload save logic. Ensures that Chrome lets Payments decide whether // Tests the upload save logic. Ensures that Chrome lets Payments decide whether
// upload save should be offered, even if multiple conflicting billing address // upload save should be offered, even if multiple conflicting billing address
// postal codes are detected. // postal codes are detected.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Logic_ShouldAttemptToOfferToSaveIfPostalCodesConflict) { Logic_ShouldAttemptToOfferToSaveIfPostalCodesConflict) {
// Start sync.
harness_->SetupSync();
// Submit first shipping address form with a conflicting postal code. // Submit first shipping address form with a conflicting postal code.
NavigateTo(kCreditCardAndShippingUploadForm);
FillAndSubmitFormWithConflictingPostalCode(); FillAndSubmitFormWithConflictingPostalCode();
// Submitting the form should still start the flow of asking Payments if // Submitting the form should still start the flow of asking Payments if
...@@ -1282,6 +1320,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest, ...@@ -1282,6 +1320,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest, SaveCardBubbleViewsFullFormBrowserTest,
Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA) { Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA) {
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1291,6 +1332,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1291,6 +1332,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1316,6 +1358,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1316,6 +1358,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate); features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1326,6 +1371,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1326,6 +1371,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate(); FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1348,6 +1394,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1348,6 +1394,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate); features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1358,6 +1407,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1358,6 +1407,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithExpiredExpirationDate(); FillAndSubmitFormWithExpiredExpirationDate();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1382,6 +1432,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1382,6 +1432,7 @@ IN_PROC_BROWSER_TEST_F(
// The credit card will not be imported if the expiration date is expired and // The credit card will not be imported if the expiration date is expired and
// experiment is off. // experiment is off.
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithExpiredExpirationDate(); FillAndSubmitFormWithExpiredExpirationDate();
EXPECT_FALSE(GetSaveCardBubbleViews()); EXPECT_FALSE(GetSaveCardBubbleViews());
} }
...@@ -1397,6 +1448,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1397,6 +1448,7 @@ IN_PROC_BROWSER_TEST_F(
// The credit card will not be imported if there is no expiration date and // The credit card will not be imported if there is no expiration date and
// experiment is off. // experiment is off.
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate(); FillAndSubmitFormWithoutExpirationDate();
EXPECT_FALSE(GetSaveCardBubbleViews()); EXPECT_FALSE(GetSaveCardBubbleViews());
} }
...@@ -1409,6 +1461,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1409,6 +1461,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate); features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1417,6 +1472,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1417,6 +1472,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitForm(); FillAndSubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1440,6 +1496,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1440,6 +1496,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate); features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1450,6 +1509,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1450,6 +1509,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate(); FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
...@@ -1499,6 +1559,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1499,6 +1559,9 @@ IN_PROC_BROWSER_TEST_F(
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate); features::kAutofillUpstreamEditableExpirationDate);
// Start sync.
harness_->SetupSync();
// Set up the Payments RPC. // Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
...@@ -1509,6 +1572,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1509,6 +1572,7 @@ IN_PROC_BROWSER_TEST_F(
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
NavigateTo(kCreditCardUploadForm);
FillAndSubmitFormWithoutExpirationDate(); FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE( EXPECT_TRUE(
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/signin/account_fetcher_service_factory.h" #include "chrome/browser/signin/identity_manager_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/signin_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/chrome_autofill_client.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -30,14 +29,19 @@ ...@@ -30,14 +29,19 @@
#include "components/autofill/core/browser/credit_card_save_manager.h" #include "components/autofill/core/browser/credit_card_save_manager.h"
#include "components/autofill/core/browser/form_data_importer.h" #include "components/autofill/core/browser/form_data_importer.h"
#include "components/autofill/core/browser/payments/payments_client.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/keyed_service/content/browser_context_dependency_manager.h"
#include "components/network_session_configurator/common/network_switches.h" #include "components/network_session_configurator/common/network_switches.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_account_fetcher_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/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.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/events/base_event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -71,21 +75,38 @@ const double kFakeGeolocationLongitude = 4.56; ...@@ -71,21 +75,38 @@ const double kFakeGeolocationLongitude = 4.56;
SaveCardBubbleViewsBrowserTestBase::SaveCardBubbleViewsBrowserTestBase( SaveCardBubbleViewsBrowserTestBase::SaveCardBubbleViewsBrowserTestBase(
const std::string& test_file_path) const std::string& test_file_path)
: test_file_path_(test_file_path) {} : SyncTest(SINGLE_CLIENT), test_file_path_(test_file_path) {}
SaveCardBubbleViewsBrowserTestBase::~SaveCardBubbleViewsBrowserTestBase() {} SaveCardBubbleViewsBrowserTestBase::~SaveCardBubbleViewsBrowserTestBase() {}
void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() { void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() {
SyncTest::SetUpOnMainThread();
// Set up the HTTPS server (uses the embedded_test_server). // Set up the HTTPS server (uses the embedded_test_server).
ASSERT_TRUE(embedded_test_server()->InitializeAndListen()); ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
embedded_test_server()->ServeFilesFromSourceDirectory( embedded_test_server()->ServeFilesFromSourceDirectory(
"components/test/data/autofill"); "components/test/data/autofill");
embedded_test_server()->StartAcceptingConnections(); embedded_test_server()->StartAcceptingConnections();
// Set up the URL fetcher. By providing an Impl, unexpected calls (sync, etc.) ProfileSyncServiceFactory::GetForProfile(browser()->profile())
// won't cause the test to crash. ->OverrideNetworkResourcesForTest(
url_fetcher_factory_ = std::make_unique<net::FakeURLFetcherFactory>( std::make_unique<fake_server::FakeServerNetworkResources>(
new net::URLFetcherImplFactory()); 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 // Set up the URL loader factory for the payments client so we can intercept
// those network requests too. // those network requests too.
...@@ -112,8 +133,6 @@ void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() { ...@@ -112,8 +133,6 @@ void SaveCardBubbleViewsBrowserTestBase::SetUpOnMainThread() {
// Set up the fake geolocation data. // Set up the fake geolocation data.
geolocation_overrider_ = std::make_unique<device::ScopedGeolocationOverrider>( geolocation_overrider_ = std::make_unique<device::ScopedGeolocationOverrider>(
kFakeGeolocationLatitude, kFakeGeolocationLongitude); kFakeGeolocationLatitude, kFakeGeolocationLongitude);
NavigateTo(test_file_path_);
} }
void SaveCardBubbleViewsBrowserTestBase::NavigateTo( void SaveCardBubbleViewsBrowserTestBase::NavigateTo(
...@@ -171,54 +190,13 @@ void SaveCardBubbleViewsBrowserTestBase::OnSCBCStrikeChangeComplete() { ...@@ -171,54 +190,13 @@ void SaveCardBubbleViewsBrowserTestBase::OnSCBCStrikeChangeComplete() {
event_waiter_->OnEvent(DialogEvent::STRIKE_CHANGE_COMPLETE); event_waiter_->OnEvent(DialogEvent::STRIKE_CHANGE_COMPLETE);
} }
void SaveCardBubbleViewsBrowserTestBase::SetUpInProcessBrowserTestFixture() { void SaveCardBubbleViewsBrowserTestBase::SetAccountFullName(
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(
const std::string& full_name) { const std::string& full_name) {
// TODO(crbug.com/859761): Can this function be used to remove the identity::IdentityManager* identity_manager =
// observer_for_testing_ hack in IdentityManagerFactory::GetForProfile(browser()->profile());
// CreditCardSaveManager::IsCreditCardUploadEnabled()? AccountInfo info = identity_manager->GetPrimaryAccountInfo();
FakeSigninManagerForTesting* signin_manager = info.full_name = full_name;
static_cast<FakeSigninManagerForTesting*>( identity::UpdateAccountInfoForAccount(identity_manager, info);
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");
} }
void SaveCardBubbleViewsBrowserTestBase::SubmitForm() { void SaveCardBubbleViewsBrowserTestBase::SubmitForm() {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/scoped_feature_list.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/autofill/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/views/autofill/dialog_view_ids.h" #include "chrome/browser/ui/views/autofill/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
...@@ -37,7 +38,7 @@ namespace autofill { ...@@ -37,7 +38,7 @@ namespace autofill {
// Base class for any interactive SaveCardBubbleViews browser test that will // Base class for any interactive SaveCardBubbleViews browser test that will
// need to show and interact with the offer-to-save bubble. // need to show and interact with the offer-to-save bubble.
class SaveCardBubbleViewsBrowserTestBase class SaveCardBubbleViewsBrowserTestBase
: public InProcessBrowserTest, : public SyncTest,
public CreditCardSaveManager::ObserverForTest, public CreditCardSaveManager::ObserverForTest,
public SaveCardBubbleControllerImpl::ObserverForTest { public SaveCardBubbleControllerImpl::ObserverForTest {
public: public:
...@@ -77,14 +78,8 @@ class SaveCardBubbleViewsBrowserTestBase ...@@ -77,14 +78,8 @@ class SaveCardBubbleViewsBrowserTestBase
void OnBubbleClosed() override; void OnBubbleClosed() override;
void OnSCBCStrikeChangeComplete() override; void OnSCBCStrikeChangeComplete() override;
// BrowserTestBase: // Sets the full name of the signed-in account to the provided |full_name|.
void SetUpInProcessBrowserTestFixture() override; void SetAccountFullName(const std::string& full_name);
// 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);
// Will call JavaScript to fill and submit the form in different ways. // Will call JavaScript to fill and submit the form in different ways.
void SubmitForm(); void SubmitForm();
...@@ -163,6 +158,8 @@ class SaveCardBubbleViewsBrowserTestBase ...@@ -163,6 +158,8 @@ class SaveCardBubbleViewsBrowserTestBase
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<ProfileSyncServiceHarness> harness_;
private: private:
std::unique_ptr<autofill::EventWaiter<DialogEvent>> event_waiter_; std::unique_ptr<autofill::EventWaiter<DialogEvent>> event_waiter_;
std::unique_ptr<net::FakeURLFetcherFactory> url_fetcher_factory_; std::unique_ptr<net::FakeURLFetcherFactory> url_fetcher_factory_;
......
...@@ -100,10 +100,13 @@ bool IsCreditCardUploadEnabled(const PrefService* pref_service, ...@@ -100,10 +100,13 @@ bool IsCreditCardUploadEnabled(const PrefService* pref_service,
// If the "allow all email domains" flag is off, restrict credit card upload // If the "allow all email domains" flag is off, restrict credit card upload
// only to Google Accounts with @googlemail, @gmail, @google, or @chromium // only to Google Accounts with @googlemail, @gmail, @google, or @chromium
// domains. // 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( if (!base::FeatureList::IsEnabled(
features::kAutofillUpstreamAllowAllEmailDomains) && features::kAutofillUpstreamAllowAllEmailDomains) &&
!(domain == "googlemail.com" || domain == "gmail.com" || !(domain == "googlemail.com" || domain == "gmail.com" ||
domain == "google.com" || domain == "chromium.org")) { domain == "google.com" || domain == "chromium.org" ||
domain == "example.com")) {
return false; return false;
} }
......
...@@ -251,12 +251,16 @@ void CreditCardSaveManager::AttemptToOfferCardUploadSave( ...@@ -251,12 +251,16 @@ void CreditCardSaveManager::AttemptToOfferCardUploadSave(
} }
bool CreditCardSaveManager::IsCreditCardUploadEnabled() { bool CreditCardSaveManager::IsCreditCardUploadEnabled() {
#if defined(OS_IOS)
// If observer_for_testing_ is set, assume we are in a browsertest and // If observer_for_testing_ is set, assume we are in a browsertest and
// credit card upload should be enabled by default. // credit card upload should be enabled by default.
return observer_for_testing_ || // TODO(crbug.com/859761): Remove dependency from iOS tests on this behavior.
::autofill::IsCreditCardUploadEnabled( if (observer_for_testing_)
client_->GetPrefs(), client_->GetSyncService(), return true;
personal_data_manager_->GetAccountInfoForPaymentsServer().email); #endif // defined(OS_IOS)
return ::autofill::IsCreditCardUploadEnabled(
client_->GetPrefs(), client_->GetSyncService(),
personal_data_manager_->GetAccountInfoForPaymentsServer().email);
} }
bool CreditCardSaveManager::IsUploadEnabledForNetwork( bool CreditCardSaveManager::IsUploadEnabledForNetwork(
......
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