| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/notifications/sync_notifier/notification_bitmap_fetcher
.h" | 5 #include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher
.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
| 12 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
| 13 #include "net/url_request/test_url_fetcher_factory.h" | 13 #include "net/url_request/test_url_fetcher_factory.h" |
| 14 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_status.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 const bool kAsyncCall = true; | 23 const bool kAsyncCall = true; |
| 23 const bool kSyncCall = false; | 24 const bool kSyncCall = false; |
| 24 } // namespace | 25 } // namespace |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed)); | 105 ASSERT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(image, true, &compressed)); |
| 105 | 106 |
| 106 // Copy the bits into the string, and put them into the FakeURLFetcher. | 107 // Copy the bits into the string, and put them into the FakeURLFetcher. |
| 107 std::string image_string(compressed.begin(), compressed.end()); | 108 std::string image_string(compressed.begin(), compressed.end()); |
| 108 | 109 |
| 109 // Set up a delegate to wait for the callback. | 110 // Set up a delegate to wait for the callback. |
| 110 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 111 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); |
| 111 | 112 |
| 112 NotificationBitmapFetcher fetcher(url, &delegate); | 113 NotificationBitmapFetcher fetcher(url, &delegate); |
| 113 | 114 |
| 114 url_fetcher_factory_->SetFakeResponse(url, image_string, net::HTTP_OK); | 115 url_fetcher_factory_->SetFakeResponse(url, image_string, net::HTTP_OK, |
| 116 net::URLRequestStatus::SUCCESS); |
| 115 | 117 |
| 116 // We expect that the image decoder will get called and return | 118 // We expect that the image decoder will get called and return |
| 117 // an image in a callback to OnImageDecoded(). | 119 // an image in a callback to OnImageDecoded(). |
| 118 fetcher.Start(browser()->profile()); | 120 fetcher.Start(browser()->profile()); |
| 119 | 121 |
| 120 // Blocks until test delegate is notified via a callback. | 122 // Blocks until test delegate is notified via a callback. |
| 121 content::RunMessageLoop(); | 123 content::RunMessageLoop(); |
| 122 | 124 |
| 123 ASSERT_TRUE(delegate.success()); | 125 ASSERT_TRUE(delegate.success()); |
| 124 | 126 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 158 |
| 157 // We intentionally put no data into the bitmap to simulate a failure. | 159 // We intentionally put no data into the bitmap to simulate a failure. |
| 158 | 160 |
| 159 // Set up a delegate to wait for the callback. | 161 // Set up a delegate to wait for the callback. |
| 160 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 162 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); |
| 161 | 163 |
| 162 NotificationBitmapFetcher fetcher(url, &delegate); | 164 NotificationBitmapFetcher fetcher(url, &delegate); |
| 163 | 165 |
| 164 url_fetcher_factory_->SetFakeResponse(url, | 166 url_fetcher_factory_->SetFakeResponse(url, |
| 165 std::string(), | 167 std::string(), |
| 166 net::HTTP_INTERNAL_SERVER_ERROR); | 168 net::HTTP_INTERNAL_SERVER_ERROR, |
| 169 net::URLRequestStatus::FAILED); |
| 167 | 170 |
| 168 fetcher.Start(browser()->profile()); | 171 fetcher.Start(browser()->profile()); |
| 169 | 172 |
| 170 // Blocks until test delegate is notified via a callback. | 173 // Blocks until test delegate is notified via a callback. |
| 171 content::RunMessageLoop(); | 174 content::RunMessageLoop(); |
| 172 | 175 |
| 173 EXPECT_FALSE(delegate.success()); | 176 EXPECT_FALSE(delegate.success()); |
| 174 } | 177 } |
| 175 | 178 |
| 176 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest, | 179 IN_PROC_BROWSER_TEST_F(NotificationBitmapFetcherBrowserTest, |
| 177 HandleImageFailedTest) { | 180 HandleImageFailedTest) { |
| 178 GURL url("http://example.com/this-should-be-a-decode-failure"); | 181 GURL url("http://example.com/this-should-be-a-decode-failure"); |
| 179 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); | 182 NotificationBitmapFetcherTestDelegate delegate(kAsyncCall); |
| 180 NotificationBitmapFetcher fetcher(url, &delegate); | 183 NotificationBitmapFetcher fetcher(url, &delegate); |
| 181 url_fetcher_factory_->SetFakeResponse( | 184 url_fetcher_factory_->SetFakeResponse( |
| 182 url, std::string("Not a real bitmap"), net::HTTP_OK); | 185 url, std::string("Not a real bitmap"), |
| 186 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 183 | 187 |
| 184 fetcher.Start(browser()->profile()); | 188 fetcher.Start(browser()->profile()); |
| 185 | 189 |
| 186 // Blocks until test delegate is notified via a callback. | 190 // Blocks until test delegate is notified via a callback. |
| 187 content::RunMessageLoop(); | 191 content::RunMessageLoop(); |
| 188 | 192 |
| 189 EXPECT_FALSE(delegate.success()); | 193 EXPECT_FALSE(delegate.success()); |
| 190 } | 194 } |
| 191 | 195 |
| 192 } // namespace notifier | 196 } // namespace notifier |
| OLD | NEW |