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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 10 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
11 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 11 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
13 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" | 13 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" |
14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/common/form_data.h" |
18 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
22 #include "webkit/forms/form_data.h" | |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
| 25 using content::FormData; |
25 using content::WebContents; | 26 using content::WebContents; |
26 using testing::_; | 27 using testing::_; |
27 using webkit::forms::FormData; | |
28 | 28 |
29 class MockWebDataService : public WebDataService { | 29 class MockWebDataService : public WebDataService { |
30 public: | 30 public: |
31 MOCK_METHOD1(AddFormFields, | 31 MOCK_METHOD1(AddFormFields, |
32 void(const std::vector<webkit::forms::FormField>&)); // NOLINT | 32 void(const std::vector<content::FormField>&)); // NOLINT |
33 | 33 |
34 protected: | 34 protected: |
35 virtual ~MockWebDataService() {} | 35 virtual ~MockWebDataService() {} |
36 }; | 36 }; |
37 | 37 |
38 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { | 38 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
39 protected: | 39 protected: |
40 AutocompleteHistoryManagerTest() | 40 AutocompleteHistoryManagerTest() |
41 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()), | 41 : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()), |
42 db_thread_(BrowserThread::DB) { | 42 db_thread_(BrowserThread::DB) { |
(...skipping 21 matching lines...) Expand all Loading... |
64 // Tests that credit card numbers are not sent to the WebDatabase to be saved. | 64 // Tests that credit card numbers are not sent to the WebDatabase to be saved. |
65 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { | 65 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { |
66 FormData form; | 66 FormData form; |
67 form.name = ASCIIToUTF16("MyForm"); | 67 form.name = ASCIIToUTF16("MyForm"); |
68 form.method = ASCIIToUTF16("POST"); | 68 form.method = ASCIIToUTF16("POST"); |
69 form.origin = GURL("http://myform.com/form.html"); | 69 form.origin = GURL("http://myform.com/form.html"); |
70 form.action = GURL("http://myform.com/submit.html"); | 70 form.action = GURL("http://myform.com/submit.html"); |
71 form.user_submitted = true; | 71 form.user_submitted = true; |
72 | 72 |
73 // Valid Visa credit card number pulled from the paypal help site. | 73 // Valid Visa credit card number pulled from the paypal help site. |
74 webkit::forms::FormField valid_cc; | 74 content::FormField valid_cc; |
75 valid_cc.label = ASCIIToUTF16("Credit Card"); | 75 valid_cc.label = ASCIIToUTF16("Credit Card"); |
76 valid_cc.name = ASCIIToUTF16("ccnum"); | 76 valid_cc.name = ASCIIToUTF16("ccnum"); |
77 valid_cc.value = ASCIIToUTF16("4012888888881881"); | 77 valid_cc.value = ASCIIToUTF16("4012888888881881"); |
78 valid_cc.form_control_type = ASCIIToUTF16("text"); | 78 valid_cc.form_control_type = ASCIIToUTF16("text"); |
79 form.fields.push_back(valid_cc); | 79 form.fields.push_back(valid_cc); |
80 | 80 |
81 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 81 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
82 autocomplete_manager_->OnFormSubmitted(form); | 82 autocomplete_manager_->OnFormSubmitted(form); |
83 } | 83 } |
84 | 84 |
85 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The | 85 // Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The |
86 // value being submitted is not a valid credit card number, so it will be sent | 86 // value being submitted is not a valid credit card number, so it will be sent |
87 // to the WebDatabase to be saved. | 87 // to the WebDatabase to be saved. |
88 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { | 88 TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) { |
89 FormData form; | 89 FormData form; |
90 form.name = ASCIIToUTF16("MyForm"); | 90 form.name = ASCIIToUTF16("MyForm"); |
91 form.method = ASCIIToUTF16("POST"); | 91 form.method = ASCIIToUTF16("POST"); |
92 form.origin = GURL("http://myform.com/form.html"); | 92 form.origin = GURL("http://myform.com/form.html"); |
93 form.action = GURL("http://myform.com/submit.html"); | 93 form.action = GURL("http://myform.com/submit.html"); |
94 form.user_submitted = true; | 94 form.user_submitted = true; |
95 | 95 |
96 // Invalid credit card number. | 96 // Invalid credit card number. |
97 webkit::forms::FormField invalid_cc; | 97 content::FormField invalid_cc; |
98 invalid_cc.label = ASCIIToUTF16("Credit Card"); | 98 invalid_cc.label = ASCIIToUTF16("Credit Card"); |
99 invalid_cc.name = ASCIIToUTF16("ccnum"); | 99 invalid_cc.name = ASCIIToUTF16("ccnum"); |
100 invalid_cc.value = ASCIIToUTF16("4580123456789012"); | 100 invalid_cc.value = ASCIIToUTF16("4580123456789012"); |
101 invalid_cc.form_control_type = ASCIIToUTF16("text"); | 101 invalid_cc.form_control_type = ASCIIToUTF16("text"); |
102 form.fields.push_back(invalid_cc); | 102 form.fields.push_back(invalid_cc); |
103 | 103 |
104 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 104 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
105 autocomplete_manager_->OnFormSubmitted(form); | 105 autocomplete_manager_->OnFormSubmitted(form); |
106 } | 106 } |
107 | 107 |
108 // Tests that SSNs are not sent to the WebDatabase to be saved. | 108 // Tests that SSNs are not sent to the WebDatabase to be saved. |
109 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { | 109 TEST_F(AutocompleteHistoryManagerTest, SSNValue) { |
110 FormData form; | 110 FormData form; |
111 form.name = ASCIIToUTF16("MyForm"); | 111 form.name = ASCIIToUTF16("MyForm"); |
112 form.method = ASCIIToUTF16("POST"); | 112 form.method = ASCIIToUTF16("POST"); |
113 form.origin = GURL("http://myform.com/form.html"); | 113 form.origin = GURL("http://myform.com/form.html"); |
114 form.action = GURL("http://myform.com/submit.html"); | 114 form.action = GURL("http://myform.com/submit.html"); |
115 form.user_submitted = true; | 115 form.user_submitted = true; |
116 | 116 |
117 webkit::forms::FormField ssn; | 117 content::FormField ssn; |
118 ssn.label = ASCIIToUTF16("Social Security Number"); | 118 ssn.label = ASCIIToUTF16("Social Security Number"); |
119 ssn.name = ASCIIToUTF16("ssn"); | 119 ssn.name = ASCIIToUTF16("ssn"); |
120 ssn.value = ASCIIToUTF16("078-05-1120"); | 120 ssn.value = ASCIIToUTF16("078-05-1120"); |
121 ssn.form_control_type = ASCIIToUTF16("text"); | 121 ssn.form_control_type = ASCIIToUTF16("text"); |
122 form.fields.push_back(ssn); | 122 form.fields.push_back(ssn); |
123 | 123 |
124 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); | 124 EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0); |
125 autocomplete_manager_->OnFormSubmitted(form); | 125 autocomplete_manager_->OnFormSubmitted(form); |
126 } | 126 } |
127 | 127 |
128 // Verify that autocomplete text is saved for search fields. | 128 // Verify that autocomplete text is saved for search fields. |
129 TEST_F(AutocompleteHistoryManagerTest, SearchField) { | 129 TEST_F(AutocompleteHistoryManagerTest, SearchField) { |
130 FormData form; | 130 FormData form; |
131 form.name = ASCIIToUTF16("MyForm"); | 131 form.name = ASCIIToUTF16("MyForm"); |
132 form.method = ASCIIToUTF16("POST"); | 132 form.method = ASCIIToUTF16("POST"); |
133 form.origin = GURL("http://myform.com/form.html"); | 133 form.origin = GURL("http://myform.com/form.html"); |
134 form.action = GURL("http://myform.com/submit.html"); | 134 form.action = GURL("http://myform.com/submit.html"); |
135 form.user_submitted = true; | 135 form.user_submitted = true; |
136 | 136 |
137 // Search field. | 137 // Search field. |
138 webkit::forms::FormField search_field; | 138 content::FormField search_field; |
139 search_field.label = ASCIIToUTF16("Search"); | 139 search_field.label = ASCIIToUTF16("Search"); |
140 search_field.name = ASCIIToUTF16("search"); | 140 search_field.name = ASCIIToUTF16("search"); |
141 search_field.value = ASCIIToUTF16("my favorite query"); | 141 search_field.value = ASCIIToUTF16("my favorite query"); |
142 search_field.form_control_type = ASCIIToUTF16("search"); | 142 search_field.form_control_type = ASCIIToUTF16("search"); |
143 form.fields.push_back(search_field); | 143 form.fields.push_back(search_field); |
144 | 144 |
145 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 145 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
146 autocomplete_manager_->OnFormSubmitted(form); | 146 autocomplete_manager_->OnFormSubmitted(form); |
147 } | 147 } |
148 | 148 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 new AutofillWebDataServiceImpl(web_data_service_))); | 195 new AutofillWebDataServiceImpl(web_data_service_))); |
196 | 196 |
197 MockAutofillExternalDelegate external_delegate( | 197 MockAutofillExternalDelegate external_delegate( |
198 TabContents::FromWebContents(contents())); | 198 TabContents::FromWebContents(contents())); |
199 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 199 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
200 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 200 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
201 | 201 |
202 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 202 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
203 autocomplete_history_manager.SendSuggestions(NULL); | 203 autocomplete_history_manager.SendSuggestions(NULL); |
204 } | 204 } |
OLD | NEW |