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

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

Issue 1054573002: Implement support for notification.vibrate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 18
18 namespace { 19 namespace {
19 20
21 const int kNotificationVibrationPattern[] = { 100, 200, 300 };
22
20 #if !defined(OS_ANDROID) 23 #if !defined(OS_ANDROID)
21 const int64_t kPersistentNotificationId = 42; 24 const int64_t kPersistentNotificationId = 42;
22 #endif 25 #endif
23 26
24 class MockDesktopNotificationDelegate 27 class MockDesktopNotificationDelegate
25 : public content::DesktopNotificationDelegate { 28 : public content::DesktopNotificationDelegate {
26 public: 29 public:
27 MockDesktopNotificationDelegate() 30 MockDesktopNotificationDelegate()
28 : displayed_(false), 31 : displayed_(false),
29 clicked_(false) {} 32 clicked_(false) {}
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 base::UTF16ToUTF8(notification.title())); 153 base::UTF16ToUTF8(notification.title()));
151 EXPECT_EQ("Hello, world!", 154 EXPECT_EQ("Hello, world!",
152 base::UTF16ToUTF8(notification.message())); 155 base::UTF16ToUTF8(notification.message()));
153 156
154 service()->ClosePersistentNotification(profile(), kPersistentNotificationId); 157 service()->ClosePersistentNotification(profile(), kPersistentNotificationId);
155 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 158 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
156 } 159 }
157 #endif // !defined(OS_ANDROID) 160 #endif // !defined(OS_ANDROID)
158 161
159 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 162 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
163 std::vector<int> vibration_pattern(
164 kNotificationVibrationPattern,
165 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
166
160 content::PlatformNotificationData notification_data; 167 content::PlatformNotificationData notification_data;
161 notification_data.title = base::ASCIIToUTF16("My notification's title"); 168 notification_data.title = base::ASCIIToUTF16("My notification's title");
162 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 169 notification_data.body = base::ASCIIToUTF16("Hello, world!");
170 notification_data.vibration_pattern = vibration_pattern;
163 notification_data.silent = true; 171 notification_data.silent = true;
164 172
165 MockDesktopNotificationDelegate* delegate 173 MockDesktopNotificationDelegate* delegate
166 = new MockDesktopNotificationDelegate(); 174 = new MockDesktopNotificationDelegate();
167 service()->DisplayNotification(profile(), 175 service()->DisplayNotification(profile(),
168 GURL("https://chrome.com/"), 176 GURL("https://chrome.com/"),
169 SkBitmap(), 177 SkBitmap(),
170 notification_data, 178 notification_data,
171 make_scoped_ptr(delegate), 179 make_scoped_ptr(delegate),
172 nullptr); 180 nullptr);
173 181
174 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 182 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
175 183
176 const Notification& notification = ui_manager()->GetNotificationAt(0); 184 const Notification& notification = ui_manager()->GetNotificationAt(0);
177 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 185 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
178 EXPECT_EQ("My notification's title", 186 EXPECT_EQ("My notification's title",
179 base::UTF16ToUTF8(notification.title())); 187 base::UTF16ToUTF8(notification.title()));
180 EXPECT_EQ("Hello, world!", 188 EXPECT_EQ("Hello, world!",
181 base::UTF16ToUTF8(notification.message())); 189 base::UTF16ToUTF8(notification.message()));
190
191 EXPECT_THAT(notification.vibration_pattern(),
192 testing::ElementsAreArray(kNotificationVibrationPattern));
193
182 EXPECT_TRUE(notification.silent()); 194 EXPECT_TRUE(notification.silent());
183 } 195 }
184 196
185 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { 197 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) {
186 base::string16 display_name = 198 base::string16 display_name =
187 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); 199 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/"));
188 200
189 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); 201 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name);
190 202
191 // TODO(peter): Include unit tests for the extension-name translation 203 // TODO(peter): Include unit tests for the extension-name translation
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 263
252 service()->DisplayPersistentNotification( 264 service()->DisplayPersistentNotification(
253 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), 265 profile(), 42 /* sw_registration_id */, origin, SkBitmap(),
254 content::PlatformNotificationData()); 266 content::PlatformNotificationData());
255 267
256 base::Time after_persistent_notification = 268 base::Time after_persistent_notification =
257 profile()->GetHostContentSettingsMap()->GetLastUsage( 269 profile()->GetHostContentSettingsMap()->GetLastUsage(
258 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 270 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
259 EXPECT_GT(after_persistent_notification, after_page_notification); 271 EXPECT_GT(after_persistent_notification, after_page_notification);
260 } 272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698