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

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, 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 const unsigned kNotificationVibrate[] = { 100, 200, 300 };
Peter Beverloo 2015/04/21 17:58:23 nit: blank line
Peter Beverloo 2015/04/21 17:58:23 Please use either int or int64_t here.
Sanghyun Park 2015/04/23 11:08:26 Done.
20 #if !defined(OS_ANDROID) 21 #if !defined(OS_ANDROID)
21 const int64_t kPersistentNotificationId = 42; 22 const int64_t kPersistentNotificationId = 42;
22 #endif 23 #endif
23 24
24 class MockDesktopNotificationDelegate 25 class MockDesktopNotificationDelegate
25 : public content::DesktopNotificationDelegate { 26 : public content::DesktopNotificationDelegate {
26 public: 27 public:
27 MockDesktopNotificationDelegate() 28 MockDesktopNotificationDelegate()
28 : displayed_(false), 29 : displayed_(false),
29 clicked_(false) {} 30 clicked_(false) {}
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 base::UTF16ToUTF8(notification.title())); 151 base::UTF16ToUTF8(notification.title()));
151 EXPECT_EQ("Hello, world!", 152 EXPECT_EQ("Hello, world!",
152 base::UTF16ToUTF8(notification.message())); 153 base::UTF16ToUTF8(notification.message()));
153 154
154 service()->ClosePersistentNotification(profile(), kPersistentNotificationId); 155 service()->ClosePersistentNotification(profile(), kPersistentNotificationId);
155 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 156 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
156 } 157 }
157 #endif // !defined(OS_ANDROID) 158 #endif // !defined(OS_ANDROID)
158 159
159 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 160 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
161 std::vector<unsigned> vibrate_pattern(
Peter Beverloo 2015/04/21 17:58:23 int/int64_t (whatever you choose to use in the //c
Sanghyun Park 2015/04/23 11:08:26 Done.
162 kNotificationVibrate,
163 kNotificationVibrate + arraysize(kNotificationVibrate));
164
160 content::PlatformNotificationData notification_data; 165 content::PlatformNotificationData notification_data;
161 notification_data.title = base::ASCIIToUTF16("My notification's title"); 166 notification_data.title = base::ASCIIToUTF16("My notification's title");
162 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 167 notification_data.body = base::ASCIIToUTF16("Hello, world!");
168 notification_data.vibrate = vibrate_pattern;
163 notification_data.silent = true; 169 notification_data.silent = true;
164 170
165 MockDesktopNotificationDelegate* delegate 171 MockDesktopNotificationDelegate* delegate
166 = new MockDesktopNotificationDelegate(); 172 = new MockDesktopNotificationDelegate();
167 service()->DisplayNotification(profile(), 173 service()->DisplayNotification(profile(),
168 GURL("https://chrome.com/"), 174 GURL("https://chrome.com/"),
169 SkBitmap(), 175 SkBitmap(),
170 notification_data, 176 notification_data,
171 make_scoped_ptr(delegate), 177 make_scoped_ptr(delegate),
172 nullptr); 178 nullptr);
173 179
174 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 180 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
175 181
176 const Notification& notification = ui_manager()->GetNotificationAt(0); 182 const Notification& notification = ui_manager()->GetNotificationAt(0);
177 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 183 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
178 EXPECT_EQ("My notification's title", 184 EXPECT_EQ("My notification's title",
179 base::UTF16ToUTF8(notification.title())); 185 base::UTF16ToUTF8(notification.title()));
180 EXPECT_EQ("Hello, world!", 186 EXPECT_EQ("Hello, world!",
181 base::UTF16ToUTF8(notification.message())); 187 base::UTF16ToUTF8(notification.message()));
188
189 ASSERT_EQ(vibrate_pattern.size(), notification.vibrate().size());
190 for (size_t i = 0; i < vibrate_pattern.size(); ++i)
191 EXPECT_EQ(vibrate_pattern[i], notification.vibrate()[i]);
192
182 EXPECT_TRUE(notification.silent()); 193 EXPECT_TRUE(notification.silent());
183 } 194 }
184 195
185 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { 196 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) {
186 base::string16 display_name = 197 base::string16 display_name =
187 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); 198 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/"));
188 199
189 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); 200 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name);
190 201
191 // TODO(peter): Include unit tests for the extension-name translation 202 // TODO(peter): Include unit tests for the extension-name translation
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 262
252 service()->DisplayPersistentNotification( 263 service()->DisplayPersistentNotification(
253 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), 264 profile(), 42 /* sw_registration_id */, origin, SkBitmap(),
254 content::PlatformNotificationData()); 265 content::PlatformNotificationData());
255 266
256 base::Time after_persistent_notification = 267 base::Time after_persistent_notification =
257 profile()->GetHostContentSettingsMap()->GetLastUsage( 268 profile()->GetHostContentSettingsMap()->GetLastUsage(
258 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 269 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
259 EXPECT_GT(after_persistent_notification, after_page_notification); 270 EXPECT_GT(after_persistent_notification, after_page_notification);
260 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698