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

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

Issue 1026853002: Integrate the notification database with the normal code path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ConfirmShow
Patch Set: Created 5 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/threading/platform_thread.h" 6 #include "base/threading/platform_thread.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/notifications/notification_test_util.h" 8 #include "chrome/browser/notifications/notification_test_util.h"
9 #include "chrome/browser/notifications/platform_notification_service_impl.h" 9 #include "chrome/browser/notifications/platform_notification_service_impl.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "content/public/browser/desktop_notification_delegate.h" 12 #include "content/public/browser/desktop_notification_delegate.h"
13 #include "content/public/common/platform_notification_data.h" 13 #include "content/public/common/platform_notification_data.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
17 17
18 namespace { 18 namespace {
19 19
20 #if !defined(OS_ANDROID)
21 const int64_t kPersistentNotificationId = 42;
22 #endif
23
20 class MockDesktopNotificationDelegate 24 class MockDesktopNotificationDelegate
21 : public content::DesktopNotificationDelegate { 25 : public content::DesktopNotificationDelegate {
22 public: 26 public:
23 MockDesktopNotificationDelegate() 27 MockDesktopNotificationDelegate()
24 : displayed_(false), 28 : displayed_(false),
25 clicked_(false) {} 29 clicked_(false) {}
26 30
27 ~MockDesktopNotificationDelegate() override {} 31 ~MockDesktopNotificationDelegate() override {}
28 32
29 // content::DesktopNotificationDelegate implementation. 33 // content::DesktopNotificationDelegate implementation.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 123
120 ASSERT_FALSE(close_closure.is_null()); 124 ASSERT_FALSE(close_closure.is_null());
121 close_closure.Run(); 125 close_closure.Run();
122 126
123 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 127 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
124 128
125 // Note that we cannot verify whether the closed event was called on the 129 // Note that we cannot verify whether the closed event was called on the
126 // delegate given that it'd result in a use-after-free. 130 // delegate given that it'd result in a use-after-free.
127 } 131 }
128 132
133 // TODO(peter): Re-enable this test when //content is responsible for creating
134 // the notification delegate ids.
135 #if !defined(OS_ANDROID)
129 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) { 136 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) {
130 content::PlatformNotificationData notification_data; 137 content::PlatformNotificationData notification_data;
131 notification_data.title = base::ASCIIToUTF16("My notification's title"); 138 notification_data.title = base::ASCIIToUTF16("My notification's title");
132 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 139 notification_data.body = base::ASCIIToUTF16("Hello, world!");
133 140
134 service()->DisplayPersistentNotification( 141 service()->DisplayPersistentNotification(
135 profile(), 42 /* sw_registration_id */, GURL("https://chrome.com/"), 142 profile(), kPersistentNotificationId, GURL("https://chrome.com/"),
136 SkBitmap(), notification_data); 143 SkBitmap(), notification_data);
137 144
138 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 145 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
139 146
140 const Notification& notification = ui_manager()->GetNotificationAt(0); 147 const Notification& notification = ui_manager()->GetNotificationAt(0);
141 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 148 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
142 EXPECT_EQ("My notification's title", 149 EXPECT_EQ("My notification's title",
143 base::UTF16ToUTF8(notification.title())); 150 base::UTF16ToUTF8(notification.title()));
144 EXPECT_EQ("Hello, world!", 151 EXPECT_EQ("Hello, world!",
145 base::UTF16ToUTF8(notification.message())); 152 base::UTF16ToUTF8(notification.message()));
146 153
147 service()->ClosePersistentNotification(profile(), 154 service()->ClosePersistentNotification(profile(), kPersistentNotificationId);
148 notification.delegate_id());
149 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 155 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
150 } 156 }
157 #endif // !defined(OS_ANDROID)
151 158
152 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 159 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
153 content::PlatformNotificationData notification_data; 160 content::PlatformNotificationData notification_data;
154 notification_data.title = base::ASCIIToUTF16("My notification's title"); 161 notification_data.title = base::ASCIIToUTF16("My notification's title");
155 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 162 notification_data.body = base::ASCIIToUTF16("Hello, world!");
156 notification_data.silent = true; 163 notification_data.silent = true;
157 164
158 MockDesktopNotificationDelegate* delegate 165 MockDesktopNotificationDelegate* delegate
159 = new MockDesktopNotificationDelegate(); 166 = new MockDesktopNotificationDelegate();
160 service()->DisplayNotification(profile(), 167 service()->DisplayNotification(profile(),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 251
245 service()->DisplayPersistentNotification( 252 service()->DisplayPersistentNotification(
246 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), 253 profile(), 42 /* sw_registration_id */, origin, SkBitmap(),
247 content::PlatformNotificationData()); 254 content::PlatformNotificationData());
248 255
249 base::Time after_persistent_notification = 256 base::Time after_persistent_notification =
250 profile()->GetHostContentSettingsMap()->GetLastUsage( 257 profile()->GetHostContentSettingsMap()->GetLastUsage(
251 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 258 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
252 EXPECT_GT(after_persistent_notification, after_page_notification); 259 EXPECT_GT(after_persistent_notification, after_page_notification);
253 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698