Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: components/autofill/browser/autofill_manager_unittest.cc

Issue 15942004: Stop offering Autocheckout bubble on the forms of no interest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/browser/autofill_manager.cc ('k') | components/autofill/common/autofill_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/browser/autofill_manager_unittest.cc
diff --git a/components/autofill/browser/autofill_manager_unittest.cc b/components/autofill/browser/autofill_manager_unittest.cc
index 9c8e8d88696a7869f50832b4b11dfb6fc245167b..4b81964d778a1068f0a30b56483d83cf594fc4c3 100644
--- a/components/autofill/browser/autofill_manager_unittest.cc
+++ b/components/autofill/browser/autofill_manager_unittest.cc
@@ -35,6 +35,7 @@
#include "components/autofill/browser/credit_card.h"
#include "components/autofill/browser/personal_data_manager.h"
#include "components/autofill/browser/test_autofill_external_delegate.h"
+#include "components/autofill/browser/test_autofill_manager_delegate.h"
#include "components/autofill/common/autofill_messages.h"
#include "components/autofill/common/form_data.h"
#include "components/autofill/common/form_field_data.h"
@@ -550,6 +551,14 @@ class TestAutofillManager : public AutofillManager {
submission_time);
}
+ virtual void OnMaybeShowAutocheckoutBubble(
+ const FormData& form,
+ const gfx::RectF& bounding_box) OVERRIDE {
+ AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box);
+ // Needed for AutocheckoutManager to post task on IO thread.
+ content::RunAllPendingInMessageLoop(BrowserThread::IO);
+ }
+
// Resets the MessageLoopRunner so that it can wait for an asynchronous form
// submission to complete.
void ResetMessageLoopRunner() {
@@ -606,6 +615,20 @@ class TestAutofillManager : public AutofillManager {
request_autocomplete_results_.push_back(std::make_pair(result, form_data));
}
+ // Set autocheckout manager's page meta data to first page on Autocheckout
+ // flow.
+ void MarkAsFirstPageInAutocheckoutFlow() {
+ scoped_ptr<AutocheckoutPageMetaData> start_of_flow(
+ new AutocheckoutPageMetaData());
+ start_of_flow->current_page_number = 0;
+ start_of_flow->total_pages = 3;
+ WebElementDescriptor* proceed_element =
+ &start_of_flow->proceed_element_descriptor;
+ proceed_element->descriptor = "#foo";
+ proceed_element->retrieval_method = WebElementDescriptor::ID;
+ autocheckout_manager()->OnLoadedPageMetaData(start_of_flow.Pass());
+ }
+
private:
// Weak reference.
TestPersonalDataManager* personal_data_;
@@ -3180,6 +3203,20 @@ TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) {
namespace {
+class MockAutofillManagerDelegate
+ : public autofill::TestAutofillManagerDelegate {
+ public:
+ MockAutofillManagerDelegate() {}
+ virtual ~MockAutofillManagerDelegate() {}
+
+ MOCK_METHOD3(ShowAutocheckoutBubble,
+ void(const gfx::RectF& bounds,
+ bool is_google_user,
+ const base::Callback<void(bool)>& callback));
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
+};
+
class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
explicit MockAutofillExternalDelegate(content::WebContents* web_contents,
@@ -3199,6 +3236,63 @@ class MockAutofillExternalDelegate : public AutofillExternalDelegate {
} // namespace
+// Test that Autocheckout bubble is offered when server specifies field types.
+TEST_F(AutofillManagerTest, TestBubbleShown) {
+ MockAutofillManagerDelegate delegate;
+ autofill_manager_.reset(new TestAutofillManager(
+ web_contents(), &delegate, &personal_data_));
+ autofill_manager_->set_autofill_enabled(true);
+ autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
+
+ EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _));
+
+ FormData form;
+ CreateTestAddressFormData(&form);
+
+ TestFormStructure* form_structure = new TestFormStructure(form);
+ AutofillMetrics metrics_logger; // ignored
+ form_structure->DetermineHeuristicTypes(metrics_logger);
+
+ // Build and add form structure with server data.
+ std::vector<AutofillFieldType> heuristic_types, server_types;
+ for (size_t i = 0; i < form.fields.size(); ++i) {
+ heuristic_types.push_back(UNKNOWN_TYPE);
+ server_types.push_back(form_structure->field(i)->type());
+ }
+ form_structure->SetFieldTypes(heuristic_types, server_types);
+ autofill_manager_->AddSeenForm(form_structure);
+
+ autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
+}
+
+// Test that Autocheckout bubble is not offered when server doesn't have data
+// for the form.
+TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
+ MockAutofillManagerDelegate delegate;
+ autofill_manager_.reset(new TestAutofillManager(
+ web_contents(), &delegate, &personal_data_));
+ autofill_manager_->set_autofill_enabled(true);
+ autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
+
+ FormData form;
+ CreateTestAddressFormData(&form);
+
+ TestFormStructure* form_structure = new TestFormStructure(form);
+ AutofillMetrics metrics_logger; // ignored
+ form_structure->DetermineHeuristicTypes(metrics_logger);
+
+ // Build form structure without server data.
+ std::vector<AutofillFieldType> heuristic_types, server_types;
+ for (size_t i = 0; i < form.fields.size(); ++i) {
+ heuristic_types.push_back(form_structure->field(i)->type());
+ server_types.push_back(NO_SERVER_DATA);
+ }
+ form_structure->SetFieldTypes(heuristic_types, server_types);
+ autofill_manager_->AddSeenForm(form_structure);
+
+ autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
+}
+
// Test our external delegate is called at the right time.
TEST_F(AutofillManagerTest, TestExternalDelegate) {
MockAutofillExternalDelegate external_delegate(web_contents(),
« no previous file with comments | « components/autofill/browser/autofill_manager.cc ('k') | components/autofill/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698