OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 5 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Set up a delegate to wait for the callback. | 106 // Set up a delegate to wait for the callback. |
107 BitmapFetcherTestDelegate delegate(kAsyncCall); | 107 BitmapFetcherTestDelegate delegate(kAsyncCall); |
108 | 108 |
109 BitmapFetcher fetcher(url, &delegate); | 109 BitmapFetcher fetcher(url, &delegate); |
110 | 110 |
111 url_fetcher_factory_->SetFakeResponse( | 111 url_fetcher_factory_->SetFakeResponse( |
112 url, image_string, net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 112 url, image_string, net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
113 | 113 |
114 // We expect that the image decoder will get called and return | 114 // We expect that the image decoder will get called and return |
115 // an image in a callback to OnImageDecoded(). | 115 // an image in a callback to OnImageDecoded(). |
116 fetcher.Start( | 116 fetcher.Init( |
117 browser()->profile()->GetRequestContext(), | 117 browser()->profile()->GetRequestContext(), |
118 std::string(), | 118 std::string(), |
119 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 119 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
120 net::LOAD_NORMAL); | 120 net::LOAD_NORMAL); |
| 121 fetcher.Start(); |
121 | 122 |
122 // Blocks until test delegate is notified via a callback. | 123 // Blocks until test delegate is notified via a callback. |
123 delegate.Wait(); | 124 delegate.Wait(); |
124 | 125 |
125 ASSERT_TRUE(delegate.success()); | 126 ASSERT_TRUE(delegate.success()); |
126 | 127 |
127 // Make sure we get back the bitmap we expect. | 128 // Make sure we get back the bitmap we expect. |
128 const SkBitmap& found_image = delegate.bitmap(); | 129 const SkBitmap& found_image = delegate.bitmap(); |
129 EXPECT_TRUE(gfx::BitmapsAreEqual(image, found_image)); | 130 EXPECT_TRUE(gfx::BitmapsAreEqual(image, found_image)); |
130 } | 131 } |
(...skipping 27 matching lines...) Expand all Loading... |
158 // Set up a delegate to wait for the callback. | 159 // Set up a delegate to wait for the callback. |
159 BitmapFetcherTestDelegate delegate(kAsyncCall); | 160 BitmapFetcherTestDelegate delegate(kAsyncCall); |
160 | 161 |
161 BitmapFetcher fetcher(url, &delegate); | 162 BitmapFetcher fetcher(url, &delegate); |
162 | 163 |
163 url_fetcher_factory_->SetFakeResponse(url, | 164 url_fetcher_factory_->SetFakeResponse(url, |
164 std::string(), | 165 std::string(), |
165 net::HTTP_INTERNAL_SERVER_ERROR, | 166 net::HTTP_INTERNAL_SERVER_ERROR, |
166 net::URLRequestStatus::FAILED); | 167 net::URLRequestStatus::FAILED); |
167 | 168 |
168 fetcher.Start( | 169 fetcher.Init( |
169 browser()->profile()->GetRequestContext(), | 170 browser()->profile()->GetRequestContext(), |
170 std::string(), | 171 std::string(), |
171 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 172 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
172 net::LOAD_NORMAL); | 173 net::LOAD_NORMAL); |
| 174 fetcher.Start(); |
173 | 175 |
174 // Blocks until test delegate is notified via a callback. | 176 // Blocks until test delegate is notified via a callback. |
175 delegate.Wait(); | 177 delegate.Wait(); |
176 | 178 |
177 EXPECT_FALSE(delegate.success()); | 179 EXPECT_FALSE(delegate.success()); |
178 } | 180 } |
179 | 181 |
180 IN_PROC_BROWSER_TEST_F(BitmapFetcherBrowserTest, HandleImageFailedTest) { | 182 IN_PROC_BROWSER_TEST_F(BitmapFetcherBrowserTest, HandleImageFailedTest) { |
181 GURL url("http://example.com/this-should-be-a-decode-failure"); | 183 GURL url("http://example.com/this-should-be-a-decode-failure"); |
182 BitmapFetcherTestDelegate delegate(kAsyncCall); | 184 BitmapFetcherTestDelegate delegate(kAsyncCall); |
183 BitmapFetcher fetcher(url, &delegate); | 185 BitmapFetcher fetcher(url, &delegate); |
184 url_fetcher_factory_->SetFakeResponse(url, | 186 url_fetcher_factory_->SetFakeResponse(url, |
185 std::string("Not a real bitmap"), | 187 std::string("Not a real bitmap"), |
186 net::HTTP_OK, | 188 net::HTTP_OK, |
187 net::URLRequestStatus::SUCCESS); | 189 net::URLRequestStatus::SUCCESS); |
188 | 190 |
189 fetcher.Start( | 191 fetcher.Init( |
190 browser()->profile()->GetRequestContext(), | 192 browser()->profile()->GetRequestContext(), |
191 std::string(), | 193 std::string(), |
192 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | 194 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
193 net::LOAD_NORMAL); | 195 net::LOAD_NORMAL); |
| 196 fetcher.Start(); |
194 | 197 |
195 // Blocks until test delegate is notified via a callback. | 198 // Blocks until test delegate is notified via a callback. |
196 delegate.Wait(); | 199 delegate.Wait(); |
197 | 200 |
198 EXPECT_FALSE(delegate.success()); | 201 EXPECT_FALSE(delegate.success()); |
199 } | 202 } |
200 | 203 |
201 } // namespace chrome | 204 } // namespace chrome |
OLD | NEW |