diff options
author | benquan@chromium.org <benquan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 05:18:32 +0000 |
---|---|---|
committer | benquan@chromium.org <benquan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 05:18:32 +0000 |
commit | dd167bd80345aba642d2ea62542711543cf97142 (patch) | |
tree | 51796b22a2c8d4163c3fb5f9f9ea5ee99852a7d1 | |
parent | a5645eda8c557e66d67b2d09aa0b0a82d3850301 (diff) | |
download | chromium_src-dd167bd80345aba642d2ea62542711543cf97142.zip chromium_src-dd167bd80345aba642d2ea62542711543cf97142.tar.gz chromium_src-dd167bd80345aba642d2ea62542711543cf97142.tar.bz2 |
Make the rAc dialog stay for Autocheckout when it clicks on proceed button on the last page.
When there is a proceed element on the last page of Autocheckout flow, it will load the confirmation page which we do not have filemap for, so |TabAutofillManagerDelegate::DidNavigateMainFrame| will close the dialog. This CL added |AutofillManagerDelegate::InAutochekoutFlow()|, which will be called by |AutocheckoutManager| to explicitly notify the delegate if we are currently in an Autocheckout flow, and it should not close the dialog if the flow is not ended yet.
BUG=260062
Review URL: https://chromiumcodereview.appspot.com/19304003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212529 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 203 insertions, 109 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index dd5be52..fece240 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -624,10 +624,6 @@ void AutofillDialogControllerImpl::Hide() { view_->Hide(); } -bool AutofillDialogControllerImpl::AutocheckoutIsRunning() const { - return autocheckout_state_ == AUTOCHECKOUT_IN_PROGRESS; -} - void AutofillDialogControllerImpl::OnAutocheckoutError() { DCHECK_EQ(AUTOCHECKOUT_IN_PROGRESS, autocheckout_state_); GetMetricLogger().LogAutocheckoutDuration( diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h index 772174b..88a1c01 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h @@ -92,9 +92,6 @@ class AutofillDialogControllerImpl : public AutofillDialogController, void Show(); void Hide(); - // Whether Autocheckout is currently running. - bool AutocheckoutIsRunning() const; - // Adds a step in the flow to the Autocheckout UI. void AddAutocheckoutStep(AutocheckoutStepType step_type); @@ -313,6 +310,8 @@ class AutofillDialogControllerImpl : public AutofillDialogController, // to the requesting site. virtual bool TransmissionWillBeSecure() const; + AutocheckoutState autocheckout_state() const { return autocheckout_state_; } + private: // Whether or not the current request wants credit info back. bool RequestingCreditCardInfo() const; diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 5dc6cdf..8e694c3 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -238,6 +238,10 @@ class TestAutofillDialogController OnWalletSigninError(); } + bool AutocheckoutIsRunning() const { + return AUTOCHECKOUT_IN_PROGRESS == autocheckout_state(); + } + MOCK_METHOD0(LoadRiskFingerprintData, void()); using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; using AutofillDialogControllerImpl::IsEditingExistingData; diff --git a/chrome/browser/ui/autofill/autofill_dialog_types.h b/chrome/browser/ui/autofill/autofill_dialog_types.h index 26df627..c67a88b 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_types.h +++ b/chrome/browser/ui/autofill/autofill_dialog_types.h @@ -173,7 +173,7 @@ enum AutocheckoutState { AUTOCHECKOUT_ERROR, // There was an error in the flow. AUTOCHECKOUT_IN_PROGRESS, // The flow is currently in. AUTOCHECKOUT_NOT_STARTED, // The flow has not been initiated by the user yet. - AUTOCHECKOUT_SUCCESS, // The flow completed successsfully. + AUTOCHECKOUT_SUCCESS, // The flow completed successfully. }; struct SuggestionState { diff --git a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc index 59e5556..44603d9 100644 --- a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc +++ b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc @@ -20,6 +20,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/common/url_constants.h" +#include "components/autofill/content/browser/autofill_driver_impl.h" #include "components/autofill/core/common/autofill_pref_names.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" @@ -203,17 +204,23 @@ void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() { void TabAutofillManagerDelegate::DidNavigateMainFrame( const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) { + + HideAutocheckoutBubble(); + + if (!dialog_controller_.get()) + return; + // A redirect immediately after a successful Autocheckout flow shouldn't hide // the dialog. + bool preserve_dialog = AutofillDriverImpl::FromWebContents(web_contents())-> + autofill_manager()->autocheckout_manager()->should_preserve_dialog(); bool was_redirect = details.entry && content::PageTransitionIsRedirect(details.entry->GetTransitionType()); - if (dialog_controller_.get() && - (dialog_controller_->dialog_type() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE || - (!dialog_controller_->AutocheckoutIsRunning() && !was_redirect))) { + + if (dialog_controller_->dialog_type() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE || + (!was_redirect && !preserve_dialog)) { HideRequestAutocompleteDialog(); } - - HideAutocheckoutBubble(); } void TabAutofillManagerDelegate::WebContentsDestroyed( diff --git a/components/autofill/content/browser/autocheckout_manager.cc b/components/autofill/content/browser/autocheckout_manager.cc index 4f2455d..ae788ce 100644 --- a/components/autofill/content/browser/autocheckout_manager.cc +++ b/components/autofill/content/browser/autocheckout_manager.cc @@ -156,6 +156,7 @@ AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) should_show_bubble_(true), is_autocheckout_bubble_showing_(false), in_autocheckout_flow_(false), + should_preserve_dialog_(false), google_transaction_id_(kTransactionIdNotSet), weak_ptr_factory_(this) {} @@ -203,12 +204,13 @@ void AutocheckoutManager::FillForms() { void AutocheckoutManager::OnAutocheckoutPageCompleted( AutocheckoutStatus status) { + if (!in_autocheckout_flow_) + return; + DVLOG(2) << "OnAutocheckoutPageCompleted, page_no: " << page_meta_data_->current_page_number << " status: " << status; - if (!in_autocheckout_flow_) - return; DCHECK_NE(MISSING_FIELDMAPPING, status); @@ -226,6 +228,18 @@ void AutocheckoutManager::OnLoadedPageMetaData( scoped_ptr<AutocheckoutPageMetaData> old_meta_data = page_meta_data_.Pass(); page_meta_data_ = page_meta_data.Pass(); + // If there is no click element in the last page, then it's the real last page + // of the flow, and the dialog will be closed when the page navigates. + // Otherwise, the dialog should be preserved for the page loaded by the click + // element on the last page of the flow. + // Note, |should_preserve_dialog_| has to be computed at this point because + // |in_autocheckout_flow_| may change after |OnLoadedPageMetaData| is called. + should_preserve_dialog_ = in_autocheckout_flow_ || + (old_meta_data.get() && + old_meta_data->IsEndOfAutofillableFlow() && + old_meta_data->proceed_element_descriptor.retrieval_method != + WebElementDescriptor::NONE); + // Don't log that the bubble could be displayed if the user entered an // Autocheckout flow and sees the first page of the flow again due to an // error. @@ -319,6 +333,9 @@ void AutocheckoutManager::ReturnAutocheckoutData( const FormStructure* result, const std::string& google_transaction_id) { if (!result) { + // When user cancels the dialog, |result| is NULL. + // TODO(): add AutocheckoutStatus.USER_CANCELLED, and call + // EndAutocheckout(USER_CANCELLED) instead. in_autocheckout_flow_ = false; return; } @@ -327,6 +344,7 @@ void AutocheckoutManager::ReturnAutocheckoutData( last_step_completion_timestamp_ = base::TimeTicks().Now(); google_transaction_id_ = google_transaction_id; in_autocheckout_flow_ = true; + should_preserve_dialog_ = true; metric_logger_->LogAutocheckoutBuyFlowMetric( AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_STARTED); diff --git a/components/autofill/content/browser/autocheckout_manager.h b/components/autofill/content/browser/autocheckout_manager.h index 9c98172..b265d8e 100644 --- a/components/autofill/content/browser/autocheckout_manager.h +++ b/components/autofill/content/browser/autocheckout_manager.h @@ -72,6 +72,9 @@ class AutocheckoutManager { virtual void MaybeShowAutocheckoutBubble(const GURL& frame_url, const gfx::RectF& bounding_box); + // Determine whether we should keep the dialog visible. + bool should_preserve_dialog() const { return should_preserve_dialog_; } + void set_should_show_bubble(bool should_show_bubble) { should_show_bubble_ = should_show_bubble; } @@ -147,7 +150,7 @@ class AutocheckoutManager { // Billing address built using data supplied by requestAutocomplete dialog. scoped_ptr<AutofillProfile> billing_address_; - // Autocheckout specific page meta data. + // Autocheckout specific page meta data of current page. scoped_ptr<AutocheckoutPageMetaData> page_meta_data_; scoped_ptr<AutofillMetrics> metric_logger_; @@ -161,6 +164,10 @@ class AutocheckoutManager { // Whether or not the user is in an Autocheckout flow. bool in_autocheckout_flow_; + // Whether or not the currently visible dialog, if there is one, should be + // preserved. + bool should_preserve_dialog_; + // AutocheckoutStepTypes for the various pages of the flow. std::map<int, std::vector<AutocheckoutStepType> > page_types_; diff --git a/components/autofill/content/browser/autocheckout_manager_unittest.cc b/components/autofill/content/browser/autocheckout_manager_unittest.cc index b7ff8cd..e5d5aa5 100644 --- a/components/autofill/content/browser/autocheckout_manager_unittest.cc +++ b/components/autofill/content/browser/autocheckout_manager_unittest.cc @@ -36,6 +36,11 @@ typedef Tuple4<std::vector<FormData>, std::vector<WebElementDescriptor>, WebElementDescriptor> AutofillParam; +enum ProceedElementPresence { + NO_PROCEED_ELEMENT, + HAS_PROCEED_ELEMENT, +}; + FormFieldData BuildFieldWithValue( const std::string& autocomplete_attribute, const std::string& value) { @@ -169,16 +174,19 @@ scoped_ptr<AutocheckoutPageMetaData> CreateNotInFlowMetaData() { return not_in_flow.Pass(); } -scoped_ptr<AutocheckoutPageMetaData> CreateEndOfFlowMetaData() { +scoped_ptr<AutocheckoutPageMetaData> CreateEndOfFlowMetaData( + ProceedElementPresence proceed_element_presence) { scoped_ptr<AutocheckoutPageMetaData> end_of_flow( new AutocheckoutPageMetaData()); end_of_flow->current_page_number = 2; end_of_flow->total_pages = 3; - PopulateClickElement(&end_of_flow->proceed_element_descriptor, "#foo"); + if (proceed_element_presence == HAS_PROCEED_ELEMENT) + PopulateClickElement(&end_of_flow->proceed_element_descriptor, "#foo"); return end_of_flow.Pass(); } -scoped_ptr<AutocheckoutPageMetaData> CreateOnePageFlowMetaData() { +scoped_ptr<AutocheckoutPageMetaData> CreateOnePageFlowMetaData( + ProceedElementPresence proceed_element_presence) { scoped_ptr<AutocheckoutPageMetaData> one_page_flow( new AutocheckoutPageMetaData()); one_page_flow->current_page_number = 0; @@ -186,7 +194,8 @@ scoped_ptr<AutocheckoutPageMetaData> CreateOnePageFlowMetaData() { one_page_flow->page_types[0].push_back(AUTOCHECKOUT_STEP_SHIPPING); one_page_flow->page_types[0].push_back(AUTOCHECKOUT_STEP_DELIVERY); one_page_flow->page_types[0].push_back(AUTOCHECKOUT_STEP_BILLING); - PopulateClickElement(&one_page_flow->proceed_element_descriptor, "#foo"); + if (proceed_element_presence == HAS_PROCEED_ELEMENT) + PopulateClickElement(&one_page_flow->proceed_element_descriptor, "#foo"); return one_page_flow.Pass(); } @@ -436,7 +445,8 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { return autofill_param.a; } - void CheckFillFormsAndClickIpc() { + void CheckFillFormsAndClickIpc( + ProceedElementPresence proceed_element_presence) { EXPECT_EQ(1U, process()->sink().message_count()); uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; const IPC::Message* message = @@ -444,8 +454,12 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { EXPECT_TRUE(message); AutofillParam autofill_param; AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); - EXPECT_EQ(WebElementDescriptor::ID, autofill_param.d.retrieval_method); - EXPECT_EQ("#foo", autofill_param.d.descriptor); + if (proceed_element_presence == HAS_PROCEED_ELEMENT) { + EXPECT_EQ(WebElementDescriptor::ID, autofill_param.d.retrieval_method); + EXPECT_EQ("#foo", autofill_param.d.descriptor); + } else { + EXPECT_EQ(WebElementDescriptor::NONE, autofill_param.d.retrieval_method); + } ClearIpcSink(); } @@ -471,8 +485,9 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { autocheckout_manager_->MaybeShowAutocheckoutDialog( frame_url, AUTOCHECKOUT_BUBBLE_ACCEPTED); - CheckFillFormsAndClickIpc(); + CheckFillFormsAndClickIpc(HAS_PROCEED_ELEMENT); EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); EXPECT_TRUE(autofill_manager_delegate_ ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, @@ -493,6 +508,120 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { autofill_manager_delegate_->request_autocomplete_dialog_open()); } + // Test a multi-page Autocheckout flow end to end. + // |proceed_element_presence_on_last_page| indicates whether the last page + // of the flow should have a proceed element. + void TestFullAutocheckoutFlow( + ProceedElementPresence proceed_element_presence_on_last_page) { + // Test for progression through last page. + OpenRequestAutocompleteDialog(); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, + AUTOCHECKOUT_STEP_STARTED)); + // Complete the first page. + autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, + AUTOCHECKOUT_STEP_COMPLETED)); + + // Go to the second page. + EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutSuccess()).Times(1); + autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); + EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); + CheckFillFormsAndClickIpc(HAS_PROCEED_ELEMENT); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, + AUTOCHECKOUT_STEP_STARTED)); + autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, + AUTOCHECKOUT_STEP_COMPLETED)); + + // Go to the third page. + EXPECT_CALL(autocheckout_manager_->metric_logger(), + LogAutocheckoutBuyFlowMetric( + AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); + autocheckout_manager_->OnLoadedPageMetaData( + CreateEndOfFlowMetaData(proceed_element_presence_on_last_page)); + CheckFillFormsAndClickIpc(proceed_element_presence_on_last_page); + EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, + AUTOCHECKOUT_STEP_STARTED)); + autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); + EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, + AUTOCHECKOUT_STEP_COMPLETED)); + + EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); + + // Go to the page after the flow. + autocheckout_manager_->OnLoadedPageMetaData( + scoped_ptr<AutocheckoutPageMetaData>()); + EXPECT_EQ(proceed_element_presence_on_last_page == HAS_PROCEED_ELEMENT, + autocheckout_manager_->should_preserve_dialog()); + // Go to another page and we should not preserve the dialog now. + autocheckout_manager_->OnLoadedPageMetaData( + scoped_ptr<AutocheckoutPageMetaData>()); + EXPECT_FALSE(autocheckout_manager_->should_preserve_dialog()); + } + + // Test a signle-page Autocheckout flow. |proceed_element_presence| indicates + // whether the page should have a proceed element. + void TestSinglePageFlow(ProceedElementPresence proceed_element_presence) { + // Test one page flow. + EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_FALSE( + autofill_manager_delegate_->request_autocomplete_dialog_open()); + EXPECT_CALL(autocheckout_manager_->metric_logger(), + LogAutocheckoutBubbleMetric( + AutofillMetrics::BUBBLE_COULD_BE_DISPLAYED)).Times(1); + EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutSuccess()).Times(1); + autocheckout_manager_->OnLoadedPageMetaData( + CreateOnePageFlowMetaData(proceed_element_presence)); + // Simulate the user submitting some data via the requestAutocomplete UI. + autofill_manager_delegate_->SetUserSuppliedData( + FakeUserSubmittedFormStructure()); + GURL frame_url; + EXPECT_CALL(autocheckout_manager_->metric_logger(), + LogAutocheckoutBuyFlowMetric( + AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_STARTED)).Times(1); + EXPECT_CALL(autocheckout_manager_->metric_logger(), + LogAutocheckoutBuyFlowMetric( + AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); + autocheckout_manager_->MaybeShowAutocheckoutDialog( + frame_url, + AUTOCHECKOUT_BUBBLE_ACCEPTED); + autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); + CheckFillFormsAndClickIpc(proceed_element_presence); + EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); + EXPECT_TRUE(autocheckout_manager_->should_preserve_dialog()); + EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, + AUTOCHECKOUT_STEP_COMPLETED)); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, + AUTOCHECKOUT_STEP_COMPLETED)); + EXPECT_TRUE(autofill_manager_delegate_ + ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, + AUTOCHECKOUT_STEP_COMPLETED)); + // Go to the page after the flow. + autocheckout_manager_->OnLoadedPageMetaData( + scoped_ptr<AutocheckoutPageMetaData>()); + EXPECT_EQ(proceed_element_presence == HAS_PROCEED_ELEMENT, + autocheckout_manager_->should_preserve_dialog()); + // Go to another page, and we should not preserve the dialog now. + autocheckout_manager_->OnLoadedPageMetaData( + scoped_ptr<AutocheckoutPageMetaData>()); + EXPECT_FALSE(autocheckout_manager_->should_preserve_dialog()); + } + protected: scoped_ptr<TestAutofillDriver> autofill_driver_; scoped_ptr<TestAutofillManager> autofill_manager_; @@ -694,7 +823,7 @@ TEST_F(AutocheckoutManagerTest, OnLoadedPageMetaDataRepeatedPage) { // Go to second page. autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); - CheckFillFormsAndClickIpc(); + CheckFillFormsAndClickIpc(HAS_PROCEED_ELEMENT); EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); EXPECT_CALL( autocheckout_manager_->metric_logger(), @@ -716,7 +845,7 @@ TEST_F(AutocheckoutManagerTest, OnLoadedPageMetaDataNotInFlow) { // Go to second page. autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); - CheckFillFormsAndClickIpc(); + CheckFillFormsAndClickIpc(HAS_PROCEED_ELEMENT); EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); EXPECT_CALL( autocheckout_manager_->metric_logger(), @@ -746,47 +875,11 @@ TEST_F(AutocheckoutManagerTest, } TEST_F(AutocheckoutManagerTest, FullAutocheckoutFlow) { - // Test for progression through last page. - OpenRequestAutocompleteDialog(); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, - AUTOCHECKOUT_STEP_STARTED)); - // Complete the first page. - autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, - AUTOCHECKOUT_STEP_COMPLETED)); - - // Go to the second page. - EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutSuccess()).Times(1); - autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); - EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); - CheckFillFormsAndClickIpc(); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, - AUTOCHECKOUT_STEP_STARTED)); - autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, - AUTOCHECKOUT_STEP_COMPLETED)); - - // Go to the third page. - EXPECT_CALL(autocheckout_manager_->metric_logger(), - LogAutocheckoutBuyFlowMetric( - AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); - autocheckout_manager_->OnLoadedPageMetaData(CreateEndOfFlowMetaData()); - CheckFillFormsAndClickIpc(); - EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, - AUTOCHECKOUT_STEP_STARTED)); - autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); - EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, - AUTOCHECKOUT_STEP_COMPLETED)); + TestFullAutocheckoutFlow(HAS_PROCEED_ELEMENT); +} - EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); +TEST_F(AutocheckoutManagerTest, FullAutocheckoutFlowNoClickOnLastPage) { + TestFullAutocheckoutFlow(NO_PROCEED_ELEMENT); } TEST_F(AutocheckoutManagerTest, CancelledAutocheckoutFlow) { @@ -795,7 +888,7 @@ TEST_F(AutocheckoutManagerTest, CancelledAutocheckoutFlow) { // Go to second page. autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); - CheckFillFormsAndClickIpc(); + CheckFillFormsAndClickIpc(HAS_PROCEED_ELEMENT); // Cancel the flow. autocheckout_manager_->ReturnAutocheckoutData(NULL, std::string()); @@ -804,49 +897,20 @@ TEST_F(AutocheckoutManagerTest, CancelledAutocheckoutFlow) { // Go to third page. EXPECT_CALL(autocheckout_manager_->metric_logger(), LogAutocheckoutBuyFlowMetric(testing::_)).Times(0); - autocheckout_manager_->OnLoadedPageMetaData(CreateEndOfFlowMetaData()); + autocheckout_manager_->OnLoadedPageMetaData( + CreateEndOfFlowMetaData(HAS_PROCEED_ELEMENT)); EXPECT_EQ(0U, process()->sink().message_count()); } TEST_F(AutocheckoutManagerTest, SinglePageFlow) { - // Test one page flow. - EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); - EXPECT_FALSE( - autofill_manager_delegate_->request_autocomplete_dialog_open()); - EXPECT_CALL(autocheckout_manager_->metric_logger(), - LogAutocheckoutBubbleMetric( - AutofillMetrics::BUBBLE_COULD_BE_DISPLAYED)).Times(1); - EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutSuccess()).Times(1); - autocheckout_manager_->OnLoadedPageMetaData(CreateOnePageFlowMetaData()); - // Simulate the user submitting some data via the requestAutocomplete UI. - autofill_manager_delegate_->SetUserSuppliedData( - FakeUserSubmittedFormStructure()); - GURL frame_url; - EXPECT_CALL(autocheckout_manager_->metric_logger(), - LogAutocheckoutBuyFlowMetric( - AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_STARTED)).Times(1); - EXPECT_CALL(autocheckout_manager_->metric_logger(), - LogAutocheckoutBuyFlowMetric( - AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_SUCCESS)).Times(1); - autocheckout_manager_->MaybeShowAutocheckoutDialog( - frame_url, - AUTOCHECKOUT_BUBBLE_ACCEPTED); - autocheckout_manager_->OnAutocheckoutPageCompleted(SUCCESS); - CheckFillFormsAndClickIpc(); - EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); - EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_SHIPPING, - AUTOCHECKOUT_STEP_COMPLETED)); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_DELIVERY, - AUTOCHECKOUT_STEP_COMPLETED)); - EXPECT_TRUE(autofill_manager_delegate_ - ->AutocheckoutStepExistsWithStatus(AUTOCHECKOUT_STEP_BILLING, - AUTOCHECKOUT_STEP_COMPLETED)); + TestSinglePageFlow(HAS_PROCEED_ELEMENT); +} + +TEST_F(AutocheckoutManagerTest, SinglePageFlowNoClickElement) { + TestSinglePageFlow(NO_PROCEED_ELEMENT); } -TEST_F(AutocheckoutManagerTest, CancelAutocheckoutDialog) { +TEST_F(AutocheckoutManagerTest, CancelAutocheckoutBubble) { GURL frame_url; gfx::RectF bounding_box; autofill_manager_delegate_->set_should_autoclick_bubble(false); diff --git a/components/autofill/core/browser/autofill_manager.h b/components/autofill/core/browser/autofill_manager.h index b5e4565..90b6552 100644 --- a/components/autofill/core/browser/autofill_manager.h +++ b/components/autofill/core/browser/autofill_manager.h @@ -180,6 +180,10 @@ class AutofillManager : public AutofillDownloadManager::Observer { // Resets cache. virtual void Reset(); + autofill::AutocheckoutManager* autocheckout_manager() { + return &autocheckout_manager_; + } + protected: // Test code should prefer to use this constructor. AutofillManager(AutofillDriver* driver, @@ -223,11 +227,6 @@ class AutofillManager : public AutofillDownloadManager::Observer { return external_delegate_; } - // Exposed for testing. - autofill::AutocheckoutManager* autocheckout_manager() { - return &autocheckout_manager_; - } - // Tell the renderer the current interactive autocomplete finished. virtual void ReturnAutocompleteResult( WebKit::WebFormElement::AutocompleteResult result, |