| OLD | NEW |
| 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/core/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" |
| 16 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 17 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const char kImageURL[] = "http://www.example.com/image"; | 25 const char kImageURL[] = "http://www.example.com/image"; |
| 25 const char kURLResponseData[] = "EncodedImageData"; | 26 const char kURLResponseData[] = "EncodedImageData"; |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 namespace image_fetcher { | 30 namespace image_fetcher { |
| 30 | 31 |
| 31 class ImageDataFetcherTest : public testing::Test { | 32 class ImageDataFetcherTest : public testing::Test { |
| 32 public: | 33 public: |
| 33 ImageDataFetcherTest() | 34 ImageDataFetcherTest() |
| 34 : test_request_context_getter_( | 35 : test_request_context_getter_( |
| 35 new net::TestURLRequestContextGetter(message_loop_.task_runner())), | 36 new net::TestURLRequestContextGetter(message_loop_.task_runner())), |
| 36 image_data_fetcher_(test_request_context_getter_.get()) {} | 37 image_data_fetcher_(test_request_context_getter_.get(), |
| 38 TRAFFIC_ANNOTATION_FOR_TESTS) {} |
| 37 ~ImageDataFetcherTest() override {} | 39 ~ImageDataFetcherTest() override {} |
| 38 | 40 |
| 39 MOCK_METHOD2(OnImageDataFetched, | 41 MOCK_METHOD2(OnImageDataFetched, |
| 40 void(const std::string&, const RequestMetadata&)); | 42 void(const std::string&, const RequestMetadata&)); |
| 41 | 43 |
| 42 MOCK_METHOD2(OnImageDataFetchedFailedRequest, | 44 MOCK_METHOD2(OnImageDataFetchedFailedRequest, |
| 43 void(const std::string&, const RequestMetadata&)); | 45 void(const std::string&, const RequestMetadata&)); |
| 44 | 46 |
| 45 MOCK_METHOD2(OnImageDataFetchedMultipleRequests, | 47 MOCK_METHOD2(OnImageDataFetchedMultipleRequests, |
| 46 void(const std::string&, const RequestMetadata&)); | 48 void(const std::string&, const RequestMetadata&)); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 ASSERT_NE(nullptr, fetcher_factory_.GetFetcherByID(0)); | 290 ASSERT_NE(nullptr, fetcher_factory_.GetFetcherByID(0)); |
| 289 | 291 |
| 290 test_url_fetcher->delegate()->OnURLFetchDownloadProgress( | 292 test_url_fetcher->delegate()->OnURLFetchDownloadProgress( |
| 291 test_url_fetcher, kMaxDownloadBytes + 1, // Limits are exceeded. | 293 test_url_fetcher, kMaxDownloadBytes + 1, // Limits are exceeded. |
| 292 /*total=*/-1, /*current_network_bytes=*/0); | 294 /*total=*/-1, /*current_network_bytes=*/0); |
| 293 // ... and be canceled. | 295 // ... and be canceled. |
| 294 EXPECT_EQ(nullptr, fetcher_factory_.GetFetcherByID(0)); | 296 EXPECT_EQ(nullptr, fetcher_factory_.GetFetcherByID(0)); |
| 295 } | 297 } |
| 296 | 298 |
| 297 } // namespace image_fetcher | 299 } // namespace image_fetcher |
| OLD | NEW |