Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: chrome/browser/ui/cocoa/notifications/message_center_tray_bridge_unittest.mm

Issue 1334363002: [Eraser] First pass at removing the notification center panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: peter comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #import "chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h"
6
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/scoped_testing_local_state.h"
14 #include "chrome/test/base/testing_browser_process.h"
15 #import "ui/gfx/test/ui_cocoa_test_helper.h"
16 #import "ui/message_center/cocoa/status_item_view.h"
17 #include "ui/message_center/message_center.h"
18 #include "ui/message_center/notification.h"
19 #include "ui/message_center/notifier_settings.h"
20
21 class MessageCenterTrayBridgeTest : public ui::CocoaTest {
22 public:
23 void SetUp() override {
24 ui::CocoaTest::SetUp();
25
26 local_state_.reset(
27 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal()));
28 message_center::MessageCenter::Initialize();
29 center_ = message_center::MessageCenter::Get();
30
31 bridge_.reset(new MessageCenterTrayBridge(center_));
32 }
33
34 void TearDown() override {
35 bridge_.reset();
36 message_center::MessageCenter::Shutdown();
37 local_state_.reset();
38 initializer_.reset();
39 ui::CocoaTest::TearDown();
40 }
41
42 MCStatusItemView* status_item() { return bridge_->status_item_view_.get(); }
43
44 protected:
45 scoped_ptr<message_center::Notification> GetNotification() {
46 message_center::RichNotificationData data;
47 data.priority = -1;
48 return make_scoped_ptr(new message_center::Notification(
49 message_center::NOTIFICATION_TYPE_SIMPLE, "1",
50 base::ASCIIToUTF16("First notification"),
51 base::ASCIIToUTF16("This is a simple test."), gfx::Image(),
52 base::string16(), GURL(), message_center::NotifierId(), data, NULL));
53 }
54
55 TestingPrefServiceSimple* local_state() { return local_state_->Get(); }
56
57 scoped_ptr<TestingBrowserProcessInitializer> initializer_;
58 scoped_ptr<ScopedTestingLocalState> local_state_;
59
60 base::MessageLoop message_loop_;
61 message_center::MessageCenter* center_; // Weak, global.
62 scoped_ptr<MessageCenterTrayBridge> bridge_;
63 };
64
65 class MessageCenterTrayBridgeTestPrefNever
66 : public MessageCenterTrayBridgeTest {
67 public:
68 void SetUp() override {
69 MessageCenterTrayBridgeTest::SetUp();
70 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, false);
71 }
72 };
73
74 TEST_F(MessageCenterTrayBridgeTest, StatusItemOnlyAfterFirstNotification) {
75 EXPECT_FALSE(status_item());
76
77 bridge_->OnMessageCenterTrayChanged();
78 base::RunLoop().RunUntilIdle();
79 EXPECT_FALSE(status_item());
80
81 center_->AddNotification(GetNotification());
82
83 base::RunLoop().RunUntilIdle();
84
85 EXPECT_TRUE(status_item());
86 EXPECT_EQ(1u, [status_item() unreadCount]);
87
88 center_->RemoveNotification("1", /*by_user=*/true);
89
90 base::RunLoop().RunUntilIdle();
91
92 EXPECT_TRUE(status_item());
93 }
94
95 TEST_F(MessageCenterTrayBridgeTest, StatusItemAppearsWithPrefChange) {
96 EXPECT_FALSE(status_item());
97 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, false);
98 EXPECT_FALSE(status_item());
99 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, true);
100 EXPECT_TRUE(status_item());
101 }
102
103 TEST_F(MessageCenterTrayBridgeTest, StatusItemDisappearsWithPrefChange) {
104 EXPECT_FALSE(status_item());
105 center_->AddNotification(GetNotification());
106
107 base::RunLoop().RunUntilIdle();
108
109 EXPECT_TRUE(status_item());
110 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, false);
111 EXPECT_FALSE(status_item());
112 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, true);
113 EXPECT_TRUE(status_item());
114 }
115
116 TEST_F(MessageCenterTrayBridgeTestPrefNever, StatusItemNever) {
117 EXPECT_FALSE(status_item());
118
119 center_->AddNotification(GetNotification());
120
121 base::RunLoop().RunUntilIdle();
122
123 EXPECT_FALSE(status_item());
124
125 center_->RemoveNotification("1", /*by_user=*/true);
126
127 base::RunLoop().RunUntilIdle();
128
129 EXPECT_FALSE(status_item());
130 }
131
132 TEST_F(MessageCenterTrayBridgeTestPrefNever, StatusItemBackWithPref) {
133 EXPECT_FALSE(status_item());
134
135 center_->AddNotification(GetNotification());
136
137 base::RunLoop().RunUntilIdle();
138
139 EXPECT_FALSE(status_item());
140
141 center_->RemoveNotification("1", /*by_user=*/true);
142
143 base::RunLoop().RunUntilIdle();
144
145 EXPECT_FALSE(status_item());
146
147 local_state()->SetBoolean(prefs::kMessageCenterShowIcon, true);
148
149 EXPECT_TRUE(status_item());
150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698