Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / notifications / message_center_tray_bridge_unittest.mm
blob567e60f9399f3f700ebf9650bcf1cd1085a1d429
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 {
17  public:
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_));
25   }
27   virtual void TearDown() OVERRIDE {
28     bridge_.reset();
29     message_center::MessageCenter::Shutdown();
30     ui::CocoaTest::TearDown();
31   }
33   MCStatusItemView* status_item() { return bridge_->status_item_view_.get(); }
35  protected:
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;
45   data.priority = -1;
46   scoped_ptr<message_center::Notification> notification(
47       new message_center::Notification(
48           message_center::NOTIFICATION_TYPE_SIMPLE,
49           "1",
50           base::ASCIIToUTF16("First notification"),
51           base::ASCIIToUTF16("This is a simple test."),
52           gfx::Image(),
53           base::string16(),
54           message_center::NotifierId(),
55           data,
56           NULL));
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());