Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/autofill/autofill_download_unittest.cc

Issue 7576001: Refactor webkit_glue::FormField to remove hacky methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright header Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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");
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
134 ASCIIToUTF16("firstname"), 135 field.label = ASCIIToUTF16("First Name");
135 string16(), 136 field.name = ASCIIToUTF16("firstname");
136 ASCIIToUTF16("text"), 137 field.form_control_type = ASCIIToUTF16("text");
137 0, 138 form.fields.push_back(field);
138 false)); 139
139 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 140 field.label = ASCIIToUTF16("Last Name");
140 ASCIIToUTF16("lastname"), 141 field.name = ASCIIToUTF16("lastname");
141 string16(), 142 field.form_control_type = ASCIIToUTF16("text");
142 ASCIIToUTF16("text"), 143 form.fields.push_back(field);
143 0, 144
144 false)); 145 field.label = ASCIIToUTF16("email");
145 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 146 field.name = ASCIIToUTF16("email");
146 ASCIIToUTF16("email"), 147 field.form_control_type = ASCIIToUTF16("text");
147 string16(), 148 form.fields.push_back(field);
148 ASCIIToUTF16("text"), 149
149 0, 150 field.label = ASCIIToUTF16("email2");
150 false)); 151 field.name = ASCIIToUTF16("email2");
151 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), 152 field.form_control_type = ASCIIToUTF16("text");
152 ASCIIToUTF16("email2"), 153 form.fields.push_back(field);
153 string16(), 154
154 ASCIIToUTF16("text"), 155 field.label = ASCIIToUTF16("password");
155 0, 156 field.name = ASCIIToUTF16("password");
156 false)); 157 field.form_control_type = ASCIIToUTF16("password");
157 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), 158 form.fields.push_back(field);
158 ASCIIToUTF16("password"), 159
159 string16(), 160 field.label = string16();
160 ASCIIToUTF16("password"), 161 field.name = ASCIIToUTF16("Submit");
161 0, 162 field.form_control_type = ASCIIToUTF16("submit");
162 false)); 163 form.fields.push_back(field);
163 form.fields.push_back(webkit_glue::FormField(string16(),
164 ASCIIToUTF16("Submit"),
165 string16(),
166 ASCIIToUTF16("submit"),
167 0,
168 false));
169 164
170 FormStructure *form_structure = new FormStructure(form); 165 FormStructure *form_structure = new FormStructure(form);
171 ScopedVector<FormStructure> form_structures; 166 ScopedVector<FormStructure> form_structures;
172 form_structures.push_back(form_structure); 167 form_structures.push_back(form_structure);
173 168
174 form.fields.clear(); 169 form.fields.clear();
175 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address"), 170
176 ASCIIToUTF16("address"), 171 field.label = ASCIIToUTF16("address");
177 string16(), 172 field.name = ASCIIToUTF16("address");
178 ASCIIToUTF16("text"), 173 field.form_control_type = ASCIIToUTF16("text");
179 0, 174 form.fields.push_back(field);
180 false)); 175
181 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), 176 field.label = ASCIIToUTF16("address2");
182 ASCIIToUTF16("address2"), 177 field.name = ASCIIToUTF16("address2");
183 string16(), 178 field.form_control_type = ASCIIToUTF16("text");
184 ASCIIToUTF16("text"), 179 form.fields.push_back(field);
185 0, 180
186 false)); 181 field.label = ASCIIToUTF16("city");
187 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), 182 field.name = ASCIIToUTF16("city");
188 ASCIIToUTF16("city"), 183 field.form_control_type = ASCIIToUTF16("text");
189 string16(), 184 form.fields.push_back(field);
190 ASCIIToUTF16("text"), 185
191 0, 186 field.label = string16();
192 false)); 187 field.name = ASCIIToUTF16("Submit");
193 form.fields.push_back(webkit_glue::FormField(string16(), 188 field.form_control_type = ASCIIToUTF16("submit");
194 ASCIIToUTF16("Submit"), 189 form.fields.push_back(field);
195 string16(), 190
196 ASCIIToUTF16("submit"),
197 0,
198 false));
199 form_structure = new FormStructure(form); 191 form_structure = new FormStructure(form);
200 form_structures.push_back(form_structure); 192 form_structures.push_back(form_structure);
201 193
202 // Request with id 0. 194 // Request with id 0.
203 MockAutofillMetrics mock_metric_logger; 195 MockAutofillMetrics mock_metric_logger;
204 EXPECT_CALL(mock_metric_logger, 196 EXPECT_CALL(mock_metric_logger,
205 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(2); 197 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(2);
206 // First one will fail because context is not set up. 198 // First one will fail because context is not set up.
207 EXPECT_FALSE(helper.download_manager.StartQueryRequest(form_structures, 199 EXPECT_FALSE(helper.download_manager.StartQueryRequest(form_structures,
208 mock_metric_logger)); 200 mock_metric_logger));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]), 285 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]),
294 true, 286 true,
295 FieldTypeSet())); 287 FieldTypeSet()));
296 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[1]), 288 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[1]),
297 false, 289 false,
298 FieldTypeSet())); 290 FieldTypeSet()));
299 fetcher = factory.GetFetcherByID(3); 291 fetcher = factory.GetFetcherByID(3);
300 EXPECT_EQ(NULL, fetcher); 292 EXPECT_EQ(NULL, fetcher);
301 293
302 // Modify form structures to miss the cache. 294 // Modify form structures to miss the cache.
303 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address line 2"), 295 field.label = ASCIIToUTF16("Address line 2");
304 ASCIIToUTF16("address2"), 296 field.name = ASCIIToUTF16("address2");
305 string16(), 297 field.form_control_type = ASCIIToUTF16("text");
306 ASCIIToUTF16("text"), 298 form.fields.push_back(field);
307 0,
308 false));
309 form_structure = new FormStructure(form); 299 form_structure = new FormStructure(form);
310 form_structures.push_back(form_structure); 300 form_structures.push_back(form_structure);
311 301
312 // Request with id 3. 302 // Request with id 3.
313 EXPECT_CALL(mock_metric_logger, 303 EXPECT_CALL(mock_metric_logger,
314 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); 304 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1);
315 EXPECT_TRUE(helper.download_manager.StartQueryRequest(form_structures, 305 EXPECT_TRUE(helper.download_manager.StartQueryRequest(form_structures,
316 mock_metric_logger)); 306 mock_metric_logger));
317 fetcher = factory.GetFetcherByID(3); 307 fetcher = factory.GetFetcherByID(3);
318 ASSERT_TRUE(fetcher); 308 ASSERT_TRUE(fetcher);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 356
367 TEST_F(AutofillDownloadTest, CacheQueryTest) { 357 TEST_F(AutofillDownloadTest, CacheQueryTest) {
368 MessageLoopForUI message_loop; 358 MessageLoopForUI message_loop;
369 AutofillDownloadTestHelper helper; 359 AutofillDownloadTestHelper helper;
370 // Create and register factory. 360 // Create and register factory.
371 TestURLFetcherFactory factory; 361 TestURLFetcherFactory factory;
372 helper.InitContextGetter(); 362 helper.InitContextGetter();
373 363
374 FormData form; 364 FormData form;
375 form.method = ASCIIToUTF16("post"); 365 form.method = ASCIIToUTF16("post");
376 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), 366
377 ASCIIToUTF16("username"), 367 FormField field;
378 string16(), 368 field.form_control_type = ASCIIToUTF16("text");
379 ASCIIToUTF16("text"), 369
380 0, 370 field.label = ASCIIToUTF16("username");
381 false)); 371 field.name = ASCIIToUTF16("username");
382 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), 372 form.fields.push_back(field);
383 ASCIIToUTF16("firstname"), 373
384 string16(), 374 field.label = ASCIIToUTF16("First Name");
385 ASCIIToUTF16("text"), 375 field.name = ASCIIToUTF16("firstname");
386 0, 376 form.fields.push_back(field);
387 false)); 377
388 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), 378 field.label = ASCIIToUTF16("Last Name");
389 ASCIIToUTF16("lastname"), 379 field.name = ASCIIToUTF16("lastname");
390 string16(), 380 form.fields.push_back(field);
391 ASCIIToUTF16("text"), 381
392 0,
393 false));
394 FormStructure *form_structure = new FormStructure(form); 382 FormStructure *form_structure = new FormStructure(form);
395 ScopedVector<FormStructure> form_structures0; 383 ScopedVector<FormStructure> form_structures0;
396 form_structures0.push_back(form_structure); 384 form_structures0.push_back(form_structure);
397 385
398 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), 386 // Add a slightly different form, which should result in a different request.
399 ASCIIToUTF16("email"), 387 field.label = ASCIIToUTF16("email");
400 string16(), 388 field.name = ASCIIToUTF16("email");
401 ASCIIToUTF16("text"), 389 form.fields.push_back(field);
402 0,
403 false));
404 // Slightly different form - so different request.
405 form_structure = new FormStructure(form); 390 form_structure = new FormStructure(form);
406 ScopedVector<FormStructure> form_structures1; 391 ScopedVector<FormStructure> form_structures1;
407 form_structures1.push_back(form_structure); 392 form_structures1.push_back(form_structure);
408 393
409 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), 394 // Add another slightly different form, which should also result in a
410 ASCIIToUTF16("email2"), 395 // different request.
411 string16(), 396 field.label = ASCIIToUTF16("email2");
412 ASCIIToUTF16("text"), 397 field.name = ASCIIToUTF16("email2");
413 0, 398 form.fields.push_back(field);
414 false));
415 // Slightly different form - so different request.
416 form_structure = new FormStructure(form); 399 form_structure = new FormStructure(form);
417 ScopedVector<FormStructure> form_structures2; 400 ScopedVector<FormStructure> form_structures2;
418 form_structures2.push_back(form_structure); 401 form_structures2.push_back(form_structure);
419 402
420 // Limit cache to two forms. 403 // Limit cache to two forms.
421 helper.LimitCache(2); 404 helper.LimitCache(2);
422 405
423 const char *responses[] = { 406 const char *responses[] = {
424 "<autofillqueryresponse>" 407 "<autofillqueryresponse>"
425 "<field autofilltype=\"0\" />" 408 "<field autofilltype=\"0\" />"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 fetcher = factory.GetFetcherByID(3); 518 fetcher = factory.GetFetcherByID(3);
536 ASSERT_TRUE(fetcher); 519 ASSERT_TRUE(fetcher);
537 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(), 520 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(),
538 net::URLRequestStatus(), 521 net::URLRequestStatus(),
539 200, net::ResponseCookies(), 522 200, net::ResponseCookies(),
540 std::string(responses[0])); 523 std::string(responses[0]));
541 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); 524 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size());
542 EXPECT_EQ(responses[0], helper.responses_.front().response); 525 EXPECT_EQ(responses[0], helper.responses_.front().response);
543 } 526 }
544 527
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_common_test.cc ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698