Commit f5932b96 authored by Siyu An's avatar Siyu An Committed by Commit Bot

[Autofill BugFix] Fix flakiness in save card bubble browsertests

In browsertests we don't wait for the bubble to be actually shown
before verifying the view. Fix it by having the tests wait for extra
events.

Bug: 1133332
Change-Id: I898ae939a7b604dff6d170d54d136566ad34799f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464025
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#816629}
parent 1378e492
...@@ -575,9 +575,6 @@ void SaveCardBubbleControllerImpl::OnBubbleClosed( ...@@ -575,9 +575,6 @@ void SaveCardBubbleControllerImpl::OnBubbleClosed(
} }
UpdateSaveCardIcon(); UpdateSaveCardIcon();
if (observer_for_testing_)
observer_for_testing_->OnBubbleClosed();
} }
const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines()
...@@ -866,6 +863,9 @@ void SaveCardBubbleControllerImpl::ShowIconOnly() { ...@@ -866,6 +863,9 @@ void SaveCardBubbleControllerImpl::ShowIconOnly() {
case BubbleType::INACTIVE: case BubbleType::INACTIVE:
NOTREACHED(); NOTREACHED();
} }
if (observer_for_testing_)
observer_for_testing_->OnIconShown();
} }
void SaveCardBubbleControllerImpl::UpdateSaveCardIcon() { void SaveCardBubbleControllerImpl::UpdateSaveCardIcon() {
......
...@@ -39,7 +39,7 @@ class SaveCardBubbleControllerImpl ...@@ -39,7 +39,7 @@ class SaveCardBubbleControllerImpl
class ObserverForTest { class ObserverForTest {
public: public:
virtual void OnBubbleShown() = 0; virtual void OnBubbleShown() = 0;
virtual void OnBubbleClosed() = 0; virtual void OnIconShown() = 0;
}; };
~SaveCardBubbleControllerImpl() override; ~SaveCardBubbleControllerImpl() override;
......
...@@ -150,6 +150,7 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -150,6 +150,7 @@ class SaveCardBubbleViewsFullFormBrowserTest
// Various events that can be waited on by the DialogEventWaiter. // Various events that can be waited on by the DialogEventWaiter.
enum DialogEvent : int { enum DialogEvent : int {
OFFERED_LOCAL_SAVE, OFFERED_LOCAL_SAVE,
OFFERED_UPLOAD_SAVE,
REQUESTED_UPLOAD_SAVE, REQUESTED_UPLOAD_SAVE,
DYNAMIC_FORM_PARSED, DYNAMIC_FORM_PARSED,
RECEIVED_GET_UPLOAD_DETAILS_RESPONSE, RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
...@@ -158,7 +159,7 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -158,7 +159,7 @@ class SaveCardBubbleViewsFullFormBrowserTest
SHOW_CARD_SAVED_FEEDBACK, SHOW_CARD_SAVED_FEEDBACK,
STRIKE_CHANGE_COMPLETE, STRIKE_CHANGE_COMPLETE,
BUBBLE_SHOWN, BUBBLE_SHOWN,
BUBBLE_CLOSED ICON_SHOWN
}; };
// SyncTest::SetUpOnMainThread: // SyncTest::SetUpOnMainThread:
...@@ -218,6 +219,7 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -218,6 +219,7 @@ class SaveCardBubbleViewsFullFormBrowserTest
->GetFormDataImporter() ->GetFormDataImporter()
->credit_card_save_manager_.get(); ->credit_card_save_manager_.get();
credit_card_save_manager_->SetEventObserverForTesting(this); credit_card_save_manager_->SetEventObserverForTesting(this);
AddEventObserverToController();
// Set up this class as the ObserverForTest implementation. // Set up this class as the ObserverForTest implementation.
AutofillHandler* autofill_handler = AutofillHandler* autofill_handler =
...@@ -244,6 +246,12 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -244,6 +246,12 @@ class SaveCardBubbleViewsFullFormBrowserTest
event_waiter_->OnEvent(DialogEvent::OFFERED_LOCAL_SAVE); event_waiter_->OnEvent(DialogEvent::OFFERED_LOCAL_SAVE);
} }
// CreditCardSaveManager::ObserverForTest:
void OnOfferUploadSave() override {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::OFFERED_UPLOAD_SAVE);
}
// CreditCardSaveManager::ObserverForTest: // CreditCardSaveManager::ObserverForTest:
void OnDecideToRequestUploadSave() override { void OnDecideToRequestUploadSave() override {
if (event_waiter_) if (event_waiter_)
...@@ -287,9 +295,9 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -287,9 +295,9 @@ class SaveCardBubbleViewsFullFormBrowserTest
} }
// SaveCardBubbleControllerImpl::ObserverForTest: // SaveCardBubbleControllerImpl::ObserverForTest:
void OnBubbleClosed() override { void OnIconShown() override {
if (event_waiter_) if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::BUBBLE_CLOSED); event_waiter_->OnEvent(DialogEvent::ICON_SHOWN);
} }
inline views::Combobox* month_input() { inline views::Combobox* month_input() {
...@@ -349,7 +357,8 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -349,7 +357,8 @@ class SaveCardBubbleViewsFullFormBrowserTest
} }
void SubmitFormAndWaitForCardLocalSaveBubble() { void SubmitFormAndWaitForCardLocalSaveBubble() {
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE}); ResetEventWaiterForSequence(
{DialogEvent::OFFERED_LOCAL_SAVE, DialogEvent::BUBBLE_SHOWN});
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
WaitForAnimationToEnd(); WaitForAnimationToEnd();
...@@ -362,7 +371,8 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -362,7 +371,8 @@ class SaveCardBubbleViewsFullFormBrowserTest
SetUploadDetailsRpcPaymentsAccepts(); SetUploadDetailsRpcPaymentsAccepts();
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_UPLOAD_SAVE, DialogEvent::BUBBLE_SHOWN});
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
WaitForAnimationToEnd(); WaitForAnimationToEnd();
...@@ -674,15 +684,9 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -674,15 +684,9 @@ class SaveCardBubbleViewsFullFormBrowserTest
return specified_view; return specified_view;
} }
void ClickOnCancelButton(bool strike_expected = false) { void ClickOnCancelButton() {
SaveCardBubbleViews* save_card_bubble_views = GetSaveCardBubbleViews(); SaveCardBubbleViews* save_card_bubble_views = GetSaveCardBubbleViews();
DCHECK(save_card_bubble_views); DCHECK(save_card_bubble_views);
if (strike_expected) {
ResetEventWaiterForSequence(
{DialogEvent::STRIKE_CHANGE_COMPLETE, DialogEvent::BUBBLE_CLOSED});
} else {
ResetEventWaiterForSequence({DialogEvent::BUBBLE_CLOSED});
}
ClickOnDialogViewWithIdAndWait(DialogViewId::CANCEL_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::CANCEL_BUTTON);
DCHECK(!GetSaveCardBubbleViews()); DCHECK(!GetSaveCardBubbleViews());
} }
...@@ -690,7 +694,6 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -690,7 +694,6 @@ class SaveCardBubbleViewsFullFormBrowserTest
void ClickOnCloseButton() { void ClickOnCloseButton() {
SaveCardBubbleViews* save_card_bubble_views = GetSaveCardBubbleViews(); SaveCardBubbleViews* save_card_bubble_views = GetSaveCardBubbleViews();
DCHECK(save_card_bubble_views); DCHECK(save_card_bubble_views);
ResetEventWaiterForSequence({DialogEvent::BUBBLE_CLOSED});
ClickOnDialogViewAndWait(save_card_bubble_views->GetBubbleFrameView() ClickOnDialogViewAndWait(save_card_bubble_views->GetBubbleFrameView()
->GetCloseButtonForTesting()); ->GetCloseButtonForTesting());
DCHECK(!GetSaveCardBubbleViews()); DCHECK(!GetSaveCardBubbleViews());
...@@ -698,7 +701,7 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -698,7 +701,7 @@ class SaveCardBubbleViewsFullFormBrowserTest
SaveCardBubbleViews* GetSaveCardBubbleViews() { SaveCardBubbleViews* GetSaveCardBubbleViews() {
SaveCardBubbleController* save_card_bubble_controller = SaveCardBubbleController* save_card_bubble_controller =
SaveCardBubbleController::GetOrCreate(GetActiveWebContents()); SaveCardBubbleController::Get(GetActiveWebContents());
if (!save_card_bubble_controller) if (!save_card_bubble_controller)
return nullptr; return nullptr;
SaveCardBubbleView* save_card_bubble_view = SaveCardBubbleView* save_card_bubble_view =
...@@ -728,15 +731,10 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -728,15 +731,10 @@ class SaveCardBubbleViewsFullFormBrowserTest
void OpenSettingsFromManageCardsPrompt() { void OpenSettingsFromManageCardsPrompt() {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble
// to show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
#endif #endif
// Click [Save] should close the offer-to-save bubble and show "Card saved" // Click [Save] should close the offer-to-save bubble and show "Card saved"
...@@ -764,7 +762,8 @@ class SaveCardBubbleViewsFullFormBrowserTest ...@@ -764,7 +762,8 @@ class SaveCardBubbleViewsFullFormBrowserTest
void AddEventObserverToController() { void AddEventObserverToController() {
SaveCardBubbleControllerImpl* save_card_bubble_controller_impl = SaveCardBubbleControllerImpl* save_card_bubble_controller_impl =
SaveCardBubbleControllerImpl::FromWebContents(GetActiveWebContents()); static_cast<SaveCardBubbleControllerImpl*>(
SaveCardBubbleController::GetOrCreate(GetActiveWebContents()));
DCHECK(save_card_bubble_controller_impl); DCHECK(save_card_bubble_controller_impl);
save_card_bubble_controller_impl->SetEventObserverForTesting(this); save_card_bubble_controller_impl->SetEventObserverForTesting(this);
} }
...@@ -855,7 +854,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -855,7 +854,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Clicking [No thanks] should cancel and close it. // Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ClickOnCancelButton(/*strike_expected=*/true); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton();
WaitForObservedEvent();
// UMA should have recorded bubble rejection. // UMA should have recorded bubble rejection.
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
...@@ -871,17 +872,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -871,17 +872,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Sign-in promo should be showing and user actions should have recorded // Sign-in promo should be showing and user actions should have recorded
...@@ -920,7 +917,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -920,7 +917,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,
DialogEvent::OFFERED_LOCAL_SAVE}); DialogEvent::OFFERED_LOCAL_SAVE, DialogEvent::BUBBLE_SHOWN});
FillForm(); FillForm();
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -947,17 +944,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -947,17 +944,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// User actions should have recorded impression. // User actions should have recorded impression.
...@@ -985,17 +978,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -985,17 +978,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Click on [Sign in] button. // Click on [Sign in] button.
...@@ -1018,16 +1007,12 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -1018,16 +1007,12 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
views::test::AXEventCounter counter(views::AXEventManager::Get()); views::test::AXEventCounter counter(views::AXEventManager::Get());
EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kAlert)); EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kAlert));
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_EQ(1, counter.GetCount(ax::mojom::Event::kAlert)); EXPECT_EQ(1, counter.GetCount(ax::mojom::Event::kAlert));
...@@ -1217,7 +1202,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsSyncTransportFullFormBrowserTest, ...@@ -1217,7 +1202,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsSyncTransportFullFormBrowserTest,
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{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, DialogEvent::BUBBLE_SHOWN});
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL) EXPECT_TRUE(FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL)
...@@ -1292,7 +1277,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1292,7 +1277,9 @@ IN_PROC_BROWSER_TEST_F(
// Clicking [No thanks] should cancel and close it. // Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ClickOnCancelButton(/*strike_expected=*/true); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton();
WaitForObservedEvent();
// UMA should have recorded bubble rejection. // UMA should have recorded bubble rejection.
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
...@@ -1565,7 +1552,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1565,7 +1552,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,
DialogEvent::OFFERED_LOCAL_SAVE}); DialogEvent::OFFERED_LOCAL_SAVE, DialogEvent::BUBBLE_SHOWN});
NavigateTo(kCreditCardAndAddressUploadForm); NavigateTo(kCreditCardAndAddressUploadForm);
FillForm(); FillForm();
SubmitForm(); SubmitForm();
...@@ -1591,7 +1578,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1591,7 +1578,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,
DialogEvent::OFFERED_LOCAL_SAVE}); DialogEvent::OFFERED_LOCAL_SAVE, DialogEvent::BUBBLE_SHOWN});
NavigateTo(kCreditCardAndAddressUploadForm); NavigateTo(kCreditCardAndAddressUploadForm);
FillForm(); FillForm();
SubmitForm(); SubmitForm();
...@@ -1634,7 +1621,8 @@ IN_PROC_BROWSER_TEST_F( ...@@ -1634,7 +1621,8 @@ IN_PROC_BROWSER_TEST_F(
WaitForObservedEvent(); WaitForObservedEvent();
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_UPLOAD_SAVE, DialogEvent::BUBBLE_SHOWN});
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
EXPECT_TRUE(GetSaveCardBubbleViews()); EXPECT_TRUE(GetSaveCardBubbleViews());
...@@ -2011,9 +1999,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -2011,9 +1999,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Clicking the [X] close button should dismiss the bubble. // Clicking the [X] close button should dismiss the bubble.
ClickOnCloseButton(); ClickOnCloseButton();
// Add an event observer to the controller to detect strike changes.
AddEventObserverToController();
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Wait long enough to avoid bubble stickiness, then navigate away from the // Wait long enough to avoid bubble stickiness, then navigate away from the
...@@ -2046,9 +2031,6 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2046,9 +2031,6 @@ IN_PROC_BROWSER_TEST_F(
// Clicking the [X] close button should dismiss the bubble. // Clicking the [X] close button should dismiss the bubble.
ClickOnCloseButton(); ClickOnCloseButton();
// Add an event observer to the controller to detect strike changes.
AddEventObserverToController();
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Wait long enough to avoid bubble stickiness, then navigate away from the // Wait long enough to avoid bubble stickiness, then navigate away from the
...@@ -2073,7 +2055,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -2073,7 +2055,9 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Clicking [No thanks] should cancel and close it. // Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ClickOnCancelButton(/*strike_expected=*/true); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton();
WaitForObservedEvent();
// Ensure that a strike was added. // Ensure that a strike was added.
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
...@@ -2094,7 +2078,9 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2094,7 +2078,9 @@ IN_PROC_BROWSER_TEST_F(
// Clicking [No thanks] should cancel and close it. // Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ClickOnCancelButton(/*strike_expected=*/true); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton();
WaitForObservedEvent();
// Ensure that a strike was added. // Ensure that a strike was added.
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
...@@ -2108,8 +2094,6 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2108,8 +2094,6 @@ IN_PROC_BROWSER_TEST_F(
// strikes are added if the card already has max strikes. // strikes are added if the card already has max strikes.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
StrikeDatabase_Local_FullFlowTest) { StrikeDatabase_Local_FullFlowTest) {
bool controller_observer_set = false;
// Show and ignore the bubble enough times in order to accrue maximum strikes. // Show and ignore the bubble enough times in order to accrue maximum strikes.
for (int i = 0; for (int i = 0;
i < credit_card_save_manager_->GetCreditCardSaveStrikeDatabase() i < credit_card_save_manager_->GetCreditCardSaveStrikeDatabase()
...@@ -2117,17 +2101,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -2117,17 +2101,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
++i) { ++i) {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
ReduceAnimationTime();
if (!controller_observer_set) {
// Add an event observer to the controller.
AddEventObserverToController();
ReduceAnimationTime();
controller_observer_set = true;
}
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE}); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton(/*strike_expected=*/true); ClickOnCancelButton();
WaitForObservedEvent(); WaitForObservedEvent();
// Ensure that a strike was added due to the bubble being declined. // Ensure that a strike was added due to the bubble being declined.
...@@ -2141,7 +2119,8 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -2141,7 +2119,8 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Submit the form a fourth time. Since the card now has maximum strikes (3), // Submit the form a fourth time. Since the card now has maximum strikes (3),
// the icon should be shown but the bubble should not. // the icon should be shown but the bubble should not.
ResetEventWaiterForSequence({DialogEvent::OFFERED_LOCAL_SAVE}); ResetEventWaiterForSequence(
{DialogEvent::OFFERED_LOCAL_SAVE, DialogEvent::ICON_SHOWN});
FillForm(); FillForm();
SubmitForm(); SubmitForm();
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -2180,8 +2159,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest, ...@@ -2180,8 +2159,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream, SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
StrikeDatabase_Upload_FullFlowTest) { StrikeDatabase_Upload_FullFlowTest) {
bool controller_observer_set = false;
// Start sync. // Start sync.
harness_->SetupSync(); harness_->SetupSync();
...@@ -2192,17 +2169,12 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2192,17 +2169,12 @@ IN_PROC_BROWSER_TEST_F(
++i) { ++i) {
FillForm(); FillForm();
SubmitFormAndWaitForCardUploadSaveBubble(); SubmitFormAndWaitForCardUploadSaveBubble();
ReduceAnimationTime();
if (!controller_observer_set) {
// Add an event observer to the controller.
AddEventObserverToController();
ReduceAnimationTime();
controller_observer_set = true;
}
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ClickOnCancelButton(/*strike_expected=*/true); ResetEventWaiterForSequence({DialogEvent::STRIKE_CHANGE_COMPLETE});
ClickOnCancelButton();
WaitForObservedEvent(); WaitForObservedEvent();
// Ensure that a strike was added due to the bubble being declined. // Ensure that a strike was added due to the bubble being declined.
...@@ -2218,7 +2190,8 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2218,7 +2190,8 @@ IN_PROC_BROWSER_TEST_F(
// the icon should be shown but the bubble should not. // the icon should be shown but the bubble should not.
ResetEventWaiterForSequence( ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE, {DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE}); DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_UPLOAD_SAVE, DialogEvent::ICON_SHOWN});
NavigateTo(kCreditCardAndAddressUploadForm); NavigateTo(kCreditCardAndAddressUploadForm);
FillForm(); FillForm();
SubmitForm(); SubmitForm();
...@@ -2310,7 +2283,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip, ...@@ -2310,7 +2283,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip,
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
ClickOnCloseButton(); ClickOnCloseButton();
AddEventObserverToController();
ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN}); ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
ClickOnView(GetSaveCardIconView()); ClickOnView(GetSaveCardIconView());
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -2460,6 +2432,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip, ...@@ -2460,6 +2432,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip,
SetUploadCardRpcPaymentsFails(); SetUploadCardRpcPaymentsFails();
ResetEventWaiterForSequence({DialogEvent::RECEIVED_UPLOAD_CARD_RESPONSE, ResetEventWaiterForSequence({DialogEvent::RECEIVED_UPLOAD_CARD_RESPONSE,
DialogEvent::STRIKE_CHANGE_COMPLETE, DialogEvent::STRIKE_CHANGE_COMPLETE,
DialogEvent::ICON_SHOWN,
DialogEvent::SHOW_CARD_SAVED_FEEDBACK}); DialogEvent::SHOW_CARD_SAVED_FEEDBACK});
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -2481,7 +2454,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip, ...@@ -2481,7 +2454,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip,
AutofillMetrics::CREDIT_CARD_UPLOAD_FEEDBACK_FAILURE_BUBBLE_SHOWN, 0); AutofillMetrics::CREDIT_CARD_UPLOAD_FEEDBACK_FAILURE_BUBBLE_SHOWN, 0);
// Click on the icon. // Click on the icon.
AddEventObserverToController();
ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN}); ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
ClickOnView(GetSaveCardIconView()); ClickOnView(GetSaveCardIconView());
WaitForObservedEvent(); WaitForObservedEvent();
...@@ -2507,15 +2479,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip, ...@@ -2507,15 +2479,11 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForStatusChip,
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
// show.
AddEventObserverToController();
ResetEventWaiterForSequence(
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Ensures the credit card icon is not visible. // Ensures the credit card icon is not visible.
...@@ -2533,21 +2501,15 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2533,21 +2501,15 @@ IN_PROC_BROWSER_TEST_F(
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
// show.
AddEventObserverToController();
ResetEventWaiterForSequence(
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Close the sign-in promo. // Close the sign-in promo.
ResetEventWaiterForSequence({DialogEvent::BUBBLE_CLOSED});
ClickOnCloseButton(); ClickOnCloseButton();
WaitForObservedEvent();
// Ensures the neither credit card icon nor the manage cards bubble is // Ensures the neither credit card icon nor the manage cards bubble is
// showing. // showing.
...@@ -2606,18 +2568,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard, ...@@ -2606,18 +2568,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard,
Local_Metrics_SigninImpressionManageCards) { Local_Metrics_SigninImpressionManageCards) {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Close promo. // Close promo.
...@@ -2640,15 +2597,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard, ...@@ -2640,15 +2597,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard,
Local_ClickingIconShowsManageCards) { Local_ClickingIconShowsManageCards) {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
#endif #endif
// Click [Save] should close the offer-to-save bubble and show "Card saved" // Click [Save] should close the offer-to-save bubble and show "Card saved"
...@@ -2680,15 +2632,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard, ...@@ -2680,15 +2632,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard,
Local_ManageCardsDoneButtonClosesBubble) { Local_ManageCardsDoneButtonClosesBubble) {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
#endif #endif
// Click [Save] should close the offer-to-save bubble and show "Card saved" // Click [Save] should close the offer-to-save bubble and show "Card saved"
...@@ -2725,18 +2672,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard, ...@@ -2725,18 +2672,13 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestForManageCard,
Local_Metrics_AcceptingFootnotePromoManageCards) { Local_Metrics_AcceptingFootnotePromoManageCards) {
FillForm(); FillForm();
SubmitFormAndWaitForCardLocalSaveBubble(); SubmitFormAndWaitForCardLocalSaveBubble();
// Adding an event observer to the controller so we can wait for the bubble to
// show.
AddEventObserverToController();
ReduceAnimationTime(); ReduceAnimationTime();
ResetEventWaiterForSequence( ResetEventWaiterForSequence({DialogEvent::BUBBLE_SHOWN});
{DialogEvent::BUBBLE_CLOSED, DialogEvent::BUBBLE_SHOWN});
// Click [Save] should close the offer-to-save bubble // Click [Save] should close the offer-to-save bubble
// and pop up the sign-in promo. // and pop up the sign-in promo.
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
ClickOnDialogViewWithId(DialogViewId::OK_BUTTON); ClickOnDialogViewWithIdAndWait(DialogViewId::OK_BUTTON);
WaitForObservedEvent(); WaitForObservedEvent();
// Close promo. // Close promo.
......
...@@ -486,6 +486,8 @@ void CreditCardSaveManager::OfferCardUploadSave() { ...@@ -486,6 +486,8 @@ void CreditCardSaveManager::OfferCardUploadSave() {
// should not display the offer-to-save infobar at all. // should not display the offer-to-save infobar at all.
if (!is_mobile_build || show_save_prompt_.value_or(true)) { if (!is_mobile_build || show_save_prompt_.value_or(true)) {
user_did_accept_upload_prompt_ = false; user_did_accept_upload_prompt_ = false;
if (observer_for_testing_)
observer_for_testing_->OnOfferUploadSave();
client_->ConfirmSaveCreditCardToCloud( client_->ConfirmSaveCreditCardToCloud(
upload_request_.card, legal_message_lines_, upload_request_.card, legal_message_lines_,
AutofillClient::SaveCreditCardOptions() AutofillClient::SaveCreditCardOptions()
......
...@@ -84,6 +84,7 @@ class CreditCardSaveManager { ...@@ -84,6 +84,7 @@ class CreditCardSaveManager {
public: public:
virtual ~ObserverForTest() {} virtual ~ObserverForTest() {}
virtual void OnOfferLocalSave() {} virtual void OnOfferLocalSave() {}
virtual void OnOfferUploadSave() {}
virtual void OnDecideToRequestUploadSave() {} virtual void OnDecideToRequestUploadSave() {}
virtual void OnReceivedGetUploadDetailsResponse() {} virtual void OnReceivedGetUploadDetailsResponse() {}
virtual void OnSentUploadCardRequest() {} virtual void OnSentUploadCardRequest() {}
......
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