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 20 matching lines...) Expand all Loading... |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
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 "webkit/glue/form_data.h" | 42 #include "webkit/glue/form_data.h" |
42 #include "webkit/glue/form_field.h" | 43 #include "webkit/glue/form_field.h" |
43 | 44 |
44 using content::BrowserThread; | 45 using content::BrowserThread; |
45 using testing::_; | 46 using testing::_; |
46 using webkit_glue::FormData; | 47 using webkit_glue::FormData; |
47 using webkit_glue::FormField; | 48 using webkit_glue::FormField; |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 561 } |
561 | 562 |
562 virtual void TearDown() OVERRIDE { | 563 virtual void TearDown() OVERRIDE { |
563 file_thread_.Stop(); | 564 file_thread_.Stop(); |
564 TabContentsWrapperTestHarness::TearDown(); | 565 TabContentsWrapperTestHarness::TearDown(); |
565 } | 566 } |
566 | 567 |
567 void GetAutofillSuggestions(int query_id, | 568 void GetAutofillSuggestions(int query_id, |
568 const webkit_glue::FormData& form, | 569 const webkit_glue::FormData& form, |
569 const webkit_glue::FormField& field) { | 570 const webkit_glue::FormField& field) { |
570 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field); | 571 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 572 form, |
| 573 field, |
| 574 gfx::Rect()); |
571 } | 575 } |
572 | 576 |
573 void GetAutofillSuggestions(const webkit_glue::FormData& form, | 577 void GetAutofillSuggestions(const webkit_glue::FormData& form, |
574 const webkit_glue::FormField& field) { | 578 const webkit_glue::FormField& field) { |
575 GetAutofillSuggestions(kDefaultPageID, form, field); | 579 GetAutofillSuggestions(kDefaultPageID, form, field); |
576 } | 580 } |
577 | 581 |
578 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 582 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
579 contents_wrapper()->autocomplete_history_manager()-> | 583 contents_wrapper()->autocomplete_history_manager()-> |
580 SendSuggestions(&result); | 584 SendSuggestions(&result); |
(...skipping 2275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2856 } | 2860 } |
2857 | 2861 |
2858 namespace { | 2862 namespace { |
2859 | 2863 |
2860 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 2864 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
2861 public: | 2865 public: |
2862 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) | 2866 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) |
2863 : AutofillExternalDelegate(wrapper) {} | 2867 : AutofillExternalDelegate(wrapper) {} |
2864 virtual ~MockAutofillExternalDelegate() {} | 2868 virtual ~MockAutofillExternalDelegate() {} |
2865 | 2869 |
2866 MOCK_METHOD3(OnQuery, void(int query_id, | 2870 MOCK_METHOD4(OnQuery, void(int query_id, |
2867 const webkit_glue::FormData& form, | 2871 const webkit_glue::FormData& form, |
2868 const webkit_glue::FormField& field)); | 2872 const webkit_glue::FormField& field, |
| 2873 const gfx::Rect& bounds)); |
2869 virtual void OnSuggestionsReturned( | 2874 virtual void OnSuggestionsReturned( |
2870 int query_id, | 2875 int query_id, |
2871 const std::vector<string16>& autofill_values, | 2876 const std::vector<string16>& autofill_values, |
2872 const std::vector<string16>& autofill_labels, | 2877 const std::vector<string16>& autofill_labels, |
2873 const std::vector<string16>& autofill_icons, | 2878 const std::vector<string16>& autofill_icons, |
2874 const std::vector<int>& autofill_unique_ids) {} | 2879 const std::vector<int>& autofill_unique_ids) OVERRIDE {} |
| 2880 |
| 2881 virtual void HideAutofillPopup() OVERRIDE {} |
2875 | 2882 |
2876 private: | 2883 private: |
2877 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 2884 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
2878 }; | 2885 }; |
2879 | 2886 |
2880 } // namespace | 2887 } // namespace |
2881 | 2888 |
2882 // Test our external delegate is called at the right time. | 2889 // Test our external delegate is called at the right time. |
2883 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 2890 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
2884 MockAutofillExternalDelegate external_delegate(contents_wrapper()); | 2891 MockAutofillExternalDelegate external_delegate(contents_wrapper()); |
2885 EXPECT_CALL(external_delegate, OnQuery(_, _, _)); | 2892 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _)); |
2886 autofill_manager_->SetExternalDelegate(&external_delegate); | 2893 autofill_manager_->SetExternalDelegate(&external_delegate); |
2887 | 2894 |
2888 FormData form; | 2895 FormData form; |
2889 CreateTestAddressFormData(&form); | 2896 CreateTestAddressFormData(&form); |
2890 std::vector<FormData> forms(1, form); | 2897 std::vector<FormData> forms(1, form); |
2891 FormsSeen(forms); | 2898 FormsSeen(forms); |
2892 const FormField& field = form.fields[0]; | 2899 const FormField& field = form.fields[0]; |
2893 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2900 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2894 | 2901 |
2895 autofill_manager_->SetExternalDelegate(NULL); | 2902 autofill_manager_->SetExternalDelegate(NULL); |
(...skipping 16 matching lines...) Expand all Loading... |
2912 | 2919 |
2913 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 2920 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
2914 EXPECT_TRUE(autofill_manager->external_delegate()); | 2921 EXPECT_TRUE(autofill_manager->external_delegate()); |
2915 | 2922 |
2916 AutocompleteHistoryManager* autocomplete_history_manager = | 2923 AutocompleteHistoryManager* autocomplete_history_manager = |
2917 contents_wrapper()->autocomplete_history_manager(); | 2924 contents_wrapper()->autocomplete_history_manager(); |
2918 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 2925 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
2919 } | 2926 } |
2920 | 2927 |
2921 #endif // OS_ANDROID | 2928 #endif // OS_ANDROID |
OLD | NEW |