| 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 30 matching lines...) Expand all Loading... |
| 41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/common/ssl_status.h" | 42 #include "content/public/common/ssl_status.h" |
| 43 #include "content/public/test/mock_render_process_host.h" | 43 #include "content/public/test/mock_render_process_host.h" |
| 44 #include "content/public/test/test_browser_thread.h" | 44 #include "content/public/test/test_browser_thread.h" |
| 45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
| 46 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
| 47 #include "ipc/ipc_test_sink.h" | 47 #include "ipc/ipc_test_sink.h" |
| 48 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
| 49 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
| 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 52 #include "ui/gfx/rect.h" | 53 #include "ui/gfx/rect.h" |
| 53 | 54 |
| 54 typedef PersonalDataManager::GUIDPair GUIDPair; | 55 typedef PersonalDataManager::GUIDPair GUIDPair; |
| 55 using content::BrowserThread; | 56 using content::BrowserThread; |
| 56 using content::WebContents; | 57 using content::WebContents; |
| 57 using testing::_; | 58 using testing::_; |
| 59 using WebKit::WebFormElement; |
| 58 | 60 |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 // The page ID sent to the AutofillManager from the RenderView, used to send | 63 // The page ID sent to the AutofillManager from the RenderView, used to send |
| 62 // an IPC message back to the renderer. | 64 // an IPC message back to the renderer. |
| 63 const int kDefaultPageID = 137; | 65 const int kDefaultPageID = 137; |
| 64 | 66 |
| 65 typedef Tuple5<int, | 67 typedef Tuple5<int, |
| 66 std::vector<string16>, | 68 std::vector<string16>, |
| 67 std::vector<string16>, | 69 std::vector<string16>, |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 456 } |
| 455 | 457 |
| 456 class TestAutofillManager : public AutofillManager { | 458 class TestAutofillManager : public AutofillManager { |
| 457 public: | 459 public: |
| 458 TestAutofillManager(content::WebContents* web_contents, | 460 TestAutofillManager(content::WebContents* web_contents, |
| 459 autofill::AutofillManagerDelegate* delegate, | 461 autofill::AutofillManagerDelegate* delegate, |
| 460 TestPersonalDataManager* personal_data) | 462 TestPersonalDataManager* personal_data) |
| 461 : AutofillManager(web_contents, delegate, personal_data), | 463 : AutofillManager(web_contents, delegate, personal_data), |
| 462 personal_data_(personal_data), | 464 personal_data_(personal_data), |
| 463 autofill_enabled_(true), | 465 autofill_enabled_(true), |
| 464 request_autocomplete_error_count_(0), | |
| 465 did_finish_async_form_submit_(false), | 466 did_finish_async_form_submit_(false), |
| 466 message_loop_is_running_(false) { | 467 message_loop_is_running_(false) { |
| 467 } | 468 } |
| 468 | 469 |
| 469 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 470 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
| 470 | 471 |
| 471 void set_autofill_enabled(bool autofill_enabled) { | 472 void set_autofill_enabled(bool autofill_enabled) { |
| 472 autofill_enabled_ = autofill_enabled; | 473 autofill_enabled_ = autofill_enabled; |
| 473 } | 474 } |
| 474 | 475 |
| 475 int request_autocomplete_error_count() const { | 476 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& |
| 476 return request_autocomplete_error_count_; | 477 request_autocomplete_results() const { |
| 478 return request_autocomplete_results_; |
| 477 } | 479 } |
| 478 | 480 |
| 481 |
| 479 void set_expected_submitted_field_types( | 482 void set_expected_submitted_field_types( |
| 480 const std::vector<FieldTypeSet>& expected_types) { | 483 const std::vector<FieldTypeSet>& expected_types) { |
| 481 expected_submitted_field_types_ = expected_types; | 484 expected_submitted_field_types_ = expected_types; |
| 482 } | 485 } |
| 483 | 486 |
| 484 virtual void UploadFormDataAsyncCallback( | 487 virtual void UploadFormDataAsyncCallback( |
| 485 const FormStructure* submitted_form, | 488 const FormStructure* submitted_form, |
| 486 const base::TimeTicks& load_time, | 489 const base::TimeTicks& load_time, |
| 487 const base::TimeTicks& interaction_time, | 490 const base::TimeTicks& interaction_time, |
| 488 const base::TimeTicks& submission_time) OVERRIDE { | 491 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 = | 576 std::string credit_card_guid = |
| 574 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); | 577 base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
| 575 | 578 |
| 576 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); | 579 return PackGUIDs(GUIDPair(credit_card_guid, 0), GUIDPair(std::string(), 0)); |
| 577 } | 580 } |
| 578 | 581 |
| 579 void AddSeenForm(FormStructure* form) { | 582 void AddSeenForm(FormStructure* form) { |
| 580 form_structures()->push_back(form); | 583 form_structures()->push_back(form); |
| 581 } | 584 } |
| 582 | 585 |
| 583 virtual void ReturnAutocompleteError() OVERRIDE { | 586 virtual void ReturnAutocompleteResult( |
| 584 ++request_autocomplete_error_count_; | 587 WebFormElement::AutocompleteResult result, |
| 588 const FormData& form_data) OVERRIDE { |
| 589 request_autocomplete_results_.push_back(std::make_pair(result, form_data)); |
| 585 } | 590 } |
| 586 | 591 |
| 587 private: | 592 private: |
| 588 // AutofillManager is ref counted. | 593 // AutofillManager is ref counted. |
| 589 virtual ~TestAutofillManager() {} | 594 virtual ~TestAutofillManager() {} |
| 590 | 595 |
| 591 // Weak reference. | 596 // Weak reference. |
| 592 TestPersonalDataManager* personal_data_; | 597 TestPersonalDataManager* personal_data_; |
| 593 | 598 |
| 594 bool autofill_enabled_; | 599 bool autofill_enabled_; |
| 595 int request_autocomplete_error_count_; | 600 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > |
| 601 request_autocomplete_results_; |
| 596 | 602 |
| 597 bool did_finish_async_form_submit_; | 603 bool did_finish_async_form_submit_; |
| 598 bool message_loop_is_running_; | 604 bool message_loop_is_running_; |
| 599 | 605 |
| 600 std::string submitted_form_signature_; | 606 std::string submitted_form_signature_; |
| 601 std::vector<FieldTypeSet> expected_submitted_field_types_; | 607 std::vector<FieldTypeSet> expected_submitted_field_types_; |
| 602 std::vector<bool> sent_states_; | 608 std::vector<bool> sent_states_; |
| 603 | 609 |
| 604 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 610 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 605 }; | 611 }; |
| (...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3181 | 3187 |
| 3182 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 3188 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
| 3183 | 3189 |
| 3184 // TODO(csharp): Currently variants should not be deleted, but once they are | 3190 // TODO(csharp): Currently variants should not be deleted, but once they are |
| 3185 // update these expectations. | 3191 // update these expectations. |
| 3186 // http://crbug.com/124211 | 3192 // http://crbug.com/124211 |
| 3187 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 3193 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
| 3188 } | 3194 } |
| 3189 | 3195 |
| 3190 TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) { | 3196 TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) { |
| 3191 ASSERT_EQ(0, autofill_manager_->request_autocomplete_error_count()); | 3197 EXPECT_TRUE(autofill_manager_->request_autocomplete_results().empty()); |
| 3192 | 3198 |
| 3193 autofill_manager_->set_autofill_enabled(false); | 3199 autofill_manager_->set_autofill_enabled(false); |
| 3194 autofill_manager_->OnRequestAutocomplete(FormData(), | 3200 autofill_manager_->OnRequestAutocomplete(FormData(), |
| 3195 GURL(), | 3201 GURL(), |
| 3196 content::SSLStatus()); | 3202 content::SSLStatus()); |
| 3197 | 3203 |
| 3198 EXPECT_EQ(1, autofill_manager_->request_autocomplete_error_count()); | 3204 EXPECT_EQ(1U, autofill_manager_->request_autocomplete_results().size()); |
| 3205 EXPECT_EQ(WebFormElement::AutocompleteResultErrorDisabled, |
| 3206 autofill_manager_->request_autocomplete_results()[0].first); |
| 3199 } | 3207 } |
| 3200 | 3208 |
| 3201 namespace { | 3209 namespace { |
| 3202 | 3210 |
| 3203 class MockAutofillExternalDelegate : | 3211 class MockAutofillExternalDelegate : |
| 3204 public autofill::TestAutofillExternalDelegate { | 3212 public autofill::TestAutofillExternalDelegate { |
| 3205 public: | 3213 public: |
| 3206 explicit MockAutofillExternalDelegate(content::WebContents* web_contents, | 3214 explicit MockAutofillExternalDelegate(content::WebContents* web_contents, |
| 3207 AutofillManager* autofill_manager) | 3215 AutofillManager* autofill_manager) |
| 3208 : TestAutofillExternalDelegate(web_contents, autofill_manager) {} | 3216 : TestAutofillExternalDelegate(web_contents, autofill_manager) {} |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3229 | 3237 |
| 3230 FormData form; | 3238 FormData form; |
| 3231 CreateTestAddressFormData(&form); | 3239 CreateTestAddressFormData(&form); |
| 3232 std::vector<FormData> forms(1, form); | 3240 std::vector<FormData> forms(1, form); |
| 3233 FormsSeen(forms); | 3241 FormsSeen(forms); |
| 3234 const FormFieldData& field = form.fields[0]; | 3242 const FormFieldData& field = form.fields[0]; |
| 3235 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3243 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3236 | 3244 |
| 3237 autofill_manager_->SetExternalDelegate(NULL); | 3245 autofill_manager_->SetExternalDelegate(NULL); |
| 3238 } | 3246 } |
| OLD | NEW |