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

Side by Side Diff: chrome/browser/notifications/message_center_notifications_unittest.cc

Issue 2776933006: CrOS: Do not allow notifications to be added during shutdown. (Closed)
Patch Set: Trybots. Created 3 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 protected: 44 protected:
45 void SetUp() override { 45 void SetUp() override {
46 BrowserWithTestWindowTest::SetUp(); 46 BrowserWithTestWindowTest::SetUp();
47 #if !defined(OS_CHROMEOS) 47 #if !defined(OS_CHROMEOS)
48 // BrowserWithTestWindowTest owns an AshTestHelper on OS_CHROMEOS, which 48 // BrowserWithTestWindowTest owns an AshTestHelper on OS_CHROMEOS, which
49 // in turn initializes the message center. On other platforms, we need to 49 // in turn initializes the message center. On other platforms, we need to
50 // initialize it here. 50 // initialize it here.
51 MessageCenter::Initialize(); 51 MessageCenter::Initialize();
52 #endif 52 #endif
53 53
54
55 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal(); 54 TestingBrowserProcess* browser_process = TestingBrowserProcess::GetGlobal();
56 profile_manager_.reset(new TestingProfileManager(browser_process)); 55 profile_manager_.reset(new TestingProfileManager(browser_process));
57 ASSERT_TRUE(profile_manager_->SetUp()); 56 ASSERT_TRUE(profile_manager_->SetUp());
58 57
59 message_center_ = MessageCenter::Get(); 58 message_center_ = MessageCenter::Get();
60 delegate_ = new FakeMessageCenterTrayDelegate(message_center_); 59 delegate_ = new FakeMessageCenterTrayDelegate(message_center_);
61 notification_manager()->SetMessageCenterTrayDelegateForTest(delegate_); 60 notification_manager()->SetMessageCenterTrayDelegateForTest(delegate_);
62 } 61 }
63 62
64 void TearDown() override { 63 void TearDown() override {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 std::unique_ptr<TestingProfileManager> profile_manager_; 96 std::unique_ptr<TestingProfileManager> profile_manager_;
98 MessageCenter* message_center_; 97 MessageCenter* message_center_;
99 FakeMessageCenterTrayDelegate* delegate_; 98 FakeMessageCenterTrayDelegate* delegate_;
100 }; 99 };
101 100
102 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) { 101 TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) {
103 TestingProfile profile; 102 TestingProfile profile;
104 notification_manager()->Add(GetANotification("test"), &profile); 103 notification_manager()->Add(GetANotification("test"), &profile);
105 } 104 }
106 105
106 TEST_F(MessageCenterNotificationManagerTest, AddNotificationOnShutdown) {
107 TestingProfile profile;
108 EXPECT_TRUE(message_center()->NotificationCount() == 0);
109 notification_manager()->Add(GetANotification("test"), &profile);
110 EXPECT_TRUE(message_center()->NotificationCount() == 1);
111
112 // Verify the number of notifications does not increase when trying to add a
113 // notifcation on shutdown.
114 notification_manager()->StartShutdown();
115 EXPECT_TRUE(message_center()->NotificationCount() == 0);
116 notification_manager()->Add(GetANotification("test2"), &profile);
117 EXPECT_TRUE(message_center()->NotificationCount() == 0);
118 }
119
107 TEST_F(MessageCenterNotificationManagerTest, UpdateNotification) { 120 TEST_F(MessageCenterNotificationManagerTest, UpdateNotification) {
108 TestingProfile profile; 121 TestingProfile profile;
109 EXPECT_TRUE(message_center()->NotificationCount() == 0); 122 EXPECT_TRUE(message_center()->NotificationCount() == 0);
110 notification_manager()->Add(GetANotification("test"), &profile); 123 notification_manager()->Add(GetANotification("test"), &profile);
111 EXPECT_TRUE(message_center()->NotificationCount() == 1); 124 EXPECT_TRUE(message_center()->NotificationCount() == 1);
112 ASSERT_TRUE( 125 ASSERT_TRUE(
113 notification_manager()->Update(GetANotification("test"), &profile)); 126 notification_manager()->Update(GetANotification("test"), &profile));
114 EXPECT_TRUE(message_center()->NotificationCount() == 1); 127 EXPECT_TRUE(message_center()->NotificationCount() == 1);
115 } 128 }
116 129
(...skipping 14 matching lines...) Expand all
131 EXPECT_EQ(0u, message_center()->NotificationCount()); 144 EXPECT_EQ(0u, message_center()->NotificationCount());
132 notification_manager()->Add(GetANotification("test"), &profile); 145 notification_manager()->Add(GetANotification("test"), &profile);
133 EXPECT_EQ(1u, message_center()->NotificationCount()); 146 EXPECT_EQ(1u, message_center()->NotificationCount());
134 notification_manager()->Update(GetANotification("test"), &profile); 147 notification_manager()->Update(GetANotification("test"), &profile);
135 EXPECT_EQ(1u, message_center()->NotificationCount()); 148 EXPECT_EQ(1u, message_center()->NotificationCount());
136 chrome::MultiUserWindowManager::DeleteInstance(); 149 chrome::MultiUserWindowManager::DeleteInstance();
137 } 150 }
138 #endif 151 #endif
139 152
140 } // namespace message_center 153 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698