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.
5 #import "chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #import "ui/base/test/ui_cocoa_test_helper.h"
12 #import "ui/message_center/cocoa/status_item_view.h"
13 #include "ui/message_center/message_center.h"
14 #include "ui/message_center/notification.h"
16 class MessageCenterTrayBridgeTest : public ui::CocoaTest {
18 virtual void SetUp() OVERRIDE {
19 ui::CocoaTest::SetUp();
21 message_center::MessageCenter::Initialize();
22 center_ = message_center::MessageCenter::Get();
24 bridge_.reset(new MessageCenterTrayBridge(center_));
27 virtual void TearDown() OVERRIDE {
29 message_center::MessageCenter::Shutdown();
30 ui::CocoaTest::TearDown();
33 MCStatusItemView* status_item() { return bridge_->status_item_view_.get(); }
36 base::MessageLoop message_loop_;
37 message_center::MessageCenter* center_; // Weak, global.
38 scoped_ptr<MessageCenterTrayBridge> bridge_;
41 TEST_F(MessageCenterTrayBridgeTest, StatusItemOnlyAfterFirstNotification) {
42 EXPECT_FALSE(status_item());
44 message_center::RichNotificationData data;
46 scoped_ptr<message_center::Notification> notification(
47 new message_center::Notification(
48 message_center::NOTIFICATION_TYPE_SIMPLE,
50 base::ASCIIToUTF16("First notification"),
51 base::ASCIIToUTF16("This is a simple test."),
54 message_center::NotifierId(),
57 center_->AddNotification(notification.Pass());
59 base::RunLoop().RunUntilIdle();
61 EXPECT_TRUE(status_item());
62 EXPECT_EQ(1u, [status_item() unreadCount]);
64 center_->RemoveNotification("1", /*by_user=*/true);
66 base::RunLoop().RunUntilIdle();
68 EXPECT_TRUE(status_item());