| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 33 #include "content/browser/tab_contents/test_tab_contents.h" | 33 #include "content/browser/tab_contents/test_tab_contents.h" |
| 34 #include "content/test/test_browser_thread.h" | 34 #include "content/test/test_browser_thread.h" |
| 35 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "ipc/ipc_test_sink.h" | 37 #include "ipc/ipc_test_sink.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/gfx/rect.h" | 41 #include "ui/gfx/rect.h" |
| 42 #include "webkit/glue/form_data.h" | 42 #include "webkit/forms/form_data.h" |
| 43 #include "webkit/glue/form_field.h" | 43 #include "webkit/forms/form_field.h" |
| 44 | 44 |
| 45 using content::BrowserThread; | 45 using content::BrowserThread; |
| 46 using testing::_; | 46 using testing::_; |
| 47 using webkit_glue::FormData; | 47 using webkit::forms::FormData; |
| 48 using webkit_glue::FormField; | 48 using webkit::forms::FormField; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 // The page ID sent to the AutofillManager from the RenderView, used to send | 52 // The page ID sent to the AutofillManager from the RenderView, used to send |
| 53 // an IPC message back to the renderer. | 53 // an IPC message back to the renderer. |
| 54 const int kDefaultPageID = 137; | 54 const int kDefaultPageID = 137; |
| 55 | 55 |
| 56 typedef Tuple5<int, | 56 typedef Tuple5<int, |
| 57 std::vector<string16>, | 57 std::vector<string16>, |
| 58 std::vector<string16>, | 58 std::vector<string16>, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 EXPECT_EQ(expected_labels[i], labels[i]); | 262 EXPECT_EQ(expected_labels[i], labels[i]); |
| 263 EXPECT_EQ(expected_icons[i], icons[i]); | 263 EXPECT_EQ(expected_icons[i], icons[i]); |
| 264 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); | 264 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ExpectFilledField(const char* expected_label, | 268 void ExpectFilledField(const char* expected_label, |
| 269 const char* expected_name, | 269 const char* expected_name, |
| 270 const char* expected_value, | 270 const char* expected_value, |
| 271 const char* expected_form_control_type, | 271 const char* expected_form_control_type, |
| 272 const webkit_glue::FormField& field) { | 272 const webkit::forms::FormField& field) { |
| 273 SCOPED_TRACE(expected_label); | 273 SCOPED_TRACE(expected_label); |
| 274 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 274 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
| 275 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 275 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
| 276 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 276 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
| 277 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); | 277 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Verifies that the |filled_form| has been filled with the given data. | 280 // Verifies that the |filled_form| has been filled with the given data. |
| 281 // Verifies address fields if |has_address_fields| is true, and verifies | 281 // Verifies address fields if |has_address_fields| is true, and verifies |
| 282 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 282 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 559 |
| 560 file_thread_.Start(); | 560 file_thread_.Start(); |
| 561 } | 561 } |
| 562 | 562 |
| 563 virtual void TearDown() OVERRIDE { | 563 virtual void TearDown() OVERRIDE { |
| 564 file_thread_.Stop(); | 564 file_thread_.Stop(); |
| 565 TabContentsWrapperTestHarness::TearDown(); | 565 TabContentsWrapperTestHarness::TearDown(); |
| 566 } | 566 } |
| 567 | 567 |
| 568 void GetAutofillSuggestions(int query_id, | 568 void GetAutofillSuggestions(int query_id, |
| 569 const webkit_glue::FormData& form, | 569 const webkit::forms::FormData& form, |
| 570 const webkit_glue::FormField& field) { | 570 const webkit::forms::FormField& field) { |
| 571 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 571 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 572 form, | 572 form, |
| 573 field, | 573 field, |
| 574 gfx::Rect(), | 574 gfx::Rect(), |
| 575 false); | 575 false); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void GetAutofillSuggestions(const webkit_glue::FormData& form, | 578 void GetAutofillSuggestions(const webkit::forms::FormData& form, |
| 579 const webkit_glue::FormField& field) { | 579 const webkit::forms::FormField& field) { |
| 580 GetAutofillSuggestions(kDefaultPageID, form, field); | 580 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 583 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
| 584 contents_wrapper()->autocomplete_history_manager()-> | 584 contents_wrapper()->autocomplete_history_manager()-> |
| 585 SendSuggestions(&result); | 585 SendSuggestions(&result); |
| 586 } | 586 } |
| 587 | 587 |
| 588 void FormsSeen(const std::vector<webkit_glue::FormData>& forms) { | 588 void FormsSeen(const std::vector<webkit::forms::FormData>& forms) { |
| 589 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 589 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
| 590 } | 590 } |
| 591 | 591 |
| 592 void FormSubmitted(const FormData& form) { | 592 void FormSubmitted(const FormData& form) { |
| 593 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 593 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
| 594 autofill_manager_->WaitForAsyncFormSubmit(); | 594 autofill_manager_->WaitForAsyncFormSubmit(); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void FillAutofillFormData(int query_id, | 597 void FillAutofillFormData(int query_id, |
| 598 const webkit_glue::FormData& form, | 598 const webkit::forms::FormData& form, |
| 599 const webkit_glue::FormField& field, | 599 const webkit::forms::FormField& field, |
| 600 int unique_id) { | 600 int unique_id) { |
| 601 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 601 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
| 602 } | 602 } |
| 603 | 603 |
| 604 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 604 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { |
| 605 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 605 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); |
| 606 } | 606 } |
| 607 | 607 |
| 608 bool GetAutofillSuggestionsMessage(int* page_id, | 608 bool GetAutofillSuggestionsMessage(int* page_id, |
| 609 std::vector<string16>* values, | 609 std::vector<string16>* values, |
| (...skipping 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2862 | 2862 |
| 2863 namespace { | 2863 namespace { |
| 2864 | 2864 |
| 2865 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 2865 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 2866 public: | 2866 public: |
| 2867 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) | 2867 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) |
| 2868 : AutofillExternalDelegate(wrapper) {} | 2868 : AutofillExternalDelegate(wrapper) {} |
| 2869 virtual ~MockAutofillExternalDelegate() {} | 2869 virtual ~MockAutofillExternalDelegate() {} |
| 2870 | 2870 |
| 2871 MOCK_METHOD5(OnQuery, void(int query_id, | 2871 MOCK_METHOD5(OnQuery, void(int query_id, |
| 2872 const webkit_glue::FormData& form, | 2872 const webkit::forms::FormData& form, |
| 2873 const webkit_glue::FormField& field, | 2873 const webkit::forms::FormField& field, |
| 2874 const gfx::Rect& bounds, | 2874 const gfx::Rect& bounds, |
| 2875 bool display_warning)); | 2875 bool display_warning)); |
| 2876 | 2876 |
| 2877 virtual void HideAutofillPopup() OVERRIDE {} | 2877 virtual void HideAutofillPopup() OVERRIDE {} |
| 2878 | 2878 |
| 2879 virtual void ApplyAutofillSuggestions( | 2879 virtual void ApplyAutofillSuggestions( |
| 2880 const std::vector<string16>& autofill_values, | 2880 const std::vector<string16>& autofill_values, |
| 2881 const std::vector<string16>& autofill_labels, | 2881 const std::vector<string16>& autofill_labels, |
| 2882 const std::vector<string16>& autofill_icons, | 2882 const std::vector<string16>& autofill_icons, |
| 2883 const std::vector<int>& autofill_unique_ids, | 2883 const std::vector<int>& autofill_unique_ids, |
| 2884 int separator_index) OVERRIDE {} | 2884 int separator_index) OVERRIDE {} |
| 2885 | 2885 |
| 2886 virtual void OnQueryPlatformSpecific( | 2886 virtual void OnQueryPlatformSpecific( |
| 2887 int query_id, | 2887 int query_id, |
| 2888 const webkit_glue::FormData& form, | 2888 const webkit::forms::FormData& form, |
| 2889 const webkit_glue::FormField& field) OVERRIDE {} | 2889 const webkit::forms::FormField& field) OVERRIDE {} |
| 2890 | 2890 |
| 2891 private: | 2891 private: |
| 2892 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 2892 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 2893 }; | 2893 }; |
| 2894 | 2894 |
| 2895 } // namespace | 2895 } // namespace |
| 2896 | 2896 |
| 2897 // Test our external delegate is called at the right time. | 2897 // Test our external delegate is called at the right time. |
| 2898 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 2898 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| 2899 MockAutofillExternalDelegate external_delegate(contents_wrapper()); | 2899 MockAutofillExternalDelegate external_delegate(contents_wrapper()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2927 | 2927 |
| 2928 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 2928 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 2929 EXPECT_TRUE(autofill_manager->external_delegate()); | 2929 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 2930 | 2930 |
| 2931 AutocompleteHistoryManager* autocomplete_history_manager = | 2931 AutocompleteHistoryManager* autocomplete_history_manager = |
| 2932 contents_wrapper()->autocomplete_history_manager(); | 2932 contents_wrapper()->autocomplete_history_manager(); |
| 2933 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 2933 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 2934 } | 2934 } |
| 2935 | 2935 |
| 2936 #endif // OS_ANDROID | 2936 #endif // OS_ANDROID |
| OLD | NEW |