Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2197)

Unified Diff: chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher_unittest.cc

Issue 15295018: Continue bitmap fetching for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced Notification Bitmap Fetching - Address DCheng CR feedback Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698