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/test_url_request_context_getter.h" | 15 #include "chrome/test/test_url_request_context_getter.h" |
16 #include "chrome/test/testing_browser_process.h" | 16 #include "chrome/test/testing_browser_process.h" |
17 #include "chrome/test/testing_browser_process_test.h" | 17 #include "chrome/test/testing_browser_process_test.h" |
18 #include "chrome/test/testing_profile.h" | 18 #include "chrome/test/testing_profile.h" |
19 #include "content/common/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::WebInputElement; | 27 using WebKit::WebInputElement; |
28 | 28 |
29 namespace { | 29 namespace { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 scoped_refptr<net::URLRequestContextGetter> request_context_getter; | 114 scoped_refptr<net::URLRequestContextGetter> request_context_getter; |
115 }; | 115 }; |
116 | 116 |
117 typedef TestingBrowserProcessTest AutofillDownloadTest; | 117 typedef TestingBrowserProcessTest AutofillDownloadTest; |
118 | 118 |
119 TEST_F(AutofillDownloadTest, QueryAndUploadTest) { | 119 TEST_F(AutofillDownloadTest, QueryAndUploadTest) { |
120 MessageLoopForUI message_loop; | 120 MessageLoopForUI message_loop; |
121 // Create and register factory. | 121 // Create and register factory. |
122 AutofillDownloadTestHelper helper; | 122 AutofillDownloadTestHelper helper; |
123 TestURLFetcherFactory factory; | 123 TestURLFetcherFactory factory; |
124 URLFetcher::set_factory(&factory); | |
125 | 124 |
126 FormData form; | 125 FormData form; |
127 form.method = ASCIIToUTF16("post"); | 126 form.method = ASCIIToUTF16("post"); |
128 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), | 127 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), |
129 ASCIIToUTF16("username"), | 128 ASCIIToUTF16("username"), |
130 string16(), | 129 string16(), |
131 ASCIIToUTF16("text"), | 130 ASCIIToUTF16("text"), |
132 0, | 131 0, |
133 false)); | 132 false)); |
134 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), | 133 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 helper.responses_.front().type_of_response); | 355 helper.responses_.front().type_of_response); |
357 EXPECT_EQ(503, helper.responses_.front().error); | 356 EXPECT_EQ(503, helper.responses_.front().error); |
358 helper.responses_.pop_front(); | 357 helper.responses_.pop_front(); |
359 | 358 |
360 // Upload requests should be ignored for the next 10 seconds. | 359 // Upload requests should be ignored for the next 10 seconds. |
361 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]), | 360 EXPECT_FALSE(helper.download_manager.StartUploadRequest(*(form_structures[0]), |
362 true, | 361 true, |
363 FieldTypeSet())); | 362 FieldTypeSet())); |
364 fetcher = factory.GetFetcherByID(5); | 363 fetcher = factory.GetFetcherByID(5); |
365 EXPECT_EQ(NULL, fetcher); | 364 EXPECT_EQ(NULL, fetcher); |
366 | |
367 // Make sure consumer of URLFetcher does the right thing. | |
368 URLFetcher::set_factory(NULL); | |
369 } | 365 } |
370 | 366 |
371 TEST_F(AutofillDownloadTest, CacheQueryTest) { | 367 TEST_F(AutofillDownloadTest, CacheQueryTest) { |
372 MessageLoopForUI message_loop; | 368 MessageLoopForUI message_loop; |
373 AutofillDownloadTestHelper helper; | 369 AutofillDownloadTestHelper helper; |
374 // Create and register factory. | 370 // Create and register factory. |
375 TestURLFetcherFactory factory; | 371 TestURLFetcherFactory factory; |
376 URLFetcher::set_factory(&factory); | |
377 helper.InitContextGetter(); | 372 helper.InitContextGetter(); |
378 | 373 |
379 FormData form; | 374 FormData form; |
380 form.method = ASCIIToUTF16("post"); | 375 form.method = ASCIIToUTF16("post"); |
381 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), | 376 form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), |
382 ASCIIToUTF16("username"), | 377 ASCIIToUTF16("username"), |
383 string16(), | 378 string16(), |
384 ASCIIToUTF16("text"), | 379 ASCIIToUTF16("text"), |
385 0, | 380 0, |
386 false)); | 381 false)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EXPECT_EQ(static_cast<size_t>(0), helper.responses_.size()); | 533 EXPECT_EQ(static_cast<size_t>(0), helper.responses_.size()); |
539 | 534 |
540 fetcher = factory.GetFetcherByID(3); | 535 fetcher = factory.GetFetcherByID(3); |
541 ASSERT_TRUE(fetcher); | 536 ASSERT_TRUE(fetcher); |
542 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(), | 537 fetcher->delegate()->OnURLFetchComplete(fetcher, GURL(), |
543 net::URLRequestStatus(), | 538 net::URLRequestStatus(), |
544 200, net::ResponseCookies(), | 539 200, net::ResponseCookies(), |
545 std::string(responses[0])); | 540 std::string(responses[0])); |
546 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); | 541 ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); |
547 EXPECT_EQ(responses[0], helper.responses_.front().response); | 542 EXPECT_EQ(responses[0], helper.responses_.front().response); |
548 | |
549 // Make sure consumer of URLFetcher does the right thing. | |
550 URLFetcher::set_factory(NULL); | |
551 } | 543 } |
552 | 544 |
OLD | NEW |