| 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.h" | 5 #include "chrome/browser/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" |
| 11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
| 12 #include "net/base/load_flags.h" |
| 12 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 13 #include "net/url_request/test_url_fetcher_factory.h" | 14 #include "net/url_request/test_url_fetcher_factory.h" |
| 14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
| 19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
| 20 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
| 21 | 22 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Set up a delegate to wait for the callback. | 107 // Set up a delegate to wait for the callback. |
| 107 BitmapFetcherTestDelegate delegate(kAsyncCall); | 108 BitmapFetcherTestDelegate delegate(kAsyncCall); |
| 108 | 109 |
| 109 BitmapFetcher fetcher(url, &delegate); | 110 BitmapFetcher fetcher(url, &delegate); |
| 110 | 111 |
| 111 url_fetcher_factory_->SetFakeResponse( | 112 url_fetcher_factory_->SetFakeResponse( |
| 112 url, image_string, net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 113 url, image_string, net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 113 | 114 |
| 114 // We expect that the image decoder will get called and return | 115 // We expect that the image decoder will get called and return |
| 115 // an image in a callback to OnImageDecoded(). | 116 // an image in a callback to OnImageDecoded(). |
| 116 fetcher.Start(browser()->profile()->GetRequestContext()); | 117 fetcher.Start( |
| 118 browser()->profile()->GetRequestContext(), |
| 119 std::string(), |
| 120 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 121 net::LOAD_NORMAL); |
| 117 | 122 |
| 118 // Blocks until test delegate is notified via a callback. | 123 // Blocks until test delegate is notified via a callback. |
| 119 content::RunMessageLoop(); | 124 content::RunMessageLoop(); |
| 120 | 125 |
| 121 ASSERT_TRUE(delegate.success()); | 126 ASSERT_TRUE(delegate.success()); |
| 122 | 127 |
| 123 // Make sure we get back the bitmap we expect. | 128 // Make sure we get back the bitmap we expect. |
| 124 const SkBitmap& found_image = delegate.bitmap(); | 129 const SkBitmap& found_image = delegate.bitmap(); |
| 125 EXPECT_TRUE(gfx::BitmapsAreEqual(image, found_image)); | 130 EXPECT_TRUE(gfx::BitmapsAreEqual(image, found_image)); |
| 126 } | 131 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 155 // Set up a delegate to wait for the callback. | 160 // Set up a delegate to wait for the callback. |
| 156 BitmapFetcherTestDelegate delegate(kAsyncCall); | 161 BitmapFetcherTestDelegate delegate(kAsyncCall); |
| 157 | 162 |
| 158 BitmapFetcher fetcher(url, &delegate); | 163 BitmapFetcher fetcher(url, &delegate); |
| 159 | 164 |
| 160 url_fetcher_factory_->SetFakeResponse(url, | 165 url_fetcher_factory_->SetFakeResponse(url, |
| 161 std::string(), | 166 std::string(), |
| 162 net::HTTP_INTERNAL_SERVER_ERROR, | 167 net::HTTP_INTERNAL_SERVER_ERROR, |
| 163 net::URLRequestStatus::FAILED); | 168 net::URLRequestStatus::FAILED); |
| 164 | 169 |
| 165 fetcher.Start(browser()->profile()->GetRequestContext()); | 170 fetcher.Start( |
| 171 browser()->profile()->GetRequestContext(), |
| 172 std::string(), |
| 173 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 174 net::LOAD_NORMAL); |
| 166 | 175 |
| 167 // Blocks until test delegate is notified via a callback. | 176 // Blocks until test delegate is notified via a callback. |
| 168 content::RunMessageLoop(); | 177 content::RunMessageLoop(); |
| 169 | 178 |
| 170 EXPECT_FALSE(delegate.success()); | 179 EXPECT_FALSE(delegate.success()); |
| 171 } | 180 } |
| 172 | 181 |
| 173 // Flaky on Win XP Debug: crbug.com/316488 | 182 // Flaky on Win XP Debug: crbug.com/316488 |
| 174 #if defined(OS_WIN) && !defined(NDEBUG) | 183 #if defined(OS_WIN) && !defined(NDEBUG) |
| 175 #define MAYBE_HandleImageFailedTest DISABLED_HandleImageFailedTest | 184 #define MAYBE_HandleImageFailedTest DISABLED_HandleImageFailedTest |
| 176 #else | 185 #else |
| 177 #define MAYBE_HandleImageFailedTest HandleImageFailedTest | 186 #define MAYBE_HandleImageFailedTest HandleImageFailedTest |
| 178 #endif | 187 #endif |
| 179 | 188 |
| 180 IN_PROC_BROWSER_TEST_F(BitmapFetcherBrowserTest, MAYBE_HandleImageFailedTest) { | 189 IN_PROC_BROWSER_TEST_F(BitmapFetcherBrowserTest, MAYBE_HandleImageFailedTest) { |
| 181 GURL url("http://example.com/this-should-be-a-decode-failure"); | 190 GURL url("http://example.com/this-should-be-a-decode-failure"); |
| 182 BitmapFetcherTestDelegate delegate(kAsyncCall); | 191 BitmapFetcherTestDelegate delegate(kAsyncCall); |
| 183 BitmapFetcher fetcher(url, &delegate); | 192 BitmapFetcher fetcher(url, &delegate); |
| 184 url_fetcher_factory_->SetFakeResponse(url, | 193 url_fetcher_factory_->SetFakeResponse(url, |
| 185 std::string("Not a real bitmap"), | 194 std::string("Not a real bitmap"), |
| 186 net::HTTP_OK, | 195 net::HTTP_OK, |
| 187 net::URLRequestStatus::SUCCESS); | 196 net::URLRequestStatus::SUCCESS); |
| 188 | 197 |
| 189 fetcher.Start(browser()->profile()->GetRequestContext()); | 198 fetcher.Start( |
| 199 browser()->profile()->GetRequestContext(), |
| 200 std::string(), |
| 201 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 202 net::LOAD_NORMAL); |
| 190 | 203 |
| 191 // Blocks until test delegate is notified via a callback. | 204 // Blocks until test delegate is notified via a callback. |
| 192 content::RunMessageLoop(); | 205 content::RunMessageLoop(); |
| 193 | 206 |
| 194 EXPECT_FALSE(delegate.success()); | 207 EXPECT_FALSE(delegate.success()); |
| 195 } | 208 } |
| 196 | 209 |
| 197 } // namespace chrome | 210 } // namespace chrome |
| OLD | NEW |