Chromium Code Reviews| Index: chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_unittest.cc |
| diff --git a/chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_unittest.cc b/chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..93ebae7181a71536bbc587b779b4844eaca090df |
| --- /dev/null |
| +++ b/chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_unittest.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/message_loop.h" |
| +#include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "net/base/host_port_pair.h" |
| +#include "net/url_request/test_url_fetcher_factory.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_request_status.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SKBitmap.h" |
| + |
| +namespace { |
| +// FF0000FF is 100% alpha and max green.(A, R, B, G) |
| +uint32_t kMaxGreen = 0xFF0000FF; |
| + |
| +} // namespace |
| + |
| +namespace net { |
| + class HttpRequestHeaders; |
|
dcheng
2013/05/23 19:32:25
Style: the contents of a namespace should not be i
Pete Williamson
2013/05/24 22:18:06
Done.
|
| + class HttpResponseHeaders; |
| + class URLRequestContextGetter; |
| +} |
| + |
| +namespace notifier { |
| + |
| +class NotificationBitmapFetcherTest : public testing::Test { |
| + public: |
| + NotificationBitmapFetcherTest() |
| + : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
| + |
| + private: |
| + MessageLoopForIO message_loop_; |
| + content::TestBrowserThread ui_thread_; |
| +}; |
| + |
| +TEST_F(NotificationBitmapFetcherTest, ImageReadyTest) { |
| + GURL url("http://localhost"); |
| + |
| + scoped_refptr<NotificationBitmapFetcher> fetcher = |
| + new NotificationBitmapFetcher(url); |
| + scoped_ptr<net::URLFetcher> url_fetcher( |
| + new net::TestURLFetcher(1, url, fetcher.get())); |
| + fetcher->SetURLFetcherForTest(url_fetcher); |
| + |
| + EXPECT_EQ(false, fetcher->image_ready()); |
| + fetcher->image_ready_ = true; |
| + EXPECT_EQ(true, fetcher->image_ready()); |
| +} |
| + |
| +TEST_F(NotificationBitmapFetcherTest, HandleImageDecodedTest) { |
| + GURL url("http://localhost"); |
| + scoped_ptr<SkBitmap> image(new SkBitmap()); |
| + |
| + // Put a real bitmap into "image". 2x2 bitmap of green 16 bit pixels. |
| + image->setConfig(SkBitmap::kRGB_565_Config, 2, 2); |
| + image->allocPixels(); |
| + SkColor c = kMaxGreen; |
| + image->eraseColor(c); |
| + // Test that the image is stored and ready. Pixel [0,0] should be green. |
| + EXPECT_EQ(8, image->getSize()); |
| + EXPECT_EQ(kMaxGreen, image->getColor(0, 0)); |
| + |
| + scoped_refptr<NotificationBitmapFetcher> fetcher = |
| + new NotificationBitmapFetcher(url); |
| + |
| + scoped_ptr<net::URLFetcher> url_fetcher( |
| + new net::TestURLFetcher(1, url, fetcher.get())); |
| + fetcher->SetURLFetcherForTest(url_fetcher); |
| + EXPECT_EQ(false, fetcher->image_ready()); |
| + |
| + fetcher->HandleImageDecoded(image.Pass()); |
| + |
| + // Ensure image is marked as succeeded. |
| + EXPECT_EQ(false, fetcher->image_failed()); |
| + EXPECT_EQ(true, fetcher->image_ready()); |
| + // Test that the image is stored and ready. Pixel [0,0] should be green. |
| + EXPECT_EQ(8, fetcher->bitmap()->getSize()); |
| + EXPECT_EQ(2, fetcher->bitmap()->width()); |
| + EXPECT_EQ(2, fetcher->bitmap()->height()); |
| + EXPECT_TRUE(fetcher->bitmap()->getPixels() != NULL); |
| + EXPECT_EQ(kMaxGreen, fetcher->bitmap()->getColor(0, 0)); |
| +} |
| + |
| +TEST_F(NotificationBitmapFetcherTest, HandleImageFailedTest) { |
| + GURL url("http://localhost"); |
| + scoped_refptr<NotificationBitmapFetcher> fetcher = |
| + new NotificationBitmapFetcher(url); |
| + |
| + scoped_ptr<net::URLFetcher> url_fetcher( |
| + new net::TestURLFetcher(1, url, fetcher.get())); |
| + fetcher->SetURLFetcherForTest(url_fetcher); |
| + |
| + EXPECT_EQ(false, fetcher->image_failed_); |
| + |
| + fetcher->HandleImageFailed(); |
| + |
| + EXPECT_EQ(true, fetcher->image_failed_); |
| + EXPECT_EQ(false, fetcher->image_ready()); |
| +} |
| + |
| +} // namespace notifier |