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

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

Issue 1814923002: Nuke NotificationUIManager from PlatformNotificationServiceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile_manager_load
Patch Set: Review comments + unique_ptr rename Created 4 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/notifications/message_center_display_service.h"
16 #include "chrome/browser/notifications/notification_delegate.h" 17 #include "chrome/browser/notifications/notification_delegate.h"
17 #include "chrome/browser/notifications/notification_test_util.h" 18 #include "chrome/browser/notifications/notification_test_util.h"
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" 19 #include "chrome/browser/notifications/platform_notification_service_impl.h"
20 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "chrome/test/base/testing_profile_manager.h"
20 #include "components/content_settings/core/browser/host_content_settings_map.h" 23 #include "components/content_settings/core/browser/host_content_settings_map.h"
21 #include "content/public/browser/desktop_notification_delegate.h" 24 #include "content/public/browser/desktop_notification_delegate.h"
22 #include "content/public/common/notification_resources.h" 25 #include "content/public/common/notification_resources.h"
23 #include "content/public/common/platform_notification_data.h" 26 #include "content/public/common/platform_notification_data.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
27 30
28 #if defined(ENABLE_EXTENSIONS) 31 #if defined(ENABLE_EXTENSIONS)
29 #include "base/command_line.h" 32 #include "base/command_line.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 private: 77 private:
75 bool displayed_; 78 bool displayed_;
76 bool clicked_; 79 bool clicked_;
77 }; 80 };
78 81
79 } // namespace 82 } // namespace
80 83
81 class PlatformNotificationServiceTest : public testing::Test { 84 class PlatformNotificationServiceTest : public testing::Test {
82 public: 85 public:
83 void SetUp() override { 86 void SetUp() override {
87 profile_.reset(new TestingProfile());
84 ui_manager_.reset(new StubNotificationUIManager); 88 ui_manager_.reset(new StubNotificationUIManager);
85 profile_.reset(new TestingProfile()); 89 display_service_.reset(
86 90 new MessageCenterDisplayService(profile_.get(), ui_manager_.get()));
87 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); 91 service()->SetNotificationDisplayServiceForTesting(display_service_.get());
92 profile_manager_.reset(
93 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
94 ASSERT_TRUE(profile_manager_->SetUp());
88 } 95 }
89 96
90 void TearDown() override { 97 void TearDown() override {
91 service()->SetNotificationUIManagerForTesting(nullptr); 98 service()->SetNotificationDisplayServiceForTesting(nullptr);
92 99 display_service_.reset();
100 ui_manager_.reset();
93 profile_.reset(); 101 profile_.reset();
94 ui_manager_.reset(); 102 profile_manager_.reset();
103 TestingBrowserProcess::DeleteInstance();
95 } 104 }
96 105
97 protected: 106 protected:
98 // Displays a simple, fake notifications and returns a weak pointer to the 107 // Displays a simple, fake notifications and returns a weak pointer to the
99 // delegate receiving events for it (ownership is transferred to the service). 108 // delegate receiving events for it (ownership is transferred to the service).
100 MockDesktopNotificationDelegate* CreateSimplePageNotification() const { 109 MockDesktopNotificationDelegate* CreateSimplePageNotification() const {
101 return CreateSimplePageNotificationWithCloseClosure(nullptr); 110 return CreateSimplePageNotificationWithCloseClosure(nullptr);
102 } 111 }
103 112
104 // Displays a simple, fake notification and returns a weak pointer to the 113 // Displays a simple, fake notification and returns a weak pointer to the
(...skipping 20 matching lines...) Expand all
125 return PlatformNotificationServiceImpl::GetInstance(); 134 return PlatformNotificationServiceImpl::GetInstance();
126 } 135 }
127 136
128 // Returns the Profile to be used for these tests. 137 // Returns the Profile to be used for these tests.
129 Profile* profile() const { return profile_.get(); } 138 Profile* profile() const { return profile_.get(); }
130 139
131 // Returns the UI Manager on which notifications will be displayed. 140 // Returns the UI Manager on which notifications will be displayed.
132 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } 141 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); }
133 142
134 private: 143 private:
144 std::unique_ptr<TestingProfile> profile_;
135 std::unique_ptr<StubNotificationUIManager> ui_manager_; 145 std::unique_ptr<StubNotificationUIManager> ui_manager_;
136 std::unique_ptr<TestingProfile> profile_; 146 std::unique_ptr<MessageCenterDisplayService> display_service_;
137 147
148 std::unique_ptr<TestingProfileManager> profile_manager_;
138 content::TestBrowserThreadBundle thread_bundle_; 149 content::TestBrowserThreadBundle thread_bundle_;
139 }; 150 };
140 151
141 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) { 152 TEST_F(PlatformNotificationServiceTest, DisplayPageDisplayedEvent) {
142 auto* delegate = CreateSimplePageNotification(); 153 auto* delegate = CreateSimplePageNotification();
143 154
144 EXPECT_EQ(1u, ui_manager()->GetNotificationCount()); 155 EXPECT_EQ(1u, ui_manager()->GetNotificationCount());
145 EXPECT_TRUE(delegate->displayed()); 156 EXPECT_TRUE(delegate->displayed());
146 } 157 }
147 158
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 notification = service()->CreateNotificationFromData( 411 notification = service()->CreateNotificationFromData(
401 profile(), 412 profile(),
402 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), 413 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
403 notification_data, NotificationResources(), 414 notification_data, NotificationResources(),
404 new MockNotificationDelegate("hello")); 415 new MockNotificationDelegate("hello"));
405 EXPECT_EQ("NotificationTest", 416 EXPECT_EQ("NotificationTest",
406 base::UTF16ToUTF8(notification.context_message())); 417 base::UTF16ToUTF8(notification.context_message()));
407 } 418 }
408 419
409 #endif // defined(ENABLE_EXTENSIONS) 420 #endif // defined(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698