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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/message_loop.h"
6 #include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher .h"
7 #include "content/public/browser/browser_thread.h"
8 #include "content/public/test/test_browser_thread.h"
9 #include "net/base/host_port_pair.h"
10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_request_status.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SKBitmap.h"
15
16 namespace {
17 // FF0000FF is 100% alpha and max green.(A, R, B, G)
18 uint32_t kMaxGreen = 0xFF0000FF;
19
20 } // namespace
21
22 namespace net {
23 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.
24 class HttpResponseHeaders;
25 class URLRequestContextGetter;
26 }
27
28 namespace notifier {
29
30 class NotificationBitmapFetcherTest : public testing::Test {
31 public:
32 NotificationBitmapFetcherTest()
33 : ui_thread_(content::BrowserThread::UI, &message_loop_) {}
34
35 private:
36 MessageLoopForIO message_loop_;
37 content::TestBrowserThread ui_thread_;
38 };
39
40 TEST_F(NotificationBitmapFetcherTest, ImageReadyTest) {
41 GURL url("http://localhost");
42
43 scoped_refptr<NotificationBitmapFetcher> fetcher =
44 new NotificationBitmapFetcher(url);
45 scoped_ptr<net::URLFetcher> url_fetcher(
46 new net::TestURLFetcher(1, url, fetcher.get()));
47 fetcher->SetURLFetcherForTest(url_fetcher);
48
49 EXPECT_EQ(false, fetcher->image_ready());
50 fetcher->image_ready_ = true;
51 EXPECT_EQ(true, fetcher->image_ready());
52 }
53
54 TEST_F(NotificationBitmapFetcherTest, HandleImageDecodedTest) {
55 GURL url("http://localhost");
56 scoped_ptr<SkBitmap> image(new SkBitmap());
57
58 // Put a real bitmap into "image". 2x2 bitmap of green 16 bit pixels.
59 image->setConfig(SkBitmap::kRGB_565_Config, 2, 2);
60 image->allocPixels();
61 SkColor c = kMaxGreen;
62 image->eraseColor(c);
63 // Test that the image is stored and ready. Pixel [0,0] should be green.
64 EXPECT_EQ(8, image->getSize());
65 EXPECT_EQ(kMaxGreen, image->getColor(0, 0));
66
67 scoped_refptr<NotificationBitmapFetcher> fetcher =
68 new NotificationBitmapFetcher(url);
69
70 scoped_ptr<net::URLFetcher> url_fetcher(
71 new net::TestURLFetcher(1, url, fetcher.get()));
72 fetcher->SetURLFetcherForTest(url_fetcher);
73 EXPECT_EQ(false, fetcher->image_ready());
74
75 fetcher->HandleImageDecoded(image.Pass());
76
77 // Ensure image is marked as succeeded.
78 EXPECT_EQ(false, fetcher->image_failed());
79 EXPECT_EQ(true, fetcher->image_ready());
80 // Test that the image is stored and ready. Pixel [0,0] should be green.
81 EXPECT_EQ(8, fetcher->bitmap()->getSize());
82 EXPECT_EQ(2, fetcher->bitmap()->width());
83 EXPECT_EQ(2, fetcher->bitmap()->height());
84 EXPECT_TRUE(fetcher->bitmap()->getPixels() != NULL);
85 EXPECT_EQ(kMaxGreen, fetcher->bitmap()->getColor(0, 0));
86 }
87
88 TEST_F(NotificationBitmapFetcherTest, HandleImageFailedTest) {
89 GURL url("http://localhost");
90 scoped_refptr<NotificationBitmapFetcher> fetcher =
91 new NotificationBitmapFetcher(url);
92
93 scoped_ptr<net::URLFetcher> url_fetcher(
94 new net::TestURLFetcher(1, url, fetcher.get()));
95 fetcher->SetURLFetcherForTest(url_fetcher);
96
97 EXPECT_EQ(false, fetcher->image_failed_);
98
99 fetcher->HandleImageFailed();
100
101 EXPECT_EQ(true, fetcher->image_failed_);
102 EXPECT_EQ(false, fetcher->image_ready());
103 }
104
105 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698