| 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/image_data_fetcher.h" | 5 #include "components/image_fetcher/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/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 RequestMetadata expected_metadata; | 67 RequestMetadata expected_metadata; |
| 67 expected_metadata.mime_type = std::string("image/png"); | 68 expected_metadata.mime_type = std::string("image/png"); |
| 68 expected_metadata.response_code = net::HTTP_OK; | 69 expected_metadata.response_code = net::HTTP_OK; |
| 69 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData), | 70 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData), |
| 70 expected_metadata)); | 71 expected_metadata)); |
| 71 | 72 |
| 72 // Get and configure the TestURLFetcher. | 73 // Get and configure the TestURLFetcher. |
| 73 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); | 74 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); |
| 74 ASSERT_NE(nullptr, test_url_fetcher); | 75 ASSERT_NE(nullptr, test_url_fetcher); |
| 76 EXPECT_TRUE(test_url_fetcher->GetLoadFlags() & net::LOAD_DO_NOT_SEND_COOKIES); |
| 77 EXPECT_TRUE(test_url_fetcher->GetLoadFlags() & net::LOAD_DO_NOT_SAVE_COOKIES); |
| 78 EXPECT_TRUE(test_url_fetcher->GetLoadFlags() & |
| 79 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 75 test_url_fetcher->set_status( | 80 test_url_fetcher->set_status( |
| 76 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); | 81 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); |
| 77 test_url_fetcher->SetResponseString(kURLResponseData); | 82 test_url_fetcher->SetResponseString(kURLResponseData); |
| 78 test_url_fetcher->set_response_code(net::HTTP_OK); | 83 test_url_fetcher->set_response_code(net::HTTP_OK); |
| 79 | 84 |
| 80 std::string raw_header = | 85 std::string raw_header = |
| 81 "HTTP/1.1 200 OK\n" | 86 "HTTP/1.1 200 OK\n" |
| 82 "Content-type: image/png\n\n"; | 87 "Content-type: image/png\n\n"; |
| 83 std::replace(raw_header.begin(), raw_header.end(), '\n', '\0'); | 88 std::replace(raw_header.begin(), raw_header.end(), '\n', '\0'); |
| 84 scoped_refptr<net::HttpResponseHeaders> headers( | 89 scoped_refptr<net::HttpResponseHeaders> headers( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); | 163 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); |
| 159 ASSERT_NE(nullptr, test_url_fetcher); | 164 ASSERT_NE(nullptr, test_url_fetcher); |
| 160 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); | 165 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); |
| 161 | 166 |
| 162 test_url_fetcher = fetcher_factory_.GetFetcherByID(1); | 167 test_url_fetcher = fetcher_factory_.GetFetcherByID(1); |
| 163 ASSERT_NE(nullptr, test_url_fetcher); | 168 ASSERT_NE(nullptr, test_url_fetcher); |
| 164 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); | 169 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); |
| 165 } | 170 } |
| 166 | 171 |
| 167 } // namespace image_fetcher | 172 } // namespace image_fetcher |
| OLD | NEW |