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

Side by Side Diff: components/image_fetcher/core/image_data_fetcher_unittest.cc

Issue 2761303002: Move common ImageFetcher component files to core/ (Closed)
Patch Set: Rebased. Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/image_fetcher/image_data_fetcher.h" 5 #include "components/image_fetcher/core/image_data_fetcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
14 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
15 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ImageDataFetcher image_data_fetcher_; 53 ImageDataFetcher image_data_fetcher_;
54 54
55 net::TestURLFetcherFactory fetcher_factory_; 55 net::TestURLFetcherFactory fetcher_factory_;
56 56
57 private: 57 private:
58 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcherTest); 58 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcherTest);
59 }; 59 };
60 60
61 TEST_F(ImageDataFetcherTest, FetchImageData) { 61 TEST_F(ImageDataFetcherTest, FetchImageData) {
62 image_data_fetcher_.FetchImageData( 62 image_data_fetcher_.FetchImageData(
63 GURL(kImageURL), 63 GURL(kImageURL), base::Bind(&ImageDataFetcherTest::OnImageDataFetched,
64 base::Bind(&ImageDataFetcherTest::OnImageDataFetched, 64 base::Unretained(this)));
65 base::Unretained(this)));
66 65
67 RequestMetadata expected_metadata; 66 RequestMetadata expected_metadata;
68 expected_metadata.mime_type = std::string("image/png"); 67 expected_metadata.mime_type = std::string("image/png");
69 expected_metadata.http_response_code = net::HTTP_OK; 68 expected_metadata.http_response_code = net::HTTP_OK;
70 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData), 69 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData),
71 expected_metadata)); 70 expected_metadata));
72 71
73 // Get and configure the TestURLFetcher. 72 // Get and configure the TestURLFetcher.
74 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); 73 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0);
75 ASSERT_NE(nullptr, test_url_fetcher); 74 ASSERT_NE(nullptr, test_url_fetcher);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 base::Unretained(this))); 166 base::Unretained(this)));
168 167
169 RequestMetadata expected_metadata; 168 RequestMetadata expected_metadata;
170 expected_metadata.http_response_code = net::URLFetcher::RESPONSE_CODE_INVALID; 169 expected_metadata.http_response_code = net::URLFetcher::RESPONSE_CODE_INVALID;
171 EXPECT_CALL( 170 EXPECT_CALL(
172 *this, OnImageDataFetchedFailedRequest(std::string(), expected_metadata)); 171 *this, OnImageDataFetchedFailedRequest(std::string(), expected_metadata));
173 172
174 // Get and configure the TestURLFetcher. 173 // Get and configure the TestURLFetcher.
175 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); 174 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0);
176 ASSERT_NE(nullptr, test_url_fetcher); 175 ASSERT_NE(nullptr, test_url_fetcher);
177 test_url_fetcher->set_status( 176 test_url_fetcher->set_status(net::URLRequestStatus(
178 net::URLRequestStatus(net::URLRequestStatus::FAILED, 177 net::URLRequestStatus::FAILED, net::ERR_INVALID_URL));
179 net::ERR_INVALID_URL));
180 178
181 // Call the URLFetcher delegate to continue the test. 179 // Call the URLFetcher delegate to continue the test.
182 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); 180 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher);
183 } 181 }
184 182
185 TEST_F(ImageDataFetcherTest, FetchImageData_MultipleRequests) { 183 TEST_F(ImageDataFetcherTest, FetchImageData_MultipleRequests) {
186 ImageDataFetcher::ImageDataFetcherCallback callback = 184 ImageDataFetcher::ImageDataFetcherCallback callback =
187 base::Bind(&ImageDataFetcherTest::OnImageDataFetchedMultipleRequests, 185 base::Bind(&ImageDataFetcherTest::OnImageDataFetchedMultipleRequests,
188 base::Unretained(this)); 186 base::Unretained(this));
189 EXPECT_CALL(*this, OnImageDataFetchedMultipleRequests(testing::_, testing::_)) 187 EXPECT_CALL(*this, OnImageDataFetchedMultipleRequests(testing::_, testing::_))
190 .Times(2); 188 .Times(2);
191 189
192 image_data_fetcher_.FetchImageData(GURL(kImageURL), callback); 190 image_data_fetcher_.FetchImageData(GURL(kImageURL), callback);
193 image_data_fetcher_.FetchImageData(GURL(kImageURL), callback); 191 image_data_fetcher_.FetchImageData(GURL(kImageURL), callback);
194 192
195 // Multiple calls to FetchImageData for the same URL will result in 193 // Multiple calls to FetchImageData for the same URL will result in
196 // multiple URLFetchers being created. 194 // multiple URLFetchers being created.
197 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); 195 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0);
198 ASSERT_NE(nullptr, test_url_fetcher); 196 ASSERT_NE(nullptr, test_url_fetcher);
199 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); 197 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher);
200 198
201 test_url_fetcher = fetcher_factory_.GetFetcherByID(1); 199 test_url_fetcher = fetcher_factory_.GetFetcherByID(1);
202 ASSERT_NE(nullptr, test_url_fetcher); 200 ASSERT_NE(nullptr, test_url_fetcher);
203 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); 201 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher);
204 } 202 }
205 203
206 } // namespace image_fetcher 204 } // namespace image_fetcher
OLDNEW
« no previous file with comments | « components/image_fetcher/core/image_data_fetcher.cc ('k') | components/image_fetcher/core/image_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698