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