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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 field.label = ASCIIToUTF16("password"); | 172 field.label = ASCIIToUTF16("password"); |
173 field.name = ASCIIToUTF16("password"); | 173 field.name = ASCIIToUTF16("password"); |
174 field.form_control_type = "password"; | 174 field.form_control_type = "password"; |
175 form.fields.push_back(field); | 175 form.fields.push_back(field); |
176 | 176 |
177 field.label = string16(); | 177 field.label = string16(); |
178 field.name = ASCIIToUTF16("Submit"); | 178 field.name = ASCIIToUTF16("Submit"); |
179 field.form_control_type = "submit"; | 179 field.form_control_type = "submit"; |
180 form.fields.push_back(field); | 180 form.fields.push_back(field); |
181 | 181 |
182 FormStructure *form_structure = new FormStructure(form); | 182 FormStructure *form_structure = new FormStructure(form, std::string()); |
183 ScopedVector<FormStructure> form_structures; | 183 ScopedVector<FormStructure> form_structures; |
184 form_structures.push_back(form_structure); | 184 form_structures.push_back(form_structure); |
185 | 185 |
186 form.fields.clear(); | 186 form.fields.clear(); |
187 | 187 |
188 field.label = ASCIIToUTF16("address"); | 188 field.label = ASCIIToUTF16("address"); |
189 field.name = ASCIIToUTF16("address"); | 189 field.name = ASCIIToUTF16("address"); |
190 field.form_control_type = "text"; | 190 field.form_control_type = "text"; |
191 form.fields.push_back(field); | 191 form.fields.push_back(field); |
192 | 192 |
193 field.label = ASCIIToUTF16("address2"); | 193 field.label = ASCIIToUTF16("address2"); |
194 field.name = ASCIIToUTF16("address2"); | 194 field.name = ASCIIToUTF16("address2"); |
195 field.form_control_type = "text"; | 195 field.form_control_type = "text"; |
196 form.fields.push_back(field); | 196 form.fields.push_back(field); |
197 | 197 |
198 field.label = ASCIIToUTF16("city"); | 198 field.label = ASCIIToUTF16("city"); |
199 field.name = ASCIIToUTF16("city"); | 199 field.name = ASCIIToUTF16("city"); |
200 field.form_control_type = "text"; | 200 field.form_control_type = "text"; |
201 form.fields.push_back(field); | 201 form.fields.push_back(field); |
202 | 202 |
203 field.label = string16(); | 203 field.label = string16(); |
204 field.name = ASCIIToUTF16("Submit"); | 204 field.name = ASCIIToUTF16("Submit"); |
205 field.form_control_type = "submit"; | 205 field.form_control_type = "submit"; |
206 form.fields.push_back(field); | 206 form.fields.push_back(field); |
207 | 207 |
208 form_structure = new FormStructure(form); | 208 form_structure = new FormStructure(form, std::string()); |
209 form_structures.push_back(form_structure); | 209 form_structures.push_back(form_structure); |
210 | 210 |
211 // Request with id 0. | 211 // Request with id 0. |
212 MockAutofillMetrics mock_metric_logger; | 212 MockAutofillMetrics mock_metric_logger; |
213 EXPECT_CALL(mock_metric_logger, | 213 EXPECT_CALL(mock_metric_logger, |
214 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); | 214 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); |
215 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), | 215 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), |
216 mock_metric_logger)); | 216 mock_metric_logger)); |
217 // Set upload to 100% so requests happen. | 217 // Set upload to 100% so requests happen. |
218 download_manager_.SetPositiveUploadRate(1.0); | 218 download_manager_.SetPositiveUploadRate(1.0); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 EXPECT_FALSE(download_manager_.StartUploadRequest( | 291 EXPECT_FALSE(download_manager_.StartUploadRequest( |
292 *(form_structures[1]), false, FieldTypeSet())); | 292 *(form_structures[1]), false, FieldTypeSet())); |
293 fetcher = factory.GetFetcherByID(3); | 293 fetcher = factory.GetFetcherByID(3); |
294 EXPECT_EQ(NULL, fetcher); | 294 EXPECT_EQ(NULL, fetcher); |
295 | 295 |
296 // Modify form structures to miss the cache. | 296 // Modify form structures to miss the cache. |
297 field.label = ASCIIToUTF16("Address line 2"); | 297 field.label = ASCIIToUTF16("Address line 2"); |
298 field.name = ASCIIToUTF16("address2"); | 298 field.name = ASCIIToUTF16("address2"); |
299 field.form_control_type = "text"; | 299 field.form_control_type = "text"; |
300 form.fields.push_back(field); | 300 form.fields.push_back(field); |
301 form_structure = new FormStructure(form); | 301 form_structure = new FormStructure(form, std::string()); |
302 form_structures.push_back(form_structure); | 302 form_structures.push_back(form_structure); |
303 | 303 |
304 // Request with id 3. | 304 // Request with id 3. |
305 EXPECT_CALL(mock_metric_logger, | 305 EXPECT_CALL(mock_metric_logger, |
306 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); | 306 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); |
307 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), | 307 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), |
308 mock_metric_logger)); | 308 mock_metric_logger)); |
309 fetcher = factory.GetFetcherByID(3); | 309 fetcher = factory.GetFetcherByID(3); |
310 ASSERT_TRUE(fetcher); | 310 ASSERT_TRUE(fetcher); |
311 fetcher->set_backoff_delay(TestTimeouts::action_max_timeout()); | 311 fetcher->set_backoff_delay(TestTimeouts::action_max_timeout()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 form.fields.push_back(field); | 363 form.fields.push_back(field); |
364 | 364 |
365 field.label = ASCIIToUTF16("First Name"); | 365 field.label = ASCIIToUTF16("First Name"); |
366 field.name = ASCIIToUTF16("firstname"); | 366 field.name = ASCIIToUTF16("firstname"); |
367 form.fields.push_back(field); | 367 form.fields.push_back(field); |
368 | 368 |
369 field.label = ASCIIToUTF16("Last Name"); | 369 field.label = ASCIIToUTF16("Last Name"); |
370 field.name = ASCIIToUTF16("lastname"); | 370 field.name = ASCIIToUTF16("lastname"); |
371 form.fields.push_back(field); | 371 form.fields.push_back(field); |
372 | 372 |
373 FormStructure *form_structure = new FormStructure(form); | 373 FormStructure *form_structure = new FormStructure(form, std::string()); |
374 ScopedVector<FormStructure> form_structures0; | 374 ScopedVector<FormStructure> form_structures0; |
375 form_structures0.push_back(form_structure); | 375 form_structures0.push_back(form_structure); |
376 | 376 |
377 // Add a slightly different form, which should result in a different request. | 377 // Add a slightly different form, which should result in a different request. |
378 field.label = ASCIIToUTF16("email"); | 378 field.label = ASCIIToUTF16("email"); |
379 field.name = ASCIIToUTF16("email"); | 379 field.name = ASCIIToUTF16("email"); |
380 form.fields.push_back(field); | 380 form.fields.push_back(field); |
381 form_structure = new FormStructure(form); | 381 form_structure = new FormStructure(form, std::string()); |
382 ScopedVector<FormStructure> form_structures1; | 382 ScopedVector<FormStructure> form_structures1; |
383 form_structures1.push_back(form_structure); | 383 form_structures1.push_back(form_structure); |
384 | 384 |
385 // Add another slightly different form, which should also result in a | 385 // Add another slightly different form, which should also result in a |
386 // different request. | 386 // different request. |
387 field.label = ASCIIToUTF16("email2"); | 387 field.label = ASCIIToUTF16("email2"); |
388 field.name = ASCIIToUTF16("email2"); | 388 field.name = ASCIIToUTF16("email2"); |
389 form.fields.push_back(field); | 389 form.fields.push_back(field); |
390 form_structure = new FormStructure(form); | 390 form_structure = new FormStructure(form, std::string()); |
391 ScopedVector<FormStructure> form_structures2; | 391 ScopedVector<FormStructure> form_structures2; |
392 form_structures2.push_back(form_structure); | 392 form_structures2.push_back(form_structure); |
393 | 393 |
394 // Limit cache to two forms. | 394 // Limit cache to two forms. |
395 LimitCache(2); | 395 LimitCache(2); |
396 | 396 |
397 const char *responses[] = { | 397 const char *responses[] = { |
398 "<autofillqueryresponse>" | 398 "<autofillqueryresponse>" |
399 "<field autofilltype=\"0\" />" | 399 "<field autofilltype=\"0\" />" |
400 "<field autofilltype=\"3\" />" | 400 "<field autofilltype=\"3\" />" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 mock_metric_logger)); | 496 mock_metric_logger)); |
497 // No responses yet | 497 // No responses yet |
498 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); | 498 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); |
499 | 499 |
500 fetcher = factory.GetFetcherByID(3); | 500 fetcher = factory.GetFetcherByID(3); |
501 ASSERT_TRUE(fetcher); | 501 ASSERT_TRUE(fetcher); |
502 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); | 502 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); |
503 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); | 503 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); |
504 EXPECT_EQ(responses[0], responses_.front().response); | 504 EXPECT_EQ(responses[0], responses_.front().response); |
505 } | 505 } |
OLD | NEW |