Commit 4373aa08 authored by Findit's avatar Findit

Revert "[Autofill] Added browser tests for local card migration dialog."

This reverts commit 656c20b3.

Reason for revert:

Findit (https://goo.gl/kROfz5) identified CL at revision 607881 as the
culprit for flakes in the build cycles as shown on:
https://findit-for-me.appspot.com/waterfall/flake/flake-culprit?key=ag9zfmZpbmRpdC1mb3ItbWVyQwsSDEZsYWtlQ3VscHJpdCIxY2hyb21pdW0vNjU2YzIwYjNhYWE0OGRiOTM4ZDYxNmMxZjQ2YjQ1ZGQ1NGMyMDZjMAw

Sample Failed Build: https://ci.chromium.org/buildbot/chromium.chromiumos/linux-chromeos-rel/15973

Sample Failed Step: single_process_mash_browser_tests

Sample Flaky Test: LocalCardMigrationBrowserTest.ClickingSaveClosesDialog

Original change's description:
> [Autofill] Added browser tests for local card migration dialog.
> 
> Relanding browser tests for local migration flow. Commented out flaky tests that were causing issues earlier.
> 
> Bug: 897998
> Change-Id: I7dd0fdb5f71587bddc236732c6d3725dc6411818
> Reviewed-on: https://chromium-review.googlesource.com/c/1332704
> Reviewed-by: Evan Stade <estade@chromium.org>
> Commit-Queue: Manas Verma <manasverma@google.com>
> Cr-Commit-Position: refs/heads/master@{#607881}

Change-Id: I128c446c52bd22b7c1957b69307d4768b5b39166
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 897998
Reviewed-on: https://chromium-review.googlesource.com/c/1335277
Cr-Commit-Position: refs/heads/master@{#607917}
parent d5e3fbea
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_CONTROLLER_IMPL_H_ #define CHROME_BROWSER_UI_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_CONTROLLER_IMPL_H_
#include <memory> #include <memory>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/timer/elapsed_timer.h" #include "base/timer/elapsed_timer.h"
...@@ -54,11 +53,6 @@ class LocalCardMigrationDialogControllerImpl ...@@ -54,11 +53,6 @@ class LocalCardMigrationDialogControllerImpl
void OnLegalMessageLinkClicked(const GURL& url) override; void OnLegalMessageLinkClicked(const GURL& url) override;
void OnDialogClosed() override; void OnDialogClosed() override;
// Returns nullptr if no dialog is currently shown.
LocalCardMigrationDialog* local_card_migration_dialog_view() const {
return local_card_migration_dialog_;
}
protected: protected:
explicit LocalCardMigrationDialogControllerImpl( explicit LocalCardMigrationDialogControllerImpl(
content::WebContents* web_contents); content::WebContents* web_contents);
......
...@@ -8,21 +8,17 @@ ...@@ -8,21 +8,17 @@
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
// This defines an enumeration of IDs that can uniquely identify a view within // This defines an enumeration of IDs that can uniquely identify a view within
// the scope of the local and upload credit card save bubbles as well as the // the scope of the local and upload credit card save bubbles.
// local card migration bubble and dialogs.
namespace autofill { namespace autofill {
enum DialogViewId : int { enum DialogViewId : int {
VIEW_ID_NONE = 0, VIEW_ID_NONE = 0,
// The following views are contained in SaveCardBubbleViews. // The following are the important containing views of the bubble.
MAIN_CONTENT_VIEW_LOCAL, // The main content view for a local MAIN_CONTENT_VIEW_LOCAL, // The main content view, for a local save bubble
// save bubble MAIN_CONTENT_VIEW_UPLOAD, // The main content view, for an upload save bubble
MAIN_CONTENT_VIEW_UPLOAD, // The main content view for an upload FOOTNOTE_VIEW, // Contains the legal messages for upload save
// save bubble
FOOTNOTE_VIEW, // The footnote view of either an upload
// save bubble or a manage cards view.
SIGN_IN_PROMO_VIEW, // Contains the sign-in promo view SIGN_IN_PROMO_VIEW, // Contains the sign-in promo view
MANAGE_CARDS_VIEW, // The manage cards view MANAGE_CARDS_VIEW, // The manage cards view
EXPIRATION_DATE_VIEW, // Contains the dropdowns for expiration date EXPIRATION_DATE_VIEW, // Contains the dropdowns for expiration date
...@@ -30,12 +26,6 @@ enum DialogViewId : int { ...@@ -30,12 +26,6 @@ enum DialogViewId : int {
// The sub-view that contains the sign-in button in the promo. // The sub-view that contains the sign-in button in the promo.
SIGN_IN_VIEW, SIGN_IN_VIEW,
// The main content view for a migration offer bubble.
MAIN_CONTENT_VIEW_MIGRATION_BUBBLE,
// The main content view for the main migration dialog.
MAIN_CONTENT_VIEW_MIGRATION_OFFER_DIALOG,
// The following are views::LabelButton objects (clickable). // The following are views::LabelButton objects (clickable).
OK_BUTTON, // Can say [Save], [Next], [Confirm], OK_BUTTON, // Can say [Save], [Next], [Confirm],
// or [Done] depending on context // or [Done] depending on context
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_browsertest_base.h"
#include "content/public/test/browser_test_utils.h"
using base::Bucket;
using testing::ElementsAre;
namespace {
constexpr char kFirstCardNumber[] = "5428424047572420"; // Mastercard
constexpr char kSecondCardNumber[] = "4782187095085933"; // Visa
constexpr char kThirdCardNumber[] = "345159891979146"; // AmEx
} // namespace
namespace autofill {
class LocalCardMigrationBrowserTest : public LocalCardMigrationBrowserTestBase {
protected:
LocalCardMigrationBrowserTest() : LocalCardMigrationBrowserTestBase() {}
// Returns the number of migratable cards.
void TriggerMigrationBubbleByReusingLocalCard() {
SaveLocalCard(kFirstCardNumber);
SaveLocalCard(kSecondCardNumber);
SignInWithFullName("John Smith");
UseCardAndWaitForMigrationOffer(kFirstCardNumber);
}
void TriggerMigrationBubbleByReusingServerCard() {
SaveLocalCard(kFirstCardNumber);
SaveLocalCard(kSecondCardNumber);
SignInWithFullName("John Smith");
SaveServerCard(kThirdCardNumber);
UseCardAndWaitForMigrationOffer(kThirdCardNumber);
}
private:
DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationBrowserTest);
};
// Ensures that migration is not offered when user saves a new card.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
UsingNewCardDoesNotShowIntermediateMigrationOffer) {
base::HistogramTester histogram_tester;
SetUploadDetailsRpcPaymentsAccepts();
SaveLocalCard(kFirstCardNumber);
SaveLocalCard(kSecondCardNumber);
SignInWithFullName("John Smith");
FillAndSubmitFormWithCard(kThirdCardNumber);
// No bubble should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// No metrics are recorded when migration is not offered.
histogram_tester.ExpectTotalCount(
"Autofill.LocalCardMigrationBubbleOffer.FirstShow", 0);
}
// Ensures that migration is not offered when payments declines the cards.
IN_PROC_BROWSER_TEST_F(
LocalCardMigrationBrowserTest,
IntermediateMigrationOfferDoesNotShowWhenPaymentsDeclines) {
base::HistogramTester histogram_tester;
SaveLocalCard(kFirstCardNumber);
SaveLocalCard(kSecondCardNumber);
SignInWithFullName("John Smith");
SetUploadDetailsRpcPaymentsDeclines();
FillAndSubmitFormWithCard(kFirstCardNumber);
// No bubble should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// No metrics are recorded when migration is not offered.
histogram_tester.ExpectTotalCount(
"Autofill.LocalCardMigrationBubbleOffer.FirstShow", 0);
}
// Ensures that the intermediate migration bubble is not shown after reusing a
// saved server card, if there are no other cards to migrate.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ReusingServerCardDoesNotShowIntermediateMigrationOffer) {
base::HistogramTester histogram_tester;
SetUploadDetailsRpcPaymentsAccepts();
SignInWithFullName("John Smith");
SaveServerCard(kFirstCardNumber);
SaveServerCard(kSecondCardNumber);
FillAndSubmitFormWithCard(kFirstCardNumber);
// No bubble should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// No metrics are recorded when migration is not offered.
histogram_tester.ExpectTotalCount(
"Autofill.LocalCardMigrationBubbleOffer.FirstShow", 0);
}
// Ensures that the intermediate migration bubble is not shown after reusing a
// previously saved local card, if there are no other cards to migrate.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ReusingLocalCardDoesNotShowIntermediateMigrationOffer) {
base::HistogramTester histogram_tester;
SetUploadDetailsRpcPaymentsAccepts();
SaveLocalCard(kFirstCardNumber);
SignInWithFullName("John Smith");
FillAndSubmitFormWithCard(kFirstCardNumber);
// No migration bubble should be showing, because the single card upload
// bubble should be displayed instead.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// No metrics are recorded when migration is not offered.
histogram_tester.ExpectTotalCount(
"Autofill.LocalCardMigrationBubbleOffer.FirstShow", 0);
}
// Ensures that the intermediate migration bubble is triggered after reusing a
// saved local card, if there are multiple local cards available to migrate.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ReusingLocalCardShowsIntermediateMigrationOffer) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
// The intermediate migration bubble should show.
EXPECT_TRUE(
FindViewInDialogById(DialogViewId::MAIN_CONTENT_VIEW_MIGRATION_BUBBLE,
GetLocalCardMigrationOfferBubbleViews())
->visible());
// Metrics
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationBubbleOffer.FirstShow"),
ElementsAre(
Bucket(AutofillMetrics::LOCAL_CARD_MIGRATION_BUBBLE_REQUESTED, 1),
Bucket(AutofillMetrics::LOCAL_CARD_MIGRATION_BUBBLE_SHOWN, 1)));
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard",
AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1);
}
// Ensures that clicking [X] on the offer bubble makes the bubble disappear.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ClickingCloseClosesBubble) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
ClickOnDialogViewAndWait(GetCloseButton(),
GetLocalCardMigrationOfferBubbleViews());
// No bubble should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// Metrics
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard",
AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1);
}
// Ensures that clicking on the credit card icon in the omnibox reopens the
// offer bubble after closing it.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ClickingOmniboxIconReshowsBubble) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
ClickOnDialogViewAndWait(GetCloseButton(),
GetLocalCardMigrationOfferBubbleViews());
ClickOnView(GetLocalCardMigrationIconView());
// Clicking the icon should reshow the bubble.
EXPECT_TRUE(
FindViewInDialogById(DialogViewId::MAIN_CONTENT_VIEW_MIGRATION_BUBBLE,
GetLocalCardMigrationOfferBubbleViews())
->visible());
// Metrics
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard"),
ElementsAre(Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1)));
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationBubbleOffer.Reshows"),
ElementsAre(
Bucket(AutofillMetrics::LOCAL_CARD_MIGRATION_BUBBLE_REQUESTED, 1),
Bucket(AutofillMetrics::LOCAL_CARD_MIGRATION_BUBBLE_SHOWN, 1)));
}
// Ensures that accepting the intermediate migration offer opens up the main
// migration dialog.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ClickingContinueOpensDialog) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
// Click the [Continue] button.
ClickOnOkButton(GetLocalCardMigrationOfferBubbleViews());
// Dialog should be visible.
EXPECT_TRUE(FindViewInDialogById(
DialogViewId::MAIN_CONTENT_VIEW_MIGRATION_OFFER_DIALOG,
GetLocalCardMigrationMainDialogView())
->visible());
// Intermediate bubble should be gone.
EXPECT_EQ(nullptr, GetLocalCardMigrationOfferBubbleViews());
// Metrics
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard"),
ElementsAre(Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1),
Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_ACCEPTED, 1),
Bucket(AutofillMetrics::MAIN_DIALOG_SHOWN, 1)));
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationBubbleUserInteraction.FirstShow",
AutofillMetrics::LOCAL_CARD_MIGRATION_BUBBLE_CLOSED_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationDialogOffer",
AutofillMetrics::LOCAL_CARD_MIGRATION_DIALOG_SHOWN, 1);
// Closing the dialog.
ClickOnCancelButton(GetLocalCardMigrationMainDialogView());
}
// Ensures that rejecting the main migration dialog closes the dialog.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ClickingCancelClosesDialog) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
// Click the [Continue] button.
ClickOnOkButton(GetLocalCardMigrationOfferBubbleViews());
// Click the [Cancel] button.
ClickOnCancelButton(GetLocalCardMigrationMainDialogView());
// No dialog should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationMainDialogView());
// Metrics
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard"),
ElementsAre(Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1),
Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_ACCEPTED, 1),
Bucket(AutofillMetrics::MAIN_DIALOG_SHOWN, 1)));
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationDialogUserInteraction",
AutofillMetrics::LOCAL_CARD_MIGRATION_DIALOG_CLOSED_CANCEL_BUTTON_CLICKED,
1);
}
// Ensures that accepting the main migration dialog closes the dialog.
IN_PROC_BROWSER_TEST_F(LocalCardMigrationBrowserTest,
ClickingSaveClosesDialog) {
base::HistogramTester histogram_tester;
TriggerMigrationBubbleByReusingLocalCard();
// Click the [Continue] button.
ClickOnOkButton(GetLocalCardMigrationOfferBubbleViews());
// Click the [Save] button and wait for RPC to go through.
ResetEventWaiterForSequence({DialogEvent::SENT_MIGRATE_LOCAL_CARDS_REQUEST,
DialogEvent::RECEIVED_MIGRATE_CARDS_RESPONSE});
ClickOnOkButton(GetLocalCardMigrationMainDialogView());
WaitForObservedEvent();
// No dialog should be showing.
EXPECT_EQ(nullptr, GetLocalCardMigrationMainDialogView());
// Metrics
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.LocalCardMigrationOrigin.UseOfLocalCard"),
ElementsAre(Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_SHOWN, 1),
Bucket(AutofillMetrics::INTERMEDIATE_BUBBLE_ACCEPTED, 1),
Bucket(AutofillMetrics::MAIN_DIALOG_SHOWN, 1),
Bucket(AutofillMetrics::MAIN_DIALOG_ACCEPTED, 1)));
histogram_tester.ExpectUniqueSample(
"Autofill.LocalCardMigrationDialogUserInteraction",
AutofillMetrics::LOCAL_CARD_MIGRATION_DIALOG_CLOSED_SAVE_BUTTON_CLICKED,
1);
}
// TODO(manasverma): Add these following tests.
// 1) Reusing a server card shows the intermediate bubble.
// 2) All valid cards are visible in the migration offer view.
// 3) Local cards should get deleted after migration.
// 4) Expired and invalid cards should not be shown.
// 5) When user navigates away after five seconds, the bubble disappears.
// 6) When user navigates away after five seconds, the dialog should stay.
// 7) When user clicks legal message links, browser should redirect to different
// tab but dialog should stay in the original tab.
// 8) Simulate check boxes to ensure
// LocalCardMigrationDialogUserSelectionPercentage is logged correctly.
// 9) Ensure LocalCardMigrationDialogActiveDuration is logged correctly.
} // namespace autofill
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/autofill/local_card_migration_browsertest_base.h"
#include <ctime>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include "chrome/browser/signin/account_fetcher_service_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_account_fetcher_service_builder.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/autofill/local_card_migration_bubble_controller_impl.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog_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_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/autofill/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_bubble_views.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_dialog_view.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_icon_view.h"
#include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver.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/local_card_migration_manager.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_account_fetcher_service.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/window/dialog_client_view.h"
namespace autofill {
namespace {
constexpr char kURLGetUploadDetailsRequest[] =
"https://payments.google.com/payments/apis/chromepaymentsservice/"
"getdetailsforsavecard";
constexpr char kResponseGetUploadDetailsSuccess[] =
"{\"legal_message\":{\"line\":[{\"template\":\"Legal message template with "
"link: "
"{0}.\",\"template_parameter\":[{\"display_text\":\"Link\",\"url\":\"https:"
"//www.example.com/\"}]}]},\"context_token\":\"dummy_context_token\"}";
constexpr char kResponseGetUploadDetailsFailure[] =
"{\"error\":{\"code\":\"FAILED_PRECONDITION\",\"user_error_message\":\"An "
"unexpected error has occurred. Please try again later.\"}}";
constexpr char kCreditCardFormURL[] =
"/credit_card_upload_form_address_and_cc.html";
constexpr double kFakeGeolocationLatitude = 1.23;
constexpr double kFakeGeolocationLongitude = 4.56;
} // namespace
LocalCardMigrationBrowserTestBase::LocalCardMigrationBrowserTestBase() {}
LocalCardMigrationBrowserTestBase::~LocalCardMigrationBrowserTestBase() {}
void LocalCardMigrationBrowserTestBase::SetUpOnMainThread() {
// Enable Local Card Migration.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set up the HTTPS server (uses the embedded_test_server).
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
embedded_test_server()->ServeFilesFromSourceDirectory(
"components/test/data/autofill");
embedded_test_server()->StartAcceptingConnections();
// Set up the URL loader factory for the payments client so we can intercept
// those network requests too.
test_shared_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_);
ContentAutofillDriver::GetForRenderFrameHost(
GetActiveWebContents()->GetMainFrame())
->autofill_manager()
->client()
->GetPaymentsClient()
->set_url_loader_factory_for_testing(test_shared_loader_factory_);
// Set up this class as the ObserverForTest implementation.
LocalCardMigrationManager* local_card_migration_manager =
ContentAutofillDriver::GetForRenderFrameHost(
GetActiveWebContents()->GetMainFrame())
->autofill_manager()
->client()
->GetFormDataImporter()
->local_card_migration_manager_.get();
local_card_migration_manager->SetEventObserverForTesting(this);
personal_data_ = local_card_migration_manager->personal_data_manager_;
// Set up the fake geolocation data.
geolocation_overrider_ = std::make_unique<device::ScopedGeolocationOverrider>(
kFakeGeolocationLatitude, kFakeGeolocationLongitude);
ContentAutofillDriver::GetForRenderFrameHost(
GetActiveWebContents()->GetMainFrame())
->autofill_manager()
->client()
->GetPrefs()
->SetDouble(prefs::kAutofillBillingCustomerNumber, 1234);
NavigateTo(kCreditCardFormURL);
}
void LocalCardMigrationBrowserTestBase::NavigateTo(
const std::string& file_path) {
ui_test_utils::NavigateToURL(browser(),
file_path.find("data:") == 0U
? GURL(file_path)
: embedded_test_server()->GetURL(file_path));
}
void LocalCardMigrationBrowserTestBase::OnSentMigrateLocalCardsRequest() {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::SENT_MIGRATE_LOCAL_CARDS_REQUEST);
}
void LocalCardMigrationBrowserTestBase::OnReceivedGetUploadDetailsResponse() {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE);
}
void LocalCardMigrationBrowserTestBase::OnDecideToRequestLocalCardMigration() {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::REQUESTED_LOCAL_CARD_MIGRATION);
}
void LocalCardMigrationBrowserTestBase::OnRecievedMigrateCardsResponse() {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::RECEIVED_MIGRATE_CARDS_RESPONSE);
}
void LocalCardMigrationBrowserTestBase::SetUpInProcessBrowserTestFixture() {
will_create_browser_context_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterWillCreateBrowserContextServicesCallbackForTesting(
base::BindRepeating(&LocalCardMigrationBrowserTestBase::
OnWillCreateBrowserContextServices,
base::Unretained(this)));
}
void LocalCardMigrationBrowserTestBase::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 LocalCardMigrationBrowserTestBase::SaveLocalCard(std::string card_number) {
CreditCard local_card;
test::SetCreditCardInfo(&local_card, "John Smith", card_number.c_str(), "12",
test::NextYear().c_str(), "1");
local_card.set_guid("00000000-0000-0000-0000-" + card_number.substr(0, 12));
local_card.set_record_type(CreditCard::LOCAL_CARD);
personal_data_->AddCreditCard(local_card);
}
void LocalCardMigrationBrowserTestBase::SaveServerCard(
std::string card_number) {
CreditCard server_card;
test::SetCreditCardInfo(&server_card, "John Smith", card_number.c_str(), "12",
test::NextYear().c_str(), "1");
server_card.set_guid("00000000-0000-0000-0000-" + card_number.substr(0, 12));
server_card.set_record_type(CreditCard::FULL_SERVER_CARD);
server_card.set_server_id("full_id_" + card_number);
personal_data_->AddFullServerCreditCard(server_card);
}
void LocalCardMigrationBrowserTestBase::UseCardAndWaitForMigrationOffer(
std::string card_number) {
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Once signed-in, reusing a card should show the migration offer bubble.
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_LOCAL_CARD_MIGRATION,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
FillAndSubmitFormWithCard(card_number);
WaitForObservedEvent();
}
void LocalCardMigrationBrowserTestBase::SignInWithFullName(
const std::string& full_name) {
// TODO(crbug.com/859761): Can this function be used to remove the
// observer_for_testing_ hack in
// CreditCardSaveManager::IsCreditCardUploadEnabled()?
FakeSigninManagerForTesting* signin_manager =
static_cast<FakeSigninManagerForTesting*>(
SigninManagerFactory::GetInstance()->GetForProfile(
browser()->profile()));
// Note: Chrome OS tests seem to rely on these specific login values, so
// changing them is probably not recommended.
constexpr char kTestEmail[] = "stub-user@example.com";
constexpr char kTestGaiaId[] = "stub-user@example.com";
#if !defined(OS_CHROMEOS)
signin_manager->SignIn(kTestGaiaId, kTestEmail, "password");
#else
AccountTrackerService* account_tracker_service =
AccountTrackerServiceFactory::GetForProfile(browser()->profile());
signin_manager->SignIn(account_tracker_service->PickAccountIdForAccount(
kTestGaiaId, kTestEmail));
#endif
FakeAccountFetcherService* account_fetcher_service =
static_cast<FakeAccountFetcherService*>(
AccountFetcherServiceFactory::GetForProfile(browser()->profile()));
account_fetcher_service->FakeUserInfoFetchSuccess(
signin_manager->GetAuthenticatedAccountId(), kTestEmail, kTestGaiaId,
AccountTrackerService::kNoHostedDomainFound, full_name,
/*given_name=*/std::string(), "locale", "avatar.jpg");
}
// Should be called for credit_card_upload_form_address_and_cc.html.
void LocalCardMigrationBrowserTestBase::FillAndSubmitFormWithCard(
std::string card_number) {
content::WebContents* web_contents = GetActiveWebContents();
const std::string click_fill_button_js =
"(function() { document.getElementById('fill_form').click(); })();";
ASSERT_TRUE(content::ExecuteScript(web_contents, click_fill_button_js));
const std::string fill_cc_number_js =
"(function() { document.getElementsByName(\"cc_number\")[0].value = " +
card_number + "; })();";
ASSERT_TRUE(content::ExecuteScript(web_contents, fill_cc_number_js));
const std::string click_submit_button_js =
"(function() { document.getElementById('submit').click(); })();";
content::TestNavigationObserver nav_observer(web_contents);
ASSERT_TRUE(content::ExecuteScript(web_contents, click_submit_button_js));
nav_observer.Wait();
}
void LocalCardMigrationBrowserTestBase::SetUploadDetailsRpcPaymentsAccepts() {
test_url_loader_factory()->AddResponse(kURLGetUploadDetailsRequest,
kResponseGetUploadDetailsSuccess);
}
void LocalCardMigrationBrowserTestBase::SetUploadDetailsRpcPaymentsDeclines() {
test_url_loader_factory()->AddResponse(kURLGetUploadDetailsRequest,
kResponseGetUploadDetailsFailure);
}
void LocalCardMigrationBrowserTestBase::ClickOnView(views::View* view) {
DCHECK(view);
ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
view->OnMousePressed(pressed);
ui::MouseEvent released_event = ui::MouseEvent(
ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
view->OnMouseReleased(released_event);
}
void LocalCardMigrationBrowserTestBase::ClickOnDialogViewAndWait(
views::View* view,
views::DialogDelegateView* local_card_migration_view) {
DCHECK(local_card_migration_view);
views::test::WidgetDestroyedWaiter destroyed_waiter(
local_card_migration_view->GetWidget());
local_card_migration_view->GetDialogClientView()
->ResetViewShownTimeStampForTesting();
views::BubbleFrameView* bubble_frame_view =
static_cast<views::BubbleFrameView*>(
local_card_migration_view->GetWidget()
->non_client_view()
->frame_view());
bubble_frame_view->ResetViewShownTimeStampForTesting();
ClickOnView(view);
destroyed_waiter.Wait();
}
views::View* LocalCardMigrationBrowserTestBase::FindViewInDialogById(
DialogViewId view_id,
views::DialogDelegateView* local_card_migration_view) {
DCHECK(local_card_migration_view);
views::View* specified_view =
local_card_migration_view->GetViewByID(static_cast<int>(view_id));
if (!specified_view) {
specified_view =
local_card_migration_view->GetDialogClientView()->GetViewByID(
static_cast<int>(view_id));
}
return specified_view;
}
void LocalCardMigrationBrowserTestBase::ClickOnOkButton(
views::DialogDelegateView* local_card_migration_view) {
views::View* ok_button =
local_card_migration_view->GetDialogClientView()->ok_button();
ClickOnDialogViewAndWait(ok_button, local_card_migration_view);
}
void LocalCardMigrationBrowserTestBase::ClickOnCancelButton(
views::DialogDelegateView* local_card_migration_view) {
views::View* cancel_button =
local_card_migration_view->GetDialogClientView()->cancel_button();
ClickOnDialogViewAndWait(cancel_button, local_card_migration_view);
}
views::DialogDelegateView*
LocalCardMigrationBrowserTestBase::GetLocalCardMigrationOfferBubbleViews() {
LocalCardMigrationBubbleControllerImpl*
local_card_migration_bubble_controller_impl =
LocalCardMigrationBubbleControllerImpl::FromWebContents(
GetActiveWebContents());
if (!local_card_migration_bubble_controller_impl)
return nullptr;
return static_cast<LocalCardMigrationBubbleViews*>(
local_card_migration_bubble_controller_impl
->local_card_migration_bubble_view());
}
views::DialogDelegateView*
LocalCardMigrationBrowserTestBase::GetLocalCardMigrationMainDialogView() {
LocalCardMigrationDialogControllerImpl*
local_card_migration_dialog_controller_impl =
LocalCardMigrationDialogControllerImpl::FromWebContents(
GetActiveWebContents());
if (!local_card_migration_dialog_controller_impl)
return nullptr;
return static_cast<LocalCardMigrationDialogView*>(
local_card_migration_dialog_controller_impl
->local_card_migration_dialog_view());
}
LocalCardMigrationIconView*
LocalCardMigrationBrowserTestBase::GetLocalCardMigrationIconView() {
if (!browser())
return nullptr;
LocationBarView* location_bar_view =
static_cast<LocationBarView*>(browser()->window()->GetLocationBar());
DCHECK(location_bar_view->local_card_migration_icon_view());
return location_bar_view->local_card_migration_icon_view();
}
views::View* LocalCardMigrationBrowserTestBase::GetCloseButton() {
LocalCardMigrationBubbleViews* local_card_migration_bubble_views =
static_cast<LocalCardMigrationBubbleViews*>(
GetLocalCardMigrationOfferBubbleViews());
DCHECK(local_card_migration_bubble_views);
return local_card_migration_bubble_views->GetBubbleFrameView()
->GetCloseButtonForTest();
}
views::View* LocalCardMigrationBrowserTestBase::GetCardListView() {
return static_cast<LocalCardMigrationDialogView*>(
GetLocalCardMigrationMainDialogView())
->card_list_view_;
}
content::WebContents*
LocalCardMigrationBrowserTestBase::GetActiveWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
void LocalCardMigrationBrowserTestBase::ResetEventWaiterForSequence(
std::list<DialogEvent> event_sequence) {
event_waiter_ =
std::make_unique<EventWaiter<DialogEvent>>(std::move(event_sequence));
}
void LocalCardMigrationBrowserTestBase::WaitForObservedEvent() {
event_waiter_->Wait();
}
network::TestURLLoaderFactory*
LocalCardMigrationBrowserTestBase::test_url_loader_factory() {
return &test_url_loader_factory_;
}
} // namespace autofill
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_BROWSERTEST_BASE_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_BROWSERTEST_BASE_H_
#include <list>
#include <memory>
#include <string>
#include "base/callback_list.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/views/autofill/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_bubble_views.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_dialog_view.h"
#include "chrome/browser/ui/views/autofill/local_card_migration_icon_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/credit_card_save_manager.h"
#include "components/autofill/core/browser/local_card_migration_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_event_waiter.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace device {
class ScopedGeolocationOverrider;
}
namespace autofill {
// Base class for any interactive LocalCardMigrationBubbleViews and
// LocalCardMigrationDialogView browser tests that will need to show and
// interact with the local card migration flow.
class LocalCardMigrationBrowserTestBase
: public InProcessBrowserTest,
public LocalCardMigrationManager::ObserverForTest {
protected:
// Various events that can be waited on by the DialogEventWaiter.
enum class DialogEvent : int {
REQUESTED_LOCAL_CARD_MIGRATION,
RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
SENT_MIGRATE_LOCAL_CARDS_REQUEST,
RECEIVED_MIGRATE_CARDS_RESPONSE
};
LocalCardMigrationBrowserTestBase();
~LocalCardMigrationBrowserTestBase() override;
void SetUpOnMainThread() override;
void NavigateTo(const std::string& file_path);
// LocalCardMigrationManager::ObserverForTest:
void OnDecideToRequestLocalCardMigration() override;
void OnReceivedGetUploadDetailsResponse() override;
void OnSentMigrateLocalCardsRequest() override;
void OnRecievedMigrateCardsResponse() override;
// BrowserTestBase:
void SetUpInProcessBrowserTestFixture() override;
// Sets up the ability to sign in the user.
void OnWillCreateBrowserContextServices(content::BrowserContext* context);
// Saves a local card.
void SaveLocalCard(std::string card_number);
// Saves a full server card.
void SaveServerCard(std::string card_number);
// Submits a checkout form with given card and waits for a migration offer.
void UseCardAndWaitForMigrationOffer(std::string card_number);
// 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.
void FillAndSubmitFormWithCard(std::string card_number);
// For setting up Payments RPCs.
void SetUploadDetailsRpcPaymentsAccepts();
void SetUploadDetailsRpcPaymentsDeclines();
// Clicks on the given views::View*.
void ClickOnView(views::View* view);
// Clicks on the given views::View* and resets the associated
// DialogDelegateView.
void ClickOnDialogViewAndWait(
views::View* view,
views::DialogDelegateView* local_card_migration_view);
// Returns the views::View* that was previously assigned the id |view_id|.
views::View* FindViewInDialogById(
DialogViewId view_id,
views::DialogDelegateView* local_card_migration_view);
// Clicks on dialog button in |local_card_migration_view|.
void ClickOnOkButton(views::DialogDelegateView* local_card_migration_view);
void ClickOnCancelButton(
views::DialogDelegateView* local_card_migration_view);
// Gets the views::DialogDelegateView* instance of the intermediate migration
// offer bubble.
views::DialogDelegateView* GetLocalCardMigrationOfferBubbleViews();
// Gets the views::DialogDelegateView* instance of the main migration dialog
// view.
views::DialogDelegateView* GetLocalCardMigrationMainDialogView();
// Gets the credit card icon in the omnibox.
LocalCardMigrationIconView* GetLocalCardMigrationIconView();
views::View* GetCloseButton();
views::View* GetCardListView();
content::WebContents* GetActiveWebContents();
// Resets the event waiter for a given |event_sequence|.
void ResetEventWaiterForSequence(std::list<DialogEvent> event_sequence);
// Wait for any events passed through ResetEventWaiterForSequence() to occur.
void WaitForObservedEvent();
network::TestURLLoaderFactory* test_url_loader_factory();
PersonalDataManager* personal_data_ = nullptr;
std::unique_ptr<
base::CallbackList<void(content::BrowserContext*)>::Subscription>
will_create_browser_context_services_subscription_;
base::test::ScopedFeatureList scoped_feature_list_;
private:
std::unique_ptr<autofill::EventWaiter<DialogEvent>> event_waiter_;
std::unique_ptr<net::FakeURLFetcherFactory> url_fetcher_factory_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;
std::unique_ptr<device::ScopedGeolocationOverrider> geolocation_overrider_;
DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationBrowserTestBase);
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_BROWSERTEST_BASE_H_
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <utility>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -30,7 +29,6 @@ ...@@ -30,7 +29,6 @@
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
#include "ui/views/window/dialog_client_view.h"
namespace autofill { namespace autofill {
...@@ -156,7 +154,6 @@ void LocalCardMigrationBubbleViews::Init() { ...@@ -156,7 +154,6 @@ void LocalCardMigrationBubbleViews::Init() {
explanatory_message->SetHorizontalAlignment(gfx::ALIGN_LEFT); explanatory_message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
explanatory_message->SetMultiLine(true); explanatory_message->SetMultiLine(true);
AddChildView(explanatory_message); AddChildView(explanatory_message);
set_id(DialogViewId::MAIN_CONTENT_VIEW_MIGRATION_BUBBLE);
} }
} // namespace autofill } // namespace autofill
...@@ -47,8 +47,6 @@ class LocalCardMigrationBubbleViews : public LocalCardMigrationBubble, ...@@ -47,8 +47,6 @@ class LocalCardMigrationBubbleViews : public LocalCardMigrationBubble,
void WindowClosing() override; void WindowClosing() override;
private: private:
friend class LocalCardMigrationBrowserTestBase;
~LocalCardMigrationBubbleViews() override; ~LocalCardMigrationBubbleViews() override;
// views::BubbleDialogDelegateView: // views::BubbleDialogDelegateView:
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
#include "chrome/browser/ui/views/autofill/local_card_migration_dialog_view.h" #include "chrome/browser/ui/views/autofill/local_card_migration_dialog_view.h"
#include <memory>
#include <string>
#include <vector>
#include "base/location.h" #include "base/location.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -283,8 +279,6 @@ class LocalCardMigrationOfferView : public views::View, ...@@ -283,8 +279,6 @@ class LocalCardMigrationOfferView : public views::View,
} }
private: private:
friend class LocalCardMigrationDialogView;
LocalCardMigrationDialogController* controller_; LocalCardMigrationDialogController* controller_;
views::View* card_list_view_ = nullptr; views::View* card_list_view_ = nullptr;
...@@ -412,8 +406,6 @@ void LocalCardMigrationDialogView::Init() { ...@@ -412,8 +406,6 @@ void LocalCardMigrationDialogView::Init() {
if (controller_->GetViewState() == LocalCardMigrationDialogState::kOffered) { if (controller_->GetViewState() == LocalCardMigrationDialogState::kOffered) {
offer_view_ = new LocalCardMigrationOfferView(controller_, this); offer_view_ = new LocalCardMigrationOfferView(controller_, this);
offer_view_->set_id(DialogViewId::MAIN_CONTENT_VIEW_MIGRATION_OFFER_DIALOG);
card_list_view_ = offer_view_->card_list_view_;
AddChildView(offer_view_); AddChildView(offer_view_);
} else { } else {
AddChildView(CreateFeedbackContentView(controller_, this).release()); AddChildView(CreateFeedbackContentView(controller_, this).release());
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_
#include <string>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog.h" #include "chrome/browser/ui/autofill/local_card_migration_dialog.h"
#include "chrome/browser/ui/views/autofill/dialog_view_ids.h" #include "chrome/browser/ui/views/autofill/dialog_view_ids.h"
...@@ -53,8 +50,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog, ...@@ -53,8 +50,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
friend class LocalCardMigrationBrowserTestBase;
base::string16 GetOkButtonLabel() const; base::string16 GetOkButtonLabel() const;
base::string16 GetCancelButtonLabel() const; base::string16 GetCancelButtonLabel() const;
...@@ -66,8 +61,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog, ...@@ -66,8 +61,6 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
// dialog is not in the 'offer' state. // dialog is not in the 'offer' state.
LocalCardMigrationOfferView* offer_view_ = nullptr; LocalCardMigrationOfferView* offer_view_ = nullptr;
views::View* card_list_view_;
DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationDialogView); DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationDialogView);
}; };
......
...@@ -1499,9 +1499,6 @@ test("browser_tests") { ...@@ -1499,9 +1499,6 @@ test("browser_tests") {
"../browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc", "../browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc",
"../browser/ui/views/autofill/card_unmask_prompt_view_tester_views.cc", "../browser/ui/views/autofill/card_unmask_prompt_view_tester_views.cc",
"../browser/ui/views/autofill/card_unmask_prompt_view_tester_views.h", "../browser/ui/views/autofill/card_unmask_prompt_view_tester_views.h",
"../browser/ui/views/autofill/local_card_migration_browsertest.cc",
"../browser/ui/views/autofill/local_card_migration_browsertest_base.cc",
"../browser/ui/views/autofill/local_card_migration_browsertest_base.h",
"../browser/ui/views/autofill/save_card_bubble_views_browsertest.cc", "../browser/ui/views/autofill/save_card_bubble_views_browsertest.cc",
"../browser/ui/views/autofill/save_card_bubble_views_browsertest_base.cc", "../browser/ui/views/autofill/save_card_bubble_views_browsertest_base.cc",
"../browser/ui/views/autofill/save_card_bubble_views_browsertest_base.h", "../browser/ui/views/autofill/save_card_bubble_views_browsertest_base.h",
......
...@@ -123,7 +123,6 @@ class CreditCardSaveManager { ...@@ -123,7 +123,6 @@ class CreditCardSaveManager {
private: private:
friend class CreditCardSaveManagerTest; friend class CreditCardSaveManagerTest;
friend class CreditCardSaveManagerTestObserverBridge; friend class CreditCardSaveManagerTestObserverBridge;
friend class LocalCardMigrationBrowserTestBase;
friend class SaveCardBubbleViewsBrowserTestBase; friend class SaveCardBubbleViewsBrowserTestBase;
// Sets |show_save_prompt| and moves forward with offering credit card local // Sets |show_save_prompt| and moves forward with offering credit card local
......
...@@ -145,7 +145,6 @@ class FormDataImporter { ...@@ -145,7 +145,6 @@ class FormDataImporter {
friend class AutofillMergeTest; friend class AutofillMergeTest;
friend class FormDataImporterTest; friend class FormDataImporterTest;
friend class FormDataImporterTestBase; friend class FormDataImporterTestBase;
friend class LocalCardMigrationBrowserTestBase;
friend class SaveCardBubbleViewsBrowserTestBase; friend class SaveCardBubbleViewsBrowserTestBase;
friend class SaveCardInfobarEGTestHelper; friend class SaveCardInfobarEGTestHelper;
FRIEND_TEST_ALL_PREFIXES(AutofillMergeTest, MergeProfiles); FRIEND_TEST_ALL_PREFIXES(AutofillMergeTest, MergeProfiles);
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm> #include <algorithm>
#include <unordered_map>
#include <utility>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
...@@ -90,8 +88,6 @@ void LocalCardMigrationManager::AttemptToOfferLocalCardMigration( ...@@ -90,8 +88,6 @@ void LocalCardMigrationManager::AttemptToOfferLocalCardMigration(
return; return;
migration_request_ = payments::PaymentsClient::MigrationRequestDetails(); migration_request_ = payments::PaymentsClient::MigrationRequestDetails();
if (observer_for_testing_)
observer_for_testing_->OnDecideToRequestLocalCardMigration();
payments_client_->GetUploadDetails( payments_client_->GetUploadDetails(
std::vector<AutofillProfile>(), GetDetectedValues(), std::vector<AutofillProfile>(), GetDetectedValues(),
/*active_experiments=*/std::vector<const char*>(), app_locale_, /*active_experiments=*/std::vector<const char*>(), app_locale_,
...@@ -143,19 +139,12 @@ bool LocalCardMigrationManager::IsCreditCardMigrationEnabled() { ...@@ -143,19 +139,12 @@ bool LocalCardMigrationManager::IsCreditCardMigrationEnabled() {
bool migration_experiment_enabled = bool migration_experiment_enabled =
features::GetLocalCardMigrationExperimentalFlag() != features::GetLocalCardMigrationExperimentalFlag() !=
features::LocalCardMigrationExperimentalFlag::kMigrationDisabled; features::LocalCardMigrationExperimentalFlag::kMigrationDisabled;
// If |observer_for_testing_| is set, assume we are in a browsertest and bool credit_card_upload_enabled = ::autofill::IsCreditCardUploadEnabled(
// credit card upload should be enabled by default. Cannot get around this as client_->GetPrefs(), client_->GetSyncService(),
// Chrome OS testing requires an unsupported email domain (i.e. client_->GetIdentityManager()->GetPrimaryAccountInfo().email);
// stub-user@example.com).
bool credit_card_upload_enabled =
observer_for_testing_ ||
::autofill::IsCreditCardUploadEnabled(
client_->GetPrefs(), client_->GetSyncService(),
client_->GetIdentityManager()->GetPrimaryAccountInfo().email);
bool has_google_payments_account = bool has_google_payments_account =
(payments::GetBillingCustomerId(personal_data_manager_, (payments::GetBillingCustomerId(personal_data_manager_,
payments_client_->GetPrefService()) != 0); payments_client_->GetPrefService()) != 0);
return migration_experiment_enabled && credit_card_upload_enabled && return migration_experiment_enabled && credit_card_upload_enabled &&
has_google_payments_account; has_google_payments_account;
} }
...@@ -165,8 +154,6 @@ void LocalCardMigrationManager::OnDidGetUploadDetails( ...@@ -165,8 +154,6 @@ void LocalCardMigrationManager::OnDidGetUploadDetails(
AutofillClient::PaymentsRpcResult result, AutofillClient::PaymentsRpcResult result,
const base::string16& context_token, const base::string16& context_token,
std::unique_ptr<base::DictionaryValue> legal_message) { std::unique_ptr<base::DictionaryValue> legal_message) {
if (observer_for_testing_)
observer_for_testing_->OnReceivedGetUploadDetailsResponse();
if (result == AutofillClient::SUCCESS) { if (result == AutofillClient::SUCCESS) {
migration_request_.context_token = context_token; migration_request_.context_token = context_token;
legal_message_ = std::move(legal_message); legal_message_ = std::move(legal_message);
...@@ -200,8 +187,6 @@ void LocalCardMigrationManager::OnDidMigrateLocalCards( ...@@ -200,8 +187,6 @@ void LocalCardMigrationManager::OnDidMigrateLocalCards(
AutofillClient::PaymentsRpcResult result, AutofillClient::PaymentsRpcResult result,
std::unique_ptr<std::unordered_map<std::string, std::string>> save_result, std::unique_ptr<std::unordered_map<std::string, std::string>> save_result,
const std::string& display_text) { const std::string& display_text) {
if (observer_for_testing_)
observer_for_testing_->OnRecievedMigrateCardsResponse();
if (!save_result) if (!save_result)
return; return;
...@@ -253,8 +238,6 @@ void LocalCardMigrationManager::OnDidGetMigrationRiskData( ...@@ -253,8 +238,6 @@ void LocalCardMigrationManager::OnDidGetMigrationRiskData(
// Send the migration request. Will call payments_client to create a new // Send the migration request. Will call payments_client to create a new
// PaymentsRequest. Also create a new callback function OnDidMigrateLocalCards. // PaymentsRequest. Also create a new callback function OnDidMigrateLocalCards.
void LocalCardMigrationManager::SendMigrateLocalCardsRequest() { void LocalCardMigrationManager::SendMigrateLocalCardsRequest() {
if (observer_for_testing_)
observer_for_testing_->OnSentMigrateLocalCardsRequest();
migration_request_.app_locale = app_locale_; migration_request_.app_locale = app_locale_;
migration_request_.billing_customer_number = payments::GetBillingCustomerId( migration_request_.billing_customer_number = payments::GetBillingCustomerId(
personal_data_manager_, payments_client_->GetPrefService()); personal_data_manager_, payments_client_->GetPrefService());
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map>
#include <vector> #include <vector>
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -46,7 +45,7 @@ class MigratableCreditCard { ...@@ -46,7 +45,7 @@ class MigratableCreditCard {
FAILURE_ON_UPLOAD, FAILURE_ON_UPLOAD,
}; };
explicit MigratableCreditCard(const CreditCard& credit_card); MigratableCreditCard(const CreditCard& credit_card);
~MigratableCreditCard(); ~MigratableCreditCard();
CreditCard credit_card() const { return credit_card_; } CreditCard credit_card() const { return credit_card_; }
...@@ -69,16 +68,6 @@ class MigratableCreditCard { ...@@ -69,16 +68,6 @@ class MigratableCreditCard {
// Owned by FormDataImporter. // Owned by FormDataImporter.
class LocalCardMigrationManager { class LocalCardMigrationManager {
public: public:
// An observer class used by browsertests that gets notified whenever
// particular actions occur.
class ObserverForTest {
public:
virtual void OnDecideToRequestLocalCardMigration() = 0;
virtual void OnReceivedGetUploadDetailsResponse() = 0;
virtual void OnSentMigrateLocalCardsRequest() = 0;
virtual void OnRecievedMigrateCardsResponse() = 0;
};
// The parameters should outlive the LocalCardMigrationManager. // The parameters should outlive the LocalCardMigrationManager.
LocalCardMigrationManager(AutofillClient* client, LocalCardMigrationManager(AutofillClient* client,
payments::PaymentsClient* payments_client, payments::PaymentsClient* payments_client,
...@@ -110,6 +99,10 @@ class LocalCardMigrationManager { ...@@ -110,6 +99,10 @@ class LocalCardMigrationManager {
virtual void OnUserAcceptedMainMigrationDialog( virtual void OnUserAcceptedMainMigrationDialog(
const std::vector<std::string>& selected_card_guids); const std::vector<std::string>& selected_card_guids);
// Check that the user is signed in, syncing, and the proper experiment
// flags are enabled. Override in the test class.
virtual bool IsCreditCardMigrationEnabled();
// Determines what detected_values metadata to send (generally, cardholder // Determines what detected_values metadata to send (generally, cardholder
// name if it exists on all cards, and existence of Payments customer). // name if it exists on all cards, and existence of Payments customer).
int GetDetectedValues() const; int GetDetectedValues() const;
...@@ -144,7 +137,6 @@ class LocalCardMigrationManager { ...@@ -144,7 +137,6 @@ class LocalCardMigrationManager {
payments::PaymentsClient* payments_client_; payments::PaymentsClient* payments_client_;
private: private:
friend class LocalCardMigrationBrowserTestBase;
FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest, FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest,
MigrateCreditCard_MigrationPermanentFailure); MigrateCreditCard_MigrationPermanentFailure);
FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest, FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest,
...@@ -154,10 +146,6 @@ class LocalCardMigrationManager { ...@@ -154,10 +146,6 @@ class LocalCardMigrationManager {
FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest, FRIEND_TEST_ALL_PREFIXES(LocalCardMigrationManagerTest,
MigrateCreditCard_ToggleIsChosen); MigrateCreditCard_ToggleIsChosen);
// Check that the user is signed in, syncing, and the proper experiment
// flags are enabled. Override in the test class.
virtual bool IsCreditCardMigrationEnabled();
// Pops up a larger, modal dialog showing the local cards to be uploaded. // Pops up a larger, modal dialog showing the local cards to be uploaded.
void ShowMainMigrationDialog(); void ShowMainMigrationDialog();
...@@ -169,11 +157,6 @@ class LocalCardMigrationManager { ...@@ -169,11 +157,6 @@ class LocalCardMigrationManager {
// Finalizes the migration request and calls PaymentsClient. // Finalizes the migration request and calls PaymentsClient.
void SendMigrateLocalCardsRequest(); void SendMigrateLocalCardsRequest();
// For testing.
void SetEventObserverForTesting(ObserverForTest* observer) {
observer_for_testing_ = observer;
}
std::unique_ptr<base::DictionaryValue> legal_message_; std::unique_ptr<base::DictionaryValue> legal_message_;
std::string app_locale_; std::string app_locale_;
...@@ -200,9 +183,6 @@ class LocalCardMigrationManager { ...@@ -200,9 +183,6 @@ class LocalCardMigrationManager {
// Record the triggering source of the local card migration. // Record the triggering source of the local card migration.
AutofillMetrics::LocalCardMigrationOrigin local_card_migration_origin_; AutofillMetrics::LocalCardMigrationOrigin local_card_migration_origin_;
// Initialized only during tests.
ObserverForTest* observer_for_testing_ = nullptr;
base::WeakPtrFactory<LocalCardMigrationManager> weak_ptr_factory_; base::WeakPtrFactory<LocalCardMigrationManager> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationManager); DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationManager);
......
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