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 |
23 const char kImageURL[] = "http://www.example.com/image"; | 24 const char kImageURL[] = "http://www.example.com/image"; |
24 const char kURLResponseData[] = "EncodedImageData"; | 25 const char kURLResponseData[] = "EncodedImageData"; |
25 | 26 |
| 27 using testing::_; |
| 28 |
26 } // namespace | 29 } // namespace |
27 | 30 |
28 namespace image_fetcher { | 31 namespace image_fetcher { |
29 | 32 |
30 class ImageDataFetcherTest : public testing::Test { | 33 class ImageDataFetcherTest : public testing::Test { |
31 public: | 34 public: |
32 ImageDataFetcherTest() | 35 ImageDataFetcherTest() |
33 : test_request_context_getter_( | 36 : test_request_context_getter_( |
34 new net::TestURLRequestContextGetter(message_loop_.task_runner())), | 37 new net::TestURLRequestContextGetter(message_loop_.task_runner())), |
35 image_data_fetcher_(test_request_context_getter_.get()) {} | 38 image_data_fetcher_(test_request_context_getter_.get()) {} |
(...skipping 29 matching lines...) Expand all Loading... |
65 | 68 |
66 RequestMetadata expected_metadata; | 69 RequestMetadata expected_metadata; |
67 expected_metadata.mime_type = std::string("image/png"); | 70 expected_metadata.mime_type = std::string("image/png"); |
68 expected_metadata.response_code = net::HTTP_OK; | 71 expected_metadata.response_code = net::HTTP_OK; |
69 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData), | 72 EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData), |
70 expected_metadata)); | 73 expected_metadata)); |
71 | 74 |
72 // Get and configure the TestURLFetcher. | 75 // Get and configure the TestURLFetcher. |
73 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); | 76 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); |
74 ASSERT_NE(nullptr, test_url_fetcher); | 77 ASSERT_NE(nullptr, test_url_fetcher); |
| 78 EXPECT_FALSE(test_url_fetcher->GetLoadFlags() & |
| 79 net::LOAD_DO_NOT_SEND_COOKIES); |
| 80 EXPECT_FALSE(test_url_fetcher->GetLoadFlags() & |
| 81 net::LOAD_DO_NOT_SAVE_COOKIES); |
75 test_url_fetcher->set_status( | 82 test_url_fetcher->set_status( |
76 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); | 83 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); |
77 test_url_fetcher->SetResponseString(kURLResponseData); | 84 test_url_fetcher->SetResponseString(kURLResponseData); |
78 test_url_fetcher->set_response_code(net::HTTP_OK); | 85 test_url_fetcher->set_response_code(net::HTTP_OK); |
79 | 86 |
80 std::string raw_header = | 87 std::string raw_header = |
81 "HTTP/1.1 200 OK\n" | 88 "HTTP/1.1 200 OK\n" |
82 "Content-type: image/png\n\n"; | 89 "Content-type: image/png\n\n"; |
83 std::replace(raw_header.begin(), raw_header.end(), '\n', '\0'); | 90 std::replace(raw_header.begin(), raw_header.end(), '\n', '\0'); |
84 scoped_refptr<net::HttpResponseHeaders> headers( | 91 scoped_refptr<net::HttpResponseHeaders> headers( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // multiple URLFetchers being created. | 164 // multiple URLFetchers being created. |
158 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); | 165 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); |
159 ASSERT_NE(nullptr, test_url_fetcher); | 166 ASSERT_NE(nullptr, test_url_fetcher); |
160 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); | 167 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); |
161 | 168 |
162 test_url_fetcher = fetcher_factory_.GetFetcherByID(1); | 169 test_url_fetcher = fetcher_factory_.GetFetcherByID(1); |
163 ASSERT_NE(nullptr, test_url_fetcher); | 170 ASSERT_NE(nullptr, test_url_fetcher); |
164 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); | 171 test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher); |
165 } | 172 } |
166 | 173 |
| 174 TEST_F(ImageDataFetcherTest, FetchImageData_DisableCookies) { |
| 175 image_data_fetcher_.DisableCookies(); |
| 176 image_data_fetcher_.FetchImageData( |
| 177 GURL(kImageURL), base::Bind(&ImageDataFetcherTest::OnImageDataFetched, |
| 178 base::Unretained(this))); |
| 179 |
| 180 net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0); |
| 181 ASSERT_NE(nullptr, test_url_fetcher); |
| 182 EXPECT_TRUE(test_url_fetcher->GetLoadFlags() & net::LOAD_DO_NOT_SEND_COOKIES); |
| 183 EXPECT_TRUE(test_url_fetcher->GetLoadFlags() & net::LOAD_DO_NOT_SAVE_COOKIES); |
| 184 } |
| 185 |
| 186 void DisableCookies(); |
| 187 |
167 } // namespace image_fetcher | 188 } // namespace image_fetcher |
OLD | NEW |