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

Side by Side Diff: components/autofill/core/browser/autofill_download_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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 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"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "components/autofill/core/browser/autofill_download.h" 12 #include "components/autofill/core/browser/autofill_download.h"
13 #include "components/autofill/core/browser/autofill_field.h" 13 #include "components/autofill/core/browser/autofill_field.h"
14 #include "components/autofill/core/browser/autofill_metrics.h" 14 #include "components/autofill/core/browser/autofill_metrics.h"
15 #include "components/autofill/core/browser/autofill_type.h" 15 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/form_structure.h" 16 #include "components/autofill/core/browser/form_structure.h"
17 #include "components/autofill/core/common/form_data.h" 17 #include "components/autofill/core/common/form_data.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "net/url_request/test_url_fetcher_factory.h" 19 #include "net/url_request/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/public/web/WebInputElement.h" 23 #include "third_party/WebKit/public/web/WebInputElement.h"
24 24
25 using content::BrowserThread;
26 using WebKit::WebInputElement; 25 using WebKit::WebInputElement;
27 26
28 namespace autofill { 27 namespace autofill {
29 28
30 namespace { 29 namespace {
31 30
32 class MockAutofillMetrics : public AutofillMetrics { 31 class MockAutofillMetrics : public AutofillMetrics {
33 public: 32 public:
34 MockAutofillMetrics() {} 33 MockAutofillMetrics() {}
35 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); 34 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
(...skipping 22 matching lines...) Expand all
58 // AutofillDownloadManager. Then it records responses to different initiated 57 // AutofillDownloadManager. Then it records responses to different initiated
59 // requests, which are verified later. To mock network requests 58 // requests, which are verified later. To mock network requests
60 // TestURLFetcherFactory is used, which creates URLFetchers that do not 59 // TestURLFetcherFactory is used, which creates URLFetchers that do not
61 // go over the wire, but allow calling back HTTP responses directly. 60 // go over the wire, but allow calling back HTTP responses directly.
62 // The responses in test are out of order and verify: successful query request, 61 // The responses in test are out of order and verify: successful query request,
63 // successful upload request, failed upload request. 62 // successful upload request, failed upload request.
64 class AutofillDownloadTest : public AutofillDownloadManager::Observer, 63 class AutofillDownloadTest : public AutofillDownloadManager::Observer,
65 public testing::Test { 64 public testing::Test {
66 public: 65 public:
67 AutofillDownloadTest() 66 AutofillDownloadTest()
68 : download_manager_(&profile_, this), 67 : download_manager_(&profile_, this) {
69 io_thread_(BrowserThread::IO) {
70 }
71
72 virtual void SetUp() {
73 io_thread_.StartIOThread();
74 profile_.CreateRequestContext();
75 }
76
77 virtual void TearDown() {
78 profile_.ResetRequestContext();
79 io_thread_.Stop();
80 } 68 }
81 69
82 void LimitCache(size_t cache_size) { 70 void LimitCache(size_t cache_size) {
83 download_manager_.set_max_form_cache_size(cache_size); 71 download_manager_.set_max_form_cache_size(cache_size);
84 } 72 }
85 73
86 // AutofillDownloadManager::Observer implementation. 74 // AutofillDownloadManager::Observer implementation.
87 virtual void OnLoadedServerPredictions( 75 virtual void OnLoadedServerPredictions(
88 const std::string& response_xml) OVERRIDE { 76 const std::string& response_xml) OVERRIDE {
89 ResponseData response; 77 ResponseData response;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 struct ResponseData { 109 struct ResponseData {
122 ResponseType type_of_response; 110 ResponseType type_of_response;
123 int error; 111 int error;
124 std::string signature; 112 std::string signature;
125 std::string response; 113 std::string response;
126 114
127 ResponseData() : type_of_response(REQUEST_QUERY_FAILED), error(0) {} 115 ResponseData() : type_of_response(REQUEST_QUERY_FAILED), error(0) {}
128 }; 116 };
129 std::list<ResponseData> responses_; 117 std::list<ResponseData> responses_;
130 118
119 content::TestBrowserThreadBundle thread_bundle_;
131 TestingProfile profile_; 120 TestingProfile profile_;
132 AutofillDownloadManager download_manager_; 121 AutofillDownloadManager download_manager_;
133
134 private:
135 // The profile's request context must be released on the IO thread.
136 content::TestBrowserThread io_thread_;
137 }; 122 };
138 123
139 TEST_F(AutofillDownloadTest, QueryAndUploadTest) { 124 TEST_F(AutofillDownloadTest, QueryAndUploadTest) {
140 base::MessageLoopForUI message_loop;
141 // Create and register factory. 125 // Create and register factory.
142 net::TestURLFetcherFactory factory; 126 net::TestURLFetcherFactory factory;
143 127
144 FormData form; 128 FormData form;
145 form.method = ASCIIToUTF16("post"); 129 form.method = ASCIIToUTF16("post");
146 130
147 FormFieldData field; 131 FormFieldData field;
148 field.label = ASCIIToUTF16("username"); 132 field.label = ASCIIToUTF16("username");
149 field.name = ASCIIToUTF16("username"); 133 field.name = ASCIIToUTF16("username");
150 field.form_control_type = "text"; 134 field.form_control_type = "text";
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 responses_.pop_front(); 326 responses_.pop_front();
343 327
344 // Upload requests should be ignored for the next 10 seconds. 328 // Upload requests should be ignored for the next 10 seconds.
345 EXPECT_FALSE(download_manager_.StartUploadRequest( 329 EXPECT_FALSE(download_manager_.StartUploadRequest(
346 *(form_structures[0]), true, FieldTypeSet())); 330 *(form_structures[0]), true, FieldTypeSet()));
347 fetcher = factory.GetFetcherByID(5); 331 fetcher = factory.GetFetcherByID(5);
348 EXPECT_EQ(NULL, fetcher); 332 EXPECT_EQ(NULL, fetcher);
349 } 333 }
350 334
351 TEST_F(AutofillDownloadTest, CacheQueryTest) { 335 TEST_F(AutofillDownloadTest, CacheQueryTest) {
352 base::MessageLoopForUI message_loop;
353 // Create and register factory. 336 // Create and register factory.
354 net::TestURLFetcherFactory factory; 337 net::TestURLFetcherFactory factory;
355 338
356 FormData form; 339 FormData form;
357 form.method = ASCIIToUTF16("post"); 340 form.method = ASCIIToUTF16("post");
358 341
359 FormFieldData field; 342 FormFieldData field;
360 field.form_control_type = "text"; 343 field.form_control_type = "text";
361 344
362 field.label = ASCIIToUTF16("username"); 345 field.label = ASCIIToUTF16("username");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 EXPECT_EQ(static_cast<size_t>(0), responses_.size()); 482 EXPECT_EQ(static_cast<size_t>(0), responses_.size());
500 483
501 fetcher = factory.GetFetcherByID(3); 484 fetcher = factory.GetFetcherByID(3);
502 ASSERT_TRUE(fetcher); 485 ASSERT_TRUE(fetcher);
503 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); 486 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0]));
504 ASSERT_EQ(static_cast<size_t>(1), responses_.size()); 487 ASSERT_EQ(static_cast<size_t>(1), responses_.size());
505 EXPECT_EQ(responses[0], responses_.front().response); 488 EXPECT_EQ(responses[0], responses_.front().response);
506 } 489 }
507 490
508 } // namespace autofill 491 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698