| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 field.label = ASCIIToUTF16("password"); | 157 field.label = ASCIIToUTF16("password"); |
| 158 field.name = ASCIIToUTF16("password"); | 158 field.name = ASCIIToUTF16("password"); |
| 159 field.form_control_type = "password"; | 159 field.form_control_type = "password"; |
| 160 form.fields.push_back(field); | 160 form.fields.push_back(field); |
| 161 | 161 |
| 162 field.label = base::string16(); | 162 field.label = base::string16(); |
| 163 field.name = ASCIIToUTF16("Submit"); | 163 field.name = ASCIIToUTF16("Submit"); |
| 164 field.form_control_type = "submit"; | 164 field.form_control_type = "submit"; |
| 165 form.fields.push_back(field); | 165 form.fields.push_back(field); |
| 166 | 166 |
| 167 FormStructure *form_structure = new FormStructure(form, std::string()); | 167 FormStructure *form_structure = new FormStructure(form); |
| 168 ScopedVector<FormStructure> form_structures; | 168 ScopedVector<FormStructure> form_structures; |
| 169 form_structures.push_back(form_structure); | 169 form_structures.push_back(form_structure); |
| 170 | 170 |
| 171 form.fields.clear(); | 171 form.fields.clear(); |
| 172 | 172 |
| 173 field.label = ASCIIToUTF16("address"); | 173 field.label = ASCIIToUTF16("address"); |
| 174 field.name = ASCIIToUTF16("address"); | 174 field.name = ASCIIToUTF16("address"); |
| 175 field.form_control_type = "text"; | 175 field.form_control_type = "text"; |
| 176 form.fields.push_back(field); | 176 form.fields.push_back(field); |
| 177 | 177 |
| 178 field.label = ASCIIToUTF16("address2"); | 178 field.label = ASCIIToUTF16("address2"); |
| 179 field.name = ASCIIToUTF16("address2"); | 179 field.name = ASCIIToUTF16("address2"); |
| 180 field.form_control_type = "text"; | 180 field.form_control_type = "text"; |
| 181 form.fields.push_back(field); | 181 form.fields.push_back(field); |
| 182 | 182 |
| 183 field.label = ASCIIToUTF16("city"); | 183 field.label = ASCIIToUTF16("city"); |
| 184 field.name = ASCIIToUTF16("city"); | 184 field.name = ASCIIToUTF16("city"); |
| 185 field.form_control_type = "text"; | 185 field.form_control_type = "text"; |
| 186 form.fields.push_back(field); | 186 form.fields.push_back(field); |
| 187 | 187 |
| 188 field.label = base::string16(); | 188 field.label = base::string16(); |
| 189 field.name = ASCIIToUTF16("Submit"); | 189 field.name = ASCIIToUTF16("Submit"); |
| 190 field.form_control_type = "submit"; | 190 field.form_control_type = "submit"; |
| 191 form.fields.push_back(field); | 191 form.fields.push_back(field); |
| 192 | 192 |
| 193 form_structure = new FormStructure(form, std::string()); | 193 form_structure = new FormStructure(form); |
| 194 form_structures.push_back(form_structure); | 194 form_structures.push_back(form_structure); |
| 195 | 195 |
| 196 // Request with id 0. | 196 // Request with id 0. |
| 197 MockAutofillMetrics mock_metric_logger; | 197 MockAutofillMetrics mock_metric_logger; |
| 198 EXPECT_CALL(mock_metric_logger, | 198 EXPECT_CALL(mock_metric_logger, |
| 199 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); | 199 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); |
| 200 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), | 200 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), |
| 201 mock_metric_logger)); | 201 mock_metric_logger)); |
| 202 // Set upload to 100% so requests happen. | 202 // Set upload to 100% so requests happen. |
| 203 download_manager_.SetPositiveUploadRate(1.0); | 203 download_manager_.SetPositiveUploadRate(1.0); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 EXPECT_FALSE(download_manager_.StartUploadRequest( | 276 EXPECT_FALSE(download_manager_.StartUploadRequest( |
| 277 *(form_structures[1]), false, ServerFieldTypeSet())); | 277 *(form_structures[1]), false, ServerFieldTypeSet())); |
| 278 fetcher = factory.GetFetcherByID(3); | 278 fetcher = factory.GetFetcherByID(3); |
| 279 EXPECT_EQ(NULL, fetcher); | 279 EXPECT_EQ(NULL, fetcher); |
| 280 | 280 |
| 281 // Modify form structures to miss the cache. | 281 // Modify form structures to miss the cache. |
| 282 field.label = ASCIIToUTF16("Address line 2"); | 282 field.label = ASCIIToUTF16("Address line 2"); |
| 283 field.name = ASCIIToUTF16("address2"); | 283 field.name = ASCIIToUTF16("address2"); |
| 284 field.form_control_type = "text"; | 284 field.form_control_type = "text"; |
| 285 form.fields.push_back(field); | 285 form.fields.push_back(field); |
| 286 form_structure = new FormStructure(form, std::string()); | 286 form_structure = new FormStructure(form); |
| 287 form_structures.push_back(form_structure); | 287 form_structures.push_back(form_structure); |
| 288 | 288 |
| 289 // Request with id 3. | 289 // Request with id 3. |
| 290 EXPECT_CALL(mock_metric_logger, | 290 EXPECT_CALL(mock_metric_logger, |
| 291 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); | 291 LogServerQueryMetric(AutofillMetrics::QUERY_SENT)).Times(1); |
| 292 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), | 292 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get(), |
| 293 mock_metric_logger)); | 293 mock_metric_logger)); |
| 294 fetcher = factory.GetFetcherByID(3); | 294 fetcher = factory.GetFetcherByID(3); |
| 295 ASSERT_TRUE(fetcher); | 295 ASSERT_TRUE(fetcher); |
| 296 fetcher->set_backoff_delay(TestTimeouts::action_max_timeout()); | 296 fetcher->set_backoff_delay(TestTimeouts::action_max_timeout()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 form.fields.push_back(field); | 347 form.fields.push_back(field); |
| 348 | 348 |
| 349 field.label = ASCIIToUTF16("First Name"); | 349 field.label = ASCIIToUTF16("First Name"); |
| 350 field.name = ASCIIToUTF16("firstname"); | 350 field.name = ASCIIToUTF16("firstname"); |
| 351 form.fields.push_back(field); | 351 form.fields.push_back(field); |
| 352 | 352 |
| 353 field.label = ASCIIToUTF16("Last Name"); | 353 field.label = ASCIIToUTF16("Last Name"); |
| 354 field.name = ASCIIToUTF16("lastname"); | 354 field.name = ASCIIToUTF16("lastname"); |
| 355 form.fields.push_back(field); | 355 form.fields.push_back(field); |
| 356 | 356 |
| 357 FormStructure *form_structure = new FormStructure(form, std::string()); | 357 FormStructure *form_structure = new FormStructure(form); |
| 358 ScopedVector<FormStructure> form_structures0; | 358 ScopedVector<FormStructure> form_structures0; |
| 359 form_structures0.push_back(form_structure); | 359 form_structures0.push_back(form_structure); |
| 360 | 360 |
| 361 // Add a slightly different form, which should result in a different request. | 361 // Add a slightly different form, which should result in a different request. |
| 362 field.label = ASCIIToUTF16("email"); | 362 field.label = ASCIIToUTF16("email"); |
| 363 field.name = ASCIIToUTF16("email"); | 363 field.name = ASCIIToUTF16("email"); |
| 364 form.fields.push_back(field); | 364 form.fields.push_back(field); |
| 365 form_structure = new FormStructure(form, std::string()); | 365 form_structure = new FormStructure(form); |
| 366 ScopedVector<FormStructure> form_structures1; | 366 ScopedVector<FormStructure> form_structures1; |
| 367 form_structures1.push_back(form_structure); | 367 form_structures1.push_back(form_structure); |
| 368 | 368 |
| 369 // Add another slightly different form, which should also result in a | 369 // Add another slightly different form, which should also result in a |
| 370 // different request. | 370 // different request. |
| 371 field.label = ASCIIToUTF16("email2"); | 371 field.label = ASCIIToUTF16("email2"); |
| 372 field.name = ASCIIToUTF16("email2"); | 372 field.name = ASCIIToUTF16("email2"); |
| 373 form.fields.push_back(field); | 373 form.fields.push_back(field); |
| 374 form_structure = new FormStructure(form, std::string()); | 374 form_structure = new FormStructure(form); |
| 375 ScopedVector<FormStructure> form_structures2; | 375 ScopedVector<FormStructure> form_structures2; |
| 376 form_structures2.push_back(form_structure); | 376 form_structures2.push_back(form_structure); |
| 377 | 377 |
| 378 // Limit cache to two forms. | 378 // Limit cache to two forms. |
| 379 LimitCache(2); | 379 LimitCache(2); |
| 380 | 380 |
| 381 const char *responses[] = { | 381 const char *responses[] = { |
| 382 "<autofillqueryresponse>" | 382 "<autofillqueryresponse>" |
| 383 "<field autofilltype=\"0\" />" | 383 "<field autofilltype=\"0\" />" |
| 384 "<field autofilltype=\"3\" />" | 384 "<field autofilltype=\"3\" />" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); | 482 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); |
| 483 | 483 |
| 484 fetcher = factory.GetFetcherByID(3); | 484 fetcher = factory.GetFetcherByID(3); |
| 485 ASSERT_TRUE(fetcher); | 485 ASSERT_TRUE(fetcher); |
| 486 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); | 486 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); |
| 487 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); | 487 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); |
| 488 EXPECT_EQ(responses[0], responses_.front().response); | 488 EXPECT_EQ(responses[0], responses_.front().response); |
| 489 } | 489 } |
| 490 | 490 |
| 491 } // namespace autofill | 491 } // namespace autofill |
| OLD | NEW |