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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_download.h" | 10 #include "chrome/browser/autofill/autofill_download.h" |
11 #include "chrome/browser/autofill/autofill_field.h" | 11 #include "chrome/browser/autofill/autofill_field.h" |
12 #include "chrome/browser/autofill/autofill_metrics.h" | 12 #include "chrome/browser/autofill/autofill_metrics.h" |
13 #include "chrome/browser/autofill/autofill_type.h" | 13 #include "chrome/browser/autofill/autofill_type.h" |
14 #include "chrome/browser/autofill/form_structure.h" | 14 #include "chrome/browser/autofill/form_structure.h" |
15 #include "chrome/test/base/test_url_request_context_getter.h" | 15 #include "chrome/test/base/test_url_request_context_getter.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "chrome/test/testing_browser_process.h" | 17 #include "chrome/test/testing_browser_process.h" |
18 #include "chrome/test/testing_browser_process_test.h" | 18 #include "chrome/test/testing_browser_process_test.h" |
19 #include "content/test/test_url_fetcher_factory.h" | 19 #include "content/test/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
24 #include "webkit/glue/form_data.h" | 24 #include "webkit/glue/form_data.h" |
25 | 25 |
26 using webkit_glue::FormData; | 26 using webkit_glue::FormData; |
27 using webkit_glue::FormField; | |
27 using WebKit::WebInputElement; | 28 using WebKit::WebInputElement; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 class MockAutofillMetrics : public AutofillMetrics { | 32 class MockAutofillMetrics : public AutofillMetrics { |
32 public: | 33 public: |
33 MockAutofillMetrics() {} | 34 MockAutofillMetrics() {} |
34 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); | 35 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); |
35 | 36 |
36 private: | 37 private: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 typedef TestingBrowserProcessTest AutofillDownloadTest; | 118 typedef TestingBrowserProcessTest AutofillDownloadTest; |
118 | 119 |
119 TEST_F(AutofillDownloadTest, QueryAndUploadTest) { | 120 TEST_F(AutofillDownloadTest, QueryAndUploadTest) { |
120 MessageLoopForUI message_loop; | 121 MessageLoopForUI message_loop; |
121 // Create and register factory. | 122 // Create and register factory. |
122 AutofillDownloadTestHelper helper; | 123 AutofillDownloadTestHelper helper; |
123 TestURLFetcherFactory factory; | 124 TestURLFetcherFactory factory; |
124 | 125 |
125 FormData form; | 126 FormData form; |
126 form.method = ASCIIToUTF16("post"); | 127 form.method = ASCIIToUTF16("post"); |
127 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), | 128 |
128 ASCIIToUTF16("username"), | 129 FormField field; |
129 string16(), | 130 field.label = ASCIIToUTF16("username"); |
dhollowa
2011/08/08 21:40:39
nit: It would be nice visually to have empty lines
Ilya Sherman
2011/08/09 00:13:43
Done.
| |
130 ASCIIToUTF16("text"), | 131 field.name = ASCIIToUTF16("username"); |
131 0, | 132 field.form_control_type = ASCIIToUTF16("text"); |
132 false)); | 133 form.fields.push_back(field); |
133 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), | 134 field.label = ASCIIToUTF16("First Name"); |
134 ASCIIToUTF16("firstname"), | 135 field.name = ASCIIToUTF16("firstname"); |
135 string16(), | 136 form.fields.push_back(field); |
136 ASCIIToUTF16("text"), | 137 field.label = ASCIIToUTF16("Last Name"); |
137 0, | 138 field.name = ASCIIToUTF16("lastname"); |
138 false)); | 139 form.fields.push_back(field); |
139 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), | 140 field.label = ASCIIToUTF16("email"); |
140 ASCIIToUTF16("lastname"), | 141 field.name = ASCIIToUTF16("email"); |
141 string16(), | 142 form.fields.push_back(field); |
142 ASCIIToUTF16("text"), | 143 field.label = ASCIIToUTF16("email2"); |
143 0, | 144 field.name = ASCIIToUTF16("email2"); |
144 false)); | 145 form.fields.push_back(field); |
145 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), | 146 field.label = ASCIIToUTF16("password"); |
146 ASCIIToUTF16("email"), | 147 field.name = ASCIIToUTF16("password"); |
147 string16(), | 148 field.form_control_type = ASCIIToUTF16("password"); |
148 ASCIIToUTF16("text"), | 149 form.fields.push_back(field); |
149 0, | 150 field.label = string16(); |
150 false)); | 151 field.name = ASCIIToUTF16("Submit"); |
151 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), | 152 field.form_control_type = ASCIIToUTF16("submit"); |
152 ASCIIToUTF16("email2"), | 153 form.fields.push_back(field); |
153 string16(), | |
154 ASCIIToUTF16("text"), | |
155 0, | |
156 false)); | |
157 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), | |
158 ASCIIToUTF16("password"), | |
159 string16(), | |
160 ASCIIToUTF16("password"), | |
161 0, | |
162 false)); | |
163 form.fields.push_back(webkit_glue::FormField(string16(), | |
164 ASCIIToUTF16("Submit"), | |
165 string16(), | |
166 ASCIIToUTF16("submit"), | |
167 0, | |
168 false)); | |
169 | 154 |
170 FormStructure *form_structure = new FormStructure(form); | 155 FormStructure *form_structure = new FormStructure(form); |
171 ScopedVector<FormStructure> form_structures; | 156 ScopedVector<FormStructure> form_structures; |
172 form_structures.push_back(form_structure); | 157 form_structures.push_back(form_structure); |
173 | 158 |
174 form.fields.clear(); | 159 form.fields.clear(); |
175 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address"), | 160 field.label = ASCIIToUTF16("address"); |
176 ASCIIToUTF16("address"), | 161 field.name = ASCIIToUTF16("address"); |
177 string16(), | 162 field.form_control_type = ASCIIToUTF16("text"); |
178 ASCIIToUTF16("text"), | 163 form.fields.push_back(field); |
179 0, | 164 field.label = ASCIIToUTF16("address2"); |
180 false)); | 165 field.name = ASCIIToUTF16("address2"); |
181 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), | 166 form.fields.push_back(field); |
182 ASCIIToUTF16("address2"), | 167 field.label = ASCIIToUTF16("city"); |
183 string16(), | 168 field.name = ASCIIToUTF16("city"); |
184 ASCIIToUTF16("text"), | 169 form.fields.push_back(field); |
185 0, | 170 field.label = string16(); |
186 false)); | 171 field.name = ASCIIToUTF16("Submit"); |
187 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), | 172 field.form_control_type = ASCIIToUTF16("submit"); |
188 ASCIIToUTF16("city"), | 173 form.fields.push_back(field); |
189 string16(), | |
190 ASCIIToUTF16("text"), | |
191 0, | |
192 false)); | |
193 form.fields.push_back(webkit_glue::FormField(string16(), | |
194 ASCIIToUTF16("Submit"), | |
195 string16(), | |
196 ASCIIToUTF16("submit"), | |
197 0, | |
198 false)); | |
199 form_structure = new FormStructure(form); | 174 form_structure = new FormStructure(form); |
200 form_structures.push_back(form_structure); | 175 form_structures.push_back(form_structure); |
201 | 176 |
202 // Request with id 0. | 177 // Request with id 0. |
203 MockAutofillMetrics mock_metric_logger; | 178 MockAutofillMetrics mock_metric_logger; |
204 EXPECT_CALL(mock_metric_logger, | 179 EXPECT_CALL(mock_metric_logger, |
205 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(2); | 180 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(2); |
206 // First one will fail because context is not set up. | 181 // First one will fail because context is not set up. |
207 EXPECT_FALSE(helper.download_manager.StartQueryRequest(form_structures, | 182 EXPECT_FALSE(helper.download_manager.StartQueryRequest(form_structures, |
208 mock_metric_logger)); | 183 mock_metric_logger)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]), | 268 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]), |
294 true, | 269 true, |
295 FieldTypeSet())); | 270 FieldTypeSet())); |
296 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[1]), | 271 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[1]), |
297 false, | 272 false, |
298 FieldTypeSet())); | 273 FieldTypeSet())); |
299 fetcher = factory.GetFetcherByID(3); | 274 fetcher = factory.GetFetcherByID(3); |
300 EXPECT_EQ(NULL, fetcher); | 275 EXPECT_EQ(NULL, fetcher); |
301 | 276 |
302 // Modify form structures to miss the cache. | 277 // Modify form structures to miss the cache. |
303 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address line 2"), | 278 field.label = ASCIIToUTF16("Address line 2"); |
304 ASCIIToUTF16("address2"), | 279 field.name = ASCIIToUTF16("address2"); |
305 string16(), | 280 field.form_control_type = ASCIIToUTF16("text"); |
306 ASCIIToUTF16("text"), | 281 form.fields.push_back(field); |
307 0, | |
308 false)); | |
309 form_structure = new FormStructure(form); | 282 form_structure = new FormStructure(form); |
310 form_structures.push_back(form_structure); | 283 form_structures.push_back(form_structure); |
311 | 284 |
312 // Request with id 3. | 285 // Request with id 3. |
313 EXPECT_CALL(mock_metric_logger, | 286 EXPECT_CALL(mock_metric_logger, |
314 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); | 287 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); |
315 EXPECT_TRUE(helper.download_manager.StartQueryRequest(form_structures, | 288 EXPECT_TRUE(helper.download_manager.StartQueryRequest(form_structures, |
316 mock_metric_logger)); | 289 mock_metric_logger)); |
317 fetcher = factory.GetFetcherByID(3); | 290 fetcher = factory.GetFetcherByID(3); |
318 ASSERT_TRUE(fetcher); | 291 ASSERT_TRUE(fetcher); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 339 |
367 TEST_F(AutofillDownloadTest, CacheQueryTest) { | 340 TEST_F(AutofillDownloadTest, CacheQueryTest) { |
368 MessageLoopForUI message_loop; | 341 MessageLoopForUI message_loop; |
369 AutofillDownloadTestHelper helper; | 342 AutofillDownloadTestHelper helper; |
370 // Create and register factory. | 343 // Create and register factory. |
371 TestURLFetcherFactory factory; | 344 TestURLFetcherFactory factory; |
372 helper.InitContextGetter(); | 345 helper.InitContextGetter(); |
373 | 346 |
374 FormData form; | 347 FormData form; |
375 form.method = ASCIIToUTF16("post"); | 348 form.method = ASCIIToUTF16("post"); |
376 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), | 349 |
377 ASCIIToUTF16("username"), | 350 FormField field; |
378 string16(), | 351 field.label = ASCIIToUTF16("username"); |
379 ASCIIToUTF16("text"), | 352 field.name = ASCIIToUTF16("username"); |
380 0, | 353 field.form_control_type = ASCIIToUTF16("text"); |
381 false)); | 354 form.fields.push_back(field); |
382 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), | 355 field.label = ASCIIToUTF16("First Name"); |
383 ASCIIToUTF16("firstname"), | 356 field.name = ASCIIToUTF16("firstname"); |
384 string16(), | 357 form.fields.push_back(field); |
385 ASCIIToUTF16("text"), | 358 field.label = ASCIIToUTF16("Last Name"); |
386 0, | 359 field.name = ASCIIToUTF16("lastname"); |
387 false)); | 360 form.fields.push_back(field); |
388 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), | |
389 ASCIIToUTF16("lastname"), | |
390 string16(), | |
391 ASCIIToUTF16("text"), | |
392 0, | |
393 false)); | |
394 FormStructure *form_structure = new FormStructure(form); | 361 FormStructure *form_structure = new FormStructure(form); |
395 ScopedVector<FormStructure> form_structures0; | 362 ScopedVector<FormStructure> form_structures0; |
396 form_structures0.push_back(form_structure); | 363 form_structures0.push_back(form_structure); |
397 | 364 |
398 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), | 365 field.label = ASCIIToUTF16("email"); |
399 ASCIIToUTF16("email"), | 366 field.name = ASCIIToUTF16("email"); |
400 string16(), | 367 form.fields.push_back(field); |
401 ASCIIToUTF16("text"), | |
402 0, | |
403 false)); | |
404 // Slightly different form - so different request. | 368 // Slightly different form - so different request. |
405 form_structure = new FormStructure(form); | 369 form_structure = new FormStructure(form); |
406 ScopedVector<FormStructure> form_structures1; | 370 ScopedVector<FormStructure> form_structures1; |
407 form_structures1.push_back(form_structure); | 371 form_structures1.push_back(form_structure); |
408 | 372 |
409 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), | 373 field.label = ASCIIToUTF16("email2"); |
410 ASCIIToUTF16("email2"), | 374 field.name = ASCIIToUTF16("email2"); |
411 string16(), | 375 form.fields.push_back(field); |
412 ASCIIToUTF16("text"), | |
413 0, | |
414 false)); | |
415 // Slightly different form - so different request. | 376 // Slightly different form - so different request. |
416 form_structure = new FormStructure(form); | 377 form_structure = new FormStructure(form); |
417 ScopedVector<FormStructure> form_structures2; | 378 ScopedVector<FormStructure> form_structures2; |
418 form_structures2.push_back(form_structure); | 379 form_structures2.push_back(form_structure); |
419 | 380 |
420 // Limit cache to two forms. | 381 // Limit cache to two forms. |
421 helper.LimitCache(2); | 382 helper.LimitCache(2); |
422 | 383 |
423 const char *responses[] = { | 384 const char *responses[] = { |
424 "<autofillqueryresponse>" | 385 "<autofillqueryresponse>" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 fetcher = factory.GetFetcherByID(3); | 496 fetcher = factory.GetFetcherByID(3); |
536 ASSERT_TRUE(fetcher); | 497 ASSERT_TRUE(fetcher); |
537 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(), | 498 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(), |
538 net::URLRequestStatus(), | 499 net::URLRequestStatus(), |
539 200, net::ResponseCookies(), | 500 200, net::ResponseCookies(), |
540 std::string(responses[0])); | 501 std::string(responses[0])); |
541 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); | 502 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); |
542 EXPECT_EQ(responses[0], helper.responses_.front().response); | 503 EXPECT_EQ(responses[0], helper.responses_.front().response); |
543 } | 504 } |
544 | 505 |
OLD | NEW |