OLD | NEW |
---|---|
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/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 } | 454 } |
455 | 455 |
456 class TestAutofillManager : public AutofillManager { | 456 class TestAutofillManager : public AutofillManager { |
457 public: | 457 public: |
458 TestAutofillManager(content::WebContents* web_contents, | 458 TestAutofillManager(content::WebContents* web_contents, |
459 autofill::AutofillManagerDelegate* delegate, | 459 autofill::AutofillManagerDelegate* delegate, |
460 TestPersonalDataManager* personal_data) | 460 TestPersonalDataManager* personal_data) |
461 : AutofillManager(web_contents, delegate, personal_data), | 461 : AutofillManager(web_contents, delegate, personal_data), |
462 personal_data_(personal_data), | 462 personal_data_(personal_data), |
463 autofill_enabled_(true), | 463 autofill_enabled_(true), |
464 request_autocomplete_error_count_(0), | |
465 did_finish_async_form_submit_(false), | 464 did_finish_async_form_submit_(false), |
466 message_loop_is_running_(false) { | 465 message_loop_is_running_(false) { |
467 } | 466 } |
468 | 467 |
469 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 468 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
470 | 469 |
471 void set_autofill_enabled(bool autofill_enabled) { | 470 void set_autofill_enabled(bool autofill_enabled) { |
472 autofill_enabled_ = autofill_enabled; | 471 autofill_enabled_ = autofill_enabled; |
473 } | 472 } |
474 | 473 |
475 int request_autocomplete_error_count() const { | 474 const |
476 return request_autocomplete_error_count_; | 475 std::vector<std::pair<WebKit::WebFormElement::AutocompleteResult, FormData> >& |
Ilya Sherman
2013/01/11 20:59:56
nit: Maybe use "using WebKit::WebFormElement" or a
Dan Beam
2013/01/11 21:50:15
Done.
| |
476 request_autocomplete_results() const { | |
477 return request_autocomplete_results_; | |
477 } | 478 } |
478 | 479 |
480 | |
479 void set_expected_submitted_field_types( | 481 void set_expected_submitted_field_types( |
480 const std::vector<FieldTypeSet>& expected_types) { | 482 const std::vector<FieldTypeSet>& expected_types) { |
481 expected_submitted_field_types_ = expected_types; | 483 expected_submitted_field_types_ = expected_types; |
482 } | 484 } |
483 | 485 |
484 virtual void UploadFormDataAsyncCallback( | 486 virtual void UploadFormDataAsyncCallback( |
485 const FormStructure* submitted_form, | 487 const FormStructure* submitted_form, |
486 const base::TimeTicks& load_time, | 488 const base::TimeTicks& load_time, |
487 const base::TimeTicks& interaction_time, | 489 const base::TimeTicks& interaction_time, |
488 const base::TimeTicks& submission_time) OVERRIDE { | 490 const base::TimeTicks& submission_time) OVERRIDE { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 std::string credit_card_guid = | 575 std::string credit_card_guid = |
574 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 576 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
575 | 577 |
576 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); | 578 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); |
577 } | 579 } |
578 | 580 |
579 void AddSeenForm(FormStructure* form) { | 581 void AddSeenForm(FormStructure* form) { |
580 form_structures()->push_back(form); | 582 form_structures()->push_back(form); |
581 } | 583 } |
582 | 584 |
583 virtual void ReturnAutocompleteError() OVERRIDE { | 585 virtual void ReturnAutocompleteResult( |
584 ++request_autocomplete_error_count_; | 586 WebKit::WebFormElement::AutocompleteResult result, |
587 const FormData& form_data) OVERRIDE { | |
588 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); | |
585 } | 589 } |
586 | 590 |
587 private: | 591 private: |
588 // AutofillManager is ref counted. | 592 // AutofillManager is ref counted. |
589 virtual ~TestAutofillManager() {} | 593 virtual ~TestAutofillManager() {} |
590 | 594 |
591 // Weak reference. | 595 // Weak reference. |
592 TestPersonalDataManager* personal_data_; | 596 TestPersonalDataManager* personal_data_; |
593 | 597 |
594 bool autofill_enabled_; | 598 bool autofill_enabled_; |
595 int request_autocomplete_error_count_; | 599 std::vector<std::pair<WebKit::WebFormElement::AutocompleteResult, FormData> > |
600 request_autocomplete_results_; | |
596 | 601 |
597 bool did_finish_async_form_submit_; | 602 bool did_finish_async_form_submit_; |
598 bool message_loop_is_running_; | 603 bool message_loop_is_running_; |
599 | 604 |
600 std::string submitted_form_signature_; | 605 std::string submitted_form_signature_; |
601 std::vector<FieldTypeSet> expected_submitted_field_types_; | 606 std::vector<FieldTypeSet> expected_submitted_field_types_; |
602 std::vector<bool> sent_states_; | 607 std::vector<bool> sent_states_; |
603 | 608 |
604 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 609 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
605 }; | 610 }; |
(...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3181 | 3186 |
3182 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3187 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
3183 | 3188 |
3184 // TODO(csharp): Currently variants should not be deleted, but once they are | 3189 // TODO(csharp): Currently variants should not be deleted, but once they are |
3185 // update these expectations. | 3190 // update these expectations. |
3186 // http://crbug.com/124211 | 3191 // http://crbug.com/124211 |
3187 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 3192 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
3188 } | 3193 } |
3189 | 3194 |
3190 TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) { | 3195 TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) { |
3191 ASSERT_EQ(0, autofill_manager_->request_autocomplete_error_count()); | 3196 EXPECT_TRUE(autofill_manager_->request_autocomplete_results().empty()); |
3192 | 3197 |
3193 autofill_manager_->set_autofill_enabled(false); | 3198 autofill_manager_->set_autofill_enabled(false); |
3194 autofill_manager_->OnRequestAutocomplete(FormData(), | 3199 autofill_manager_->OnRequestAutocomplete(FormData(), |
3195 GURL(), | 3200 GURL(), |
3196 content::SSLStatus()); | 3201 content::SSLStatus()); |
3197 | 3202 |
3198 EXPECT_EQ(1, autofill_manager_->request_autocomplete_error_count()); | 3203 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size()); |
3204 EXPECT_EQ(WebKit::WebFormElement::AutocompleteResultErrorDisabled, | |
3205 autofill_manager_->request_autocomplete_results()[0].first); | |
3199 } | 3206 } |
3200 | 3207 |
3201 namespace { | 3208 namespace { |
3202 | 3209 |
3203 class MockAutofillExternalDelegate : | 3210 class MockAutofillExternalDelegate : |
3204 public autofill::TestAutofillExternalDelegate { | 3211 public autofill::TestAutofillExternalDelegate { |
3205 public: | 3212 public: |
3206 explicit MockAutofillExternalDelegate(content::WebContents* web_contents, | 3213 explicit MockAutofillExternalDelegate(content::WebContents* web_contents, |
3207 AutofillManager* autofill_manager) | 3214 AutofillManager* autofill_manager) |
3208 : TestAutofillExternalDelegate(web_contents, autofill_manager) {} | 3215 : TestAutofillExternalDelegate(web_contents, autofill_manager) {} |
(...skipping 20 matching lines...) Expand all Loading... | |
3229 | 3236 |
3230 FormData form; | 3237 FormData form; |
3231 CreateTestAddressFormData(&form); | 3238 CreateTestAddressFormData(&form); |
3232 std::vector<FormData> forms(1, form); | 3239 std::vector<FormData> forms(1, form); |
3233 FormsSeen(forms); | 3240 FormsSeen(forms); |
3234 const FormFieldData& field = form.fields[0]; | 3241 const FormFieldData& field = form.fields[0]; |
3235 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3242 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3236 | 3243 |
3237 autofill_manager_->SetExternalDelegate(NULL); | 3244 autofill_manager_->SetExternalDelegate(NULL); |
3238 } | 3245 } |
OLD | NEW |