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.
5 #include "ui/message_center/notification_delegate.h"
7 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace message_center
{
15 class NotificationDelegateTest
: public testing::Test
{
17 NotificationDelegateTest();
18 ~NotificationDelegateTest() override
;
22 int GetClickedCallbackAndReset();
27 DISALLOW_COPY_AND_ASSIGN(NotificationDelegateTest
);
30 NotificationDelegateTest::NotificationDelegateTest() : callback_count_(0) {}
32 NotificationDelegateTest::~NotificationDelegateTest() {}
34 void NotificationDelegateTest::ClickCallback() {
38 int NotificationDelegateTest::GetClickedCallbackAndReset() {
39 int result
= callback_count_
;
44 TEST_F(NotificationDelegateTest
, ClickedDelegate
) {
45 scoped_refptr
<HandleNotificationClickedDelegate
> delegate(
46 new HandleNotificationClickedDelegate(
47 base::Bind(&NotificationDelegateTest::ClickCallback
,
48 base::Unretained(this))));
50 EXPECT_TRUE(delegate
->HasClickedListener());
52 EXPECT_EQ(1, GetClickedCallbackAndReset());
54 // ButtonClick doesn't call the callback.
55 delegate
->ButtonClick(0);
56 EXPECT_EQ(0, GetClickedCallbackAndReset());
59 TEST_F(NotificationDelegateTest
, NullClickedDelegate
) {
60 scoped_refptr
<HandleNotificationClickedDelegate
> delegate(
61 new HandleNotificationClickedDelegate(base::Closure()));
63 EXPECT_FALSE(delegate
->HasClickedListener());
65 EXPECT_EQ(0, GetClickedCallbackAndReset());
67 delegate
->ButtonClick(0);
68 EXPECT_EQ(0, GetClickedCallbackAndReset());