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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
29 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
30 #include "components/autofill/browser/autocomplete_history_manager.h" 30 #include "components/autofill/browser/autocomplete_history_manager.h"
31 #include "components/autofill/browser/autofill_common_test.h" 31 #include "components/autofill/browser/autofill_common_test.h"
32 #include "components/autofill/browser/autofill_manager.h" 32 #include "components/autofill/browser/autofill_manager.h"
33 #include "components/autofill/browser/autofill_metrics.h" 33 #include "components/autofill/browser/autofill_metrics.h"
34 #include "components/autofill/browser/autofill_profile.h" 34 #include "components/autofill/browser/autofill_profile.h"
35 #include "components/autofill/browser/credit_card.h" 35 #include "components/autofill/browser/credit_card.h"
36 #include "components/autofill/browser/personal_data_manager.h" 36 #include "components/autofill/browser/personal_data_manager.h"
37 #include "components/autofill/browser/test_autofill_external_delegate.h" 37 #include "components/autofill/browser/test_autofill_external_delegate.h"
38 #include "components/autofill/browser/test_autofill_manager_delegate.h"
38 #include "components/autofill/common/autofill_messages.h" 39 #include "components/autofill/common/autofill_messages.h"
39 #include "components/autofill/common/form_data.h" 40 #include "components/autofill/common/form_data.h"
40 #include "components/autofill/common/form_field_data.h" 41 #include "components/autofill/common/form_field_data.h"
41 #include "components/autofill/common/forms_seen_state.h" 42 #include "components/autofill/common/forms_seen_state.h"
42 #include "components/user_prefs/user_prefs.h" 43 #include "components/user_prefs/user_prefs.h"
43 #include "content/public/browser/web_contents.h" 44 #include "content/public/browser/web_contents.h"
44 #include "content/public/test/mock_render_process_host.h" 45 #include "content/public/test/mock_render_process_host.h"
45 #include "content/public/test/test_browser_thread.h" 46 #include "content/public/test/test_browser_thread.h"
46 #include "content/public/test/test_utils.h" 47 #include "content/public/test/test_utils.h"
47 #include "googleurl/src/gurl.h" 48 #include "googleurl/src/gurl.h"
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 544 }
544 } 545 }
545 } 546 }
546 547
547 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 548 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
548 load_time, 549 load_time,
549 interaction_time, 550 interaction_time,
550 submission_time); 551 submission_time);
551 } 552 }
552 553
554 virtual void OnMaybeShowAutocheckoutBubble(
555 const FormData& form,
556 const gfx::RectF& bounding_box) OVERRIDE {
557 AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box);
558 // Needed for AutocheckoutManager to post task on IO thread.
559 content::RunAllPendingInMessageLoop(BrowserThread::IO);
560 }
561
553 // Resets the MessageLoopRunner so that it can wait for an asynchronous form 562 // Resets the MessageLoopRunner so that it can wait for an asynchronous form
554 // submission to complete. 563 // submission to complete.
555 void ResetMessageLoopRunner() { 564 void ResetMessageLoopRunner() {
556 message_loop_runner_ = new content::MessageLoopRunner(); 565 message_loop_runner_ = new content::MessageLoopRunner();
557 } 566 }
558 567
559 // Wait for the asynchronous OnFormSubmitted() call to complete. 568 // Wait for the asynchronous OnFormSubmitted() call to complete.
560 void WaitForAsyncFormSubmit() { 569 void WaitForAsyncFormSubmit() {
561 message_loop_runner_->Run(); 570 message_loop_runner_->Run();
562 } 571 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 void ClearFormStructures() { 608 void ClearFormStructures() {
600 form_structures()->clear(); 609 form_structures()->clear();
601 } 610 }
602 611
603 virtual void ReturnAutocompleteResult( 612 virtual void ReturnAutocompleteResult(
604 WebFormElement::AutocompleteResult result, 613 WebFormElement::AutocompleteResult result,
605 const FormData& form_data) OVERRIDE { 614 const FormData& form_data) OVERRIDE {
606 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); 615 request_autocomplete_results_.push_back(std::make_pair(result, form_data));
607 } 616 }
608 617
618 // Set autocheckout manager's page meta data to first page on Autocheckout
619 // flow.
620 void MarkAsFirstPageInAutocheckoutFlow() {
621 scoped_ptr<AutocheckoutPageMetaData> start_of_flow(
622 new AutocheckoutPageMetaData());
623 start_of_flow->current_page_number = 0;
624 start_of_flow->total_pages = 3;
625 WebElementDescriptor* proceed_element =
626 &start_of_flow->proceed_element_descriptor;
627 proceed_element->descriptor = "#foo";
628 proceed_element->retrieval_method = WebElementDescriptor::ID;
629 autocheckout_manager()->OnLoadedPageMetaData(start_of_flow.Pass());
630 }
631
609 private: 632 private:
610 // Weak reference. 633 // Weak reference.
611 TestPersonalDataManager* personal_data_; 634 TestPersonalDataManager* personal_data_;
612 635
613 bool autofill_enabled_; 636 bool autofill_enabled_;
614 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > 637 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >
615 request_autocomplete_results_; 638 request_autocomplete_results_;
616 639
617 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 640 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
618 641
(...skipping 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 autofill_manager_->OnRequestAutocomplete(FormData(), 3196 autofill_manager_->OnRequestAutocomplete(FormData(),
3174 GURL()); 3197 GURL());
3175 3198
3176 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size()); 3199 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size());
3177 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled, 3200 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled,
3178 autofill_manager_->request_autocomplete_results()[0].first); 3201 autofill_manager_->request_autocomplete_results()[0].first);
3179 } 3202 }
3180 3203
3181 namespace { 3204 namespace {
3182 3205
3206 class MockAutofillManagerDelegate
3207 : public autofill::TestAutofillManagerDelegate {
3208 public:
3209 MockAutofillManagerDelegate() {}
3210 virtual ~MockAutofillManagerDelegate() {}
3211
3212 MOCK_METHOD3(ShowAutocheckoutBubble,
3213 void(const gfx::RectF& bounds,
3214 bool is_google_user,
3215 const base::Callback<void(bool)>& callback));
3216 private:
3217 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
3218 };
3219
3183 class MockAutofillExternalDelegate : public AutofillExternalDelegate { 3220 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
3184 public: 3221 public:
3185 explicit MockAutofillExternalDelegate(content::WebContents* web_contents, 3222 explicit MockAutofillExternalDelegate(content::WebContents* web_contents,
3186 AutofillManager* autofill_manager) 3223 AutofillManager* autofill_manager)
3187 : AutofillExternalDelegate(web_contents, autofill_manager) {} 3224 : AutofillExternalDelegate(web_contents, autofill_manager) {}
3188 virtual ~MockAutofillExternalDelegate() {} 3225 virtual ~MockAutofillExternalDelegate() {}
3189 3226
3190 MOCK_METHOD5(OnQuery, void(int query_id, 3227 MOCK_METHOD5(OnQuery, void(int query_id,
3191 const FormData& form, 3228 const FormData& form,
3192 const FormFieldData& field, 3229 const FormFieldData& field,
3193 const gfx::RectF& bounds, 3230 const gfx::RectF& bounds,
3194 bool display_warning)); 3231 bool display_warning));
3195 3232
3196 private: 3233 private:
3197 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 3234 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
3198 }; 3235 };
3199 3236
3200 } // namespace 3237 } // namespace
3201 3238
3239 // Test that Autocheckout bubble is offered when server specifies field types.
3240 TEST_F(AutofillManagerTest, TestBubbleShown) {
3241 MockAutofillManagerDelegate delegate;
3242 autofill_manager_.reset(new TestAutofillManager(
3243 web_contents(), &delegate, &personal_data_));
3244 autofill_manager_->set_autofill_enabled(true);
3245 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3246
3247 EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _));
3248
3249 FormData form;
3250 CreateTestAddressFormData(&form);
3251
3252 TestFormStructure* form_structure = new TestFormStructure(form);
3253 AutofillMetrics metrics_logger; // ignored
3254 form_structure->DetermineHeuristicTypes(metrics_logger);
3255
3256 // Build and add form structure with server data.
3257 std::vector<AutofillFieldType> heuristic_types, server_types;
3258 for (size_t i = 0; i < form.fields.size(); ++i) {
3259 heuristic_types.push_back(UNKNOWN_TYPE);
3260 server_types.push_back(form_structure->field(i)->type());
3261 }
3262 form_structure->SetFieldTypes(heuristic_types, server_types);
3263 autofill_manager_->AddSeenForm(form_structure);
3264
3265 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3266 }
3267
3268 // Test that Autocheckout bubble is not offered when server doesn't have data
3269 // for the form.
3270 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
3271 MockAutofillManagerDelegate delegate;
3272 autofill_manager_.reset(new TestAutofillManager(
3273 web_contents(), &delegate, &personal_data_));
3274 autofill_manager_->set_autofill_enabled(true);
3275 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3276
3277 FormData form;
3278 CreateTestAddressFormData(&form);
3279
3280 TestFormStructure* form_structure = new TestFormStructure(form);
3281 AutofillMetrics metrics_logger; // ignored
3282 form_structure->DetermineHeuristicTypes(metrics_logger);
3283
3284 // Build form structure without server data.
3285 std::vector<AutofillFieldType> heuristic_types, server_types;
3286 for (size_t i = 0; i < form.fields.size(); ++i) {
3287 heuristic_types.push_back(form_structure->field(i)->type());
3288 server_types.push_back(NO_SERVER_DATA);
3289 }
3290 form_structure->SetFieldTypes(heuristic_types, server_types);
3291 autofill_manager_->AddSeenForm(form_structure);
3292
3293 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3294 }
3295
3202 // Test our external delegate is called at the right time. 3296 // Test our external delegate is called at the right time.
3203 TEST_F(AutofillManagerTest, TestExternalDelegate) { 3297 TEST_F(AutofillManagerTest, TestExternalDelegate) {
3204 MockAutofillExternalDelegate external_delegate(web_contents(), 3298 MockAutofillExternalDelegate external_delegate(web_contents(),
3205 autofill_manager_.get()); 3299 autofill_manager_.get());
3206 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); 3300 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _));
3207 autofill_manager_->SetExternalDelegate(&external_delegate); 3301 autofill_manager_->SetExternalDelegate(&external_delegate);
3208 3302
3209 FormData form; 3303 FormData form;
3210 CreateTestAddressFormData(&form); 3304 CreateTestAddressFormData(&form);
3211 std::vector<FormData> forms(1, form); 3305 std::vector<FormData> forms(1, form);
3212 FormsSeen(forms); 3306 FormsSeen(forms);
3213 const FormFieldData& field = form.fields[0]; 3307 const FormFieldData& field = form.fields[0];
3214 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3308 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3215 3309
3216 autofill_manager_->SetExternalDelegate(NULL); 3310 autofill_manager_->SetExternalDelegate(NULL);
3217 } 3311 }
3218 3312
3219 } // namespace autofill 3313 } // namespace autofill
OLDNEW
« 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