This source file includes following definitions.
- OnFetchComplete
- TEST_F
- TEST_F
- TEST_F
#include <string>
#include "chrome/browser/notifications/sync_notifier/image_holder.h"
#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TestDelegate : public notifier::ImageHolderDelegate {
public:
TestDelegate() : on_fetch_complete_called_(false) {}
virtual void OnFetchComplete() OVERRIDE {
on_fetch_complete_called_ = true;
}
bool on_fetch_complete_called_;
};
}
namespace notifier {
typedef testing::Test ImageHolderTest;
TEST_F(ImageHolderTest, CreateBitmapFetcherTest) {
TestDelegate delegate;
ImageHolder image_holder(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate);
EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url());
EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url());
EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size());
image_holder.CreateBitmapFetcher(GURL(kIconUrl2));
EXPECT_EQ(GURL(kIconUrl1), image_holder.fetchers_[0]->url());
EXPECT_EQ(GURL(kIconUrl2), image_holder.fetchers_[1]->url());
EXPECT_EQ(static_cast<unsigned int>(2), image_holder.fetchers_.size());
}
TEST_F(ImageHolderTest, OnFetchCompleteTest) {
TestDelegate delegate;
ImageHolder image_holder(GURL(kIconUrl1), GURL(), NULL, &delegate);
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
bitmap.allocPixels();
bitmap.eraseColor(SK_ColorGREEN);
image_holder.OnFetchComplete(GURL(kIconUrl1), &bitmap);
EXPECT_FALSE(image_holder.low_dpi_image().IsEmpty());
EXPECT_TRUE(delegate.on_fetch_complete_called_);
}
TEST_F(ImageHolderTest, IsFetchingDoneTest) {
TestDelegate delegate;
ImageHolder image_holder1(GURL(kIconUrl1), GURL(kIconUrl2), NULL, &delegate);
ImageHolder image_holder2(GURL(kIconUrl1), GURL(), NULL, &delegate);
ImageHolder image_holder3(GURL(), GURL(kIconUrl2), NULL, &delegate);
ImageHolder image_holder4(GURL(), GURL(), NULL, &delegate);
EXPECT_FALSE(image_holder1.IsFetchingDone());
EXPECT_FALSE(image_holder2.IsFetchingDone());
EXPECT_FALSE(image_holder3.IsFetchingDone());
EXPECT_TRUE(image_holder4.IsFetchingDone());
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
bitmap.allocPixels();
bitmap.eraseColor(SK_ColorGREEN);
image_holder1.OnFetchComplete(GURL(kIconUrl1), &bitmap);
image_holder2.OnFetchComplete(GURL(kIconUrl1), &bitmap);
image_holder3.OnFetchComplete(GURL(kIconUrl1), &bitmap);
image_holder4.OnFetchComplete(GURL(kIconUrl1), &bitmap);
EXPECT_FALSE(image_holder1.IsFetchingDone());
EXPECT_TRUE(image_holder2.IsFetchingDone());
EXPECT_FALSE(image_holder3.IsFetchingDone());
EXPECT_TRUE(image_holder4.IsFetchingDone());
image_holder1.OnFetchComplete(GURL(kIconUrl2), &bitmap);
image_holder2.OnFetchComplete(GURL(kIconUrl2), &bitmap);
image_holder3.OnFetchComplete(GURL(kIconUrl2), &bitmap);
image_holder4.OnFetchComplete(GURL(kIconUrl2), &bitmap);
EXPECT_TRUE(image_holder1.IsFetchingDone());
EXPECT_TRUE(image_holder2.IsFetchingDone());
EXPECT_TRUE(image_holder3.IsFetchingDone());
EXPECT_TRUE(image_holder4.IsFetchingDone());
}
}