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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
9 #include "base/string16.h" | 10 #include "base/string16.h" |
10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "base/tuple.h" | 14 #include "base/tuple.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/autocomplete_history_manager.h" | 16 #include "chrome/browser/autocomplete_history_manager.h" |
16 #include "chrome/browser/autofill/autofill_common_test.h" | 17 #include "chrome/browser/autofill/autofill_common_test.h" |
| 18 #include "chrome/browser/autofill/autofill_external_delegate.h" |
17 #include "chrome/browser/autofill/autofill_manager.h" | 19 #include "chrome/browser/autofill/autofill_manager.h" |
18 #include "chrome/browser/autofill/autofill_profile.h" | 20 #include "chrome/browser/autofill/autofill_profile.h" |
19 #include "chrome/browser/autofill/credit_card.h" | 21 #include "chrome/browser/autofill/credit_card.h" |
20 #include "chrome/browser/autofill/personal_data_manager.h" | 22 #include "chrome/browser/autofill/personal_data_manager.h" |
21 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 23 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
26 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 28 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
27 #include "chrome/common/autofill_messages.h" | 29 #include "chrome/common/autofill_messages.h" |
| 30 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
29 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
30 #include "content/browser/browser_thread.h" | 33 #include "content/browser/browser_thread.h" |
31 #include "content/browser/tab_contents/test_tab_contents.h" | 34 #include "content/browser/tab_contents/test_tab_contents.h" |
32 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
34 #include "ipc/ipc_test_sink.h" | 37 #include "ipc/ipc_test_sink.h" |
35 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
37 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
38 #include "webkit/glue/form_data.h" | 41 #include "webkit/glue/form_data.h" |
39 #include "webkit/glue/form_field.h" | 42 #include "webkit/glue/form_field.h" |
40 | 43 |
| 44 using testing::_; |
41 using webkit_glue::FormData; | 45 using webkit_glue::FormData; |
42 using webkit_glue::FormField; | 46 using webkit_glue::FormField; |
43 | 47 |
44 namespace { | 48 namespace { |
45 | 49 |
46 // The page ID sent to the AutofillManager from the RenderView, used to send | 50 // The page ID sent to the AutofillManager from the RenderView, used to send |
47 // an IPC message back to the renderer. | 51 // an IPC message back to the renderer. |
48 const int kDefaultPageID = 137; | 52 const int kDefaultPageID = 137; |
49 | 53 |
50 typedef Tuple5<int, | 54 typedef Tuple5<int, |
(...skipping 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2827 const FieldTypeSet& possible_types1 = | 2831 const FieldTypeSet& possible_types1 = |
2828 form_structure.field(1)->possible_types(); | 2832 form_structure.field(1)->possible_types(); |
2829 EXPECT_EQ(1U, possible_types1.size()); | 2833 EXPECT_EQ(1U, possible_types1.size()); |
2830 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); | 2834 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); |
2831 const FieldTypeSet& possible_types2 = | 2835 const FieldTypeSet& possible_types2 = |
2832 form_structure.field(2)->possible_types(); | 2836 form_structure.field(2)->possible_types(); |
2833 EXPECT_EQ(1U, possible_types2.size()); | 2837 EXPECT_EQ(1U, possible_types2.size()); |
2834 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != | 2838 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != |
2835 possible_types2.end()); | 2839 possible_types2.end()); |
2836 } | 2840 } |
| 2841 |
| 2842 namespace { |
| 2843 |
| 2844 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| 2845 public: |
| 2846 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper) |
| 2847 : AutofillExternalDelegate(wrapper) {} |
| 2848 virtual ~MockAutofillExternalDelegate() {} |
| 2849 |
| 2850 MOCK_METHOD3(OnQuery, void(int query_id, |
| 2851 const webkit_glue::FormData& form, |
| 2852 const webkit_glue::FormField& field)); |
| 2853 virtual void OnSuggestionsReturned( |
| 2854 int query_id, |
| 2855 const std::vector<string16>& autofill_values, |
| 2856 const std::vector<string16>& autofill_labels, |
| 2857 const std::vector<string16>& autofill_icons, |
| 2858 const std::vector<int>& autofill_unique_ids) {} |
| 2859 |
| 2860 private: |
| 2861 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 2862 }; |
| 2863 |
| 2864 } // namespace |
| 2865 |
| 2866 // Test our external delegate is called at the right time. |
| 2867 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| 2868 MockAutofillExternalDelegate external_delegate(contents_wrapper()); |
| 2869 EXPECT_CALL(external_delegate, OnQuery(_, _, _)); |
| 2870 autofill_manager_->SetExternalDelegate(&external_delegate); |
| 2871 |
| 2872 FormData form; |
| 2873 CreateTestAddressFormData(&form); |
| 2874 std::vector<FormData> forms(1, form); |
| 2875 FormsSeen(forms); |
| 2876 const FormField& field = form.fields[0]; |
| 2877 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 2878 |
| 2879 autofill_manager_->SetExternalDelegate(NULL); |
| 2880 } |
| 2881 |
| 2882 #if defined(OS_ANDROID) |
| 2883 // Only OS_ANDROID defines an external delegate, but prerequisites for |
| 2884 // landing autofill_external_delegate_android.cc in the Chromium tree |
| 2885 // have not themselves landed. |
| 2886 |
| 2887 // Turn on the external delegate. Recreate a TabContents. Make sure |
| 2888 // an external delegate was set in the proper structures. |
| 2889 TEST_F(AutofillManagerTest, TestTabContentsWithExternalDelegate) { |
| 2890 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2891 switches::kExternalAutofillPopup); |
| 2892 |
| 2893 // Setting the contents creates a new TabContentsWrapper. |
| 2894 TestTabContents* contents = CreateTestTabContents(); |
| 2895 SetContents(contents); |
| 2896 |
| 2897 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); |
| 2898 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 2899 |
| 2900 AutocompleteHistoryManager* autocomplete_history_manager = |
| 2901 contents_wrapper()->autocomplete_history_manager(); |
| 2902 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 2903 } |
| 2904 |
| 2905 #endif // OS_ANDROID |
OLD | NEW |