Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / message_center / message_center_tray_unittest.cc
blobbd9271fa575f6a3bfea0fd167503a3ce14b28ecf
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 #include "ui/message_center/message_center_tray.h"
7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/message_center/message_center.h"
10 #include "ui/message_center/notification_types.h"
12 namespace message_center {
13 namespace {
15 class MockDelegate : public MessageCenterTrayDelegate {
16 public:
17 MockDelegate()
18 : show_popups_success_(true),
19 show_message_center_success_(true) {}
20 virtual ~MockDelegate() {}
21 virtual void OnMessageCenterTrayChanged() OVERRIDE {}
22 virtual bool ShowPopups() OVERRIDE {
23 return show_message_center_success_;
25 virtual void HidePopups() OVERRIDE {}
26 virtual void UpdatePopups() OVERRIDE {}
27 virtual bool ShowMessageCenter() OVERRIDE {
28 return show_popups_success_;
30 virtual void HideMessageCenter() OVERRIDE {}
31 virtual void UpdateMessageCenter() OVERRIDE {}
33 bool show_popups_success_;
34 bool show_message_center_success_;
36 private:
37 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
40 class MessageCenterTrayTest : public testing::Test {
41 public:
42 MessageCenterTrayTest() {}
43 virtual ~MessageCenterTrayTest() {}
45 virtual void SetUp() {
46 MessageCenter::Initialize();
47 delegate_.reset(new MockDelegate);
48 message_center_ = MessageCenter::Get();
49 message_center_tray_.reset(
50 new MessageCenterTray(delegate_.get(), message_center_));
53 virtual void TearDown() {
54 message_center_tray_.reset();
55 delegate_.reset();
56 message_center_ = NULL;
57 MessageCenter::Shutdown();
60 protected:
61 scoped_ptr<MockDelegate> delegate_;
62 scoped_ptr<MessageCenterTray> message_center_tray_;
63 MessageCenter* message_center_;
65 private:
66 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest);
69 } // namespace
71 TEST_F(MessageCenterTrayTest, BasicMessageCenter) {
72 ASSERT_FALSE(message_center_tray_->popups_visible());
73 ASSERT_FALSE(message_center_tray_->message_center_visible());
75 bool shown = message_center_tray_->ShowMessageCenterBubble();
76 EXPECT_TRUE(shown);
78 ASSERT_FALSE(message_center_tray_->popups_visible());
79 ASSERT_TRUE(message_center_tray_->message_center_visible());
81 message_center_tray_->HideMessageCenterBubble();
83 ASSERT_FALSE(message_center_tray_->popups_visible());
84 ASSERT_FALSE(message_center_tray_->message_center_visible());
86 message_center_tray_->ToggleMessageCenterBubble();
88 ASSERT_FALSE(message_center_tray_->popups_visible());
89 ASSERT_TRUE(message_center_tray_->message_center_visible());
91 message_center_tray_->ToggleMessageCenterBubble();
93 ASSERT_FALSE(message_center_tray_->popups_visible());
94 ASSERT_FALSE(message_center_tray_->message_center_visible());
97 TEST_F(MessageCenterTrayTest, BasicPopup) {
98 ASSERT_FALSE(message_center_tray_->popups_visible());
99 ASSERT_FALSE(message_center_tray_->message_center_visible());
101 message_center_tray_->ShowPopupBubble();
103 ASSERT_FALSE(message_center_tray_->popups_visible());
104 ASSERT_FALSE(message_center_tray_->message_center_visible());
106 message_center_->AddNotification(
107 message_center::NOTIFICATION_TYPE_SIMPLE,
108 "BasicPopup",
109 ASCIIToUTF16("Test Web Notification"),
110 ASCIIToUTF16("Notification message body."),
111 ASCIIToUTF16("www.test.org"),
112 "" /* extension id */,
113 NULL /* optional_fields */);
115 ASSERT_TRUE(message_center_tray_->popups_visible());
116 ASSERT_FALSE(message_center_tray_->message_center_visible());
118 message_center_tray_->HidePopupBubble();
120 ASSERT_FALSE(message_center_tray_->popups_visible());
121 ASSERT_FALSE(message_center_tray_->message_center_visible());
124 TEST_F(MessageCenterTrayTest, MessageCenterClosesPopups) {
125 ASSERT_FALSE(message_center_tray_->popups_visible());
126 ASSERT_FALSE(message_center_tray_->message_center_visible());
128 message_center_->AddNotification(
129 message_center::NOTIFICATION_TYPE_SIMPLE,
130 "MessageCenterClosesPopups",
131 ASCIIToUTF16("Test Web Notification"),
132 ASCIIToUTF16("Notification message body."),
133 ASCIIToUTF16("www.test.org"),
134 "" /* extension id */,
135 NULL /* optional_fields */);
137 ASSERT_TRUE(message_center_tray_->popups_visible());
138 ASSERT_FALSE(message_center_tray_->message_center_visible());
140 bool shown = message_center_tray_->ShowMessageCenterBubble();
141 EXPECT_TRUE(shown);
143 ASSERT_FALSE(message_center_tray_->popups_visible());
144 ASSERT_TRUE(message_center_tray_->message_center_visible());
146 message_center_->AddNotification(
147 message_center::NOTIFICATION_TYPE_SIMPLE,
148 "MessageCenterClosesPopups2",
149 ASCIIToUTF16("Test Web Notification"),
150 ASCIIToUTF16("Notification message body."),
151 ASCIIToUTF16("www.test.org"),
152 "" /* extension id */,
153 NULL /* optional_fields */);
155 message_center_tray_->ShowPopupBubble();
157 ASSERT_FALSE(message_center_tray_->popups_visible());
158 ASSERT_TRUE(message_center_tray_->message_center_visible());
160 message_center_tray_->HideMessageCenterBubble();
162 ASSERT_FALSE(message_center_tray_->popups_visible());
163 ASSERT_FALSE(message_center_tray_->message_center_visible());
166 TEST_F(MessageCenterTrayTest, ShowBubbleFails) {
167 // Now the delegate will signal that it was unable to show a bubble.
168 delegate_->show_popups_success_ = false;
169 delegate_->show_message_center_success_ = false;
171 ASSERT_FALSE(message_center_tray_->popups_visible());
172 ASSERT_FALSE(message_center_tray_->message_center_visible());
174 message_center_->AddNotification(
175 message_center::NOTIFICATION_TYPE_SIMPLE,
176 "ShowBubbleFails",
177 ASCIIToUTF16("Test Web Notification"),
178 ASCIIToUTF16("Notification message body."),
179 ASCIIToUTF16("www.test.org"),
180 "" /* extension id */,
181 NULL /* optional_fields */);
183 message_center_tray_->ShowPopupBubble();
185 ASSERT_FALSE(message_center_tray_->popups_visible());
186 ASSERT_FALSE(message_center_tray_->message_center_visible());
188 bool shown = message_center_tray_->ShowMessageCenterBubble();
189 EXPECT_FALSE(shown);
191 ASSERT_FALSE(message_center_tray_->popups_visible());
192 ASSERT_FALSE(message_center_tray_->message_center_visible());
194 message_center_tray_->HideMessageCenterBubble();
196 ASSERT_FALSE(message_center_tray_->popups_visible());
197 ASSERT_FALSE(message_center_tray_->message_center_visible());
199 message_center_tray_->ToggleMessageCenterBubble();
201 ASSERT_FALSE(message_center_tray_->popups_visible());
202 ASSERT_FALSE(message_center_tray_->message_center_visible());
204 message_center_tray_->HidePopupBubble();
206 ASSERT_FALSE(message_center_tray_->popups_visible());
207 ASSERT_FALSE(message_center_tray_->message_center_visible());
210 } // namespace message_center