1 // Copyright 2014 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 "ui/message_center/notification_delegate.h" 6 7 #include "base/basictypes.h" 8 #include "base/bind.h" 9 #include "base/callback.h" 10 #include "base/memory/ref_counted.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 13 namespace message_center { 14 15 class NotificationDelegateTest : public testing::Test { 16 public: 17 NotificationDelegateTest(); 18 virtual ~NotificationDelegateTest(); 19 20 void ClickCallback(); 21 22 int GetClickedCallbackAndReset(); 23 24 private: 25 int callback_count_; 26 27 DISALLOW_COPY_AND_ASSIGN(NotificationDelegateTest); 28 }; 29 NotificationDelegateTest()30NotificationDelegateTest::NotificationDelegateTest() : callback_count_(0) {} 31 ~NotificationDelegateTest()32NotificationDelegateTest::~NotificationDelegateTest() {} 33 ClickCallback()34void NotificationDelegateTest::ClickCallback() { 35 ++callback_count_; 36 } 37 GetClickedCallbackAndReset()38int NotificationDelegateTest::GetClickedCallbackAndReset() { 39 int result = callback_count_; 40 callback_count_ = 0; 41 return result; 42 } 43 TEST_F(NotificationDelegateTest,ClickedDelegate)44TEST_F(NotificationDelegateTest, ClickedDelegate) { 45 scoped_refptr<HandleNotificationClickedDelegate> delegate( 46 new HandleNotificationClickedDelegate( 47 base::Bind(&NotificationDelegateTest::ClickCallback, 48 base::Unretained(this)))); 49 50 EXPECT_TRUE(delegate->HasClickedListener()); 51 delegate->Click(); 52 EXPECT_EQ(1, GetClickedCallbackAndReset()); 53 54 // ButtonClick doesn't call the callback. 55 delegate->ButtonClick(0); 56 EXPECT_EQ(0, GetClickedCallbackAndReset()); 57 } 58 TEST_F(NotificationDelegateTest,NullClickedDelegate)59TEST_F(NotificationDelegateTest, NullClickedDelegate) { 60 scoped_refptr<HandleNotificationClickedDelegate> delegate( 61 new HandleNotificationClickedDelegate(base::Closure())); 62 63 EXPECT_FALSE(delegate->HasClickedListener()); 64 delegate->Click(); 65 EXPECT_EQ(0, GetClickedCallbackAndReset()); 66 67 delegate->ButtonClick(0); 68 EXPECT_EQ(0, GetClickedCallbackAndReset()); 69 } 70 71 } 72