OLD | NEW |
---|---|
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" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { | 180 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { |
181 std::vector<int> vibration_pattern( | 181 std::vector<int> vibration_pattern( |
182 kNotificationVibrationPattern, | 182 kNotificationVibrationPattern, |
183 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); | 183 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); |
184 | 184 |
185 content::PlatformNotificationData notification_data; | 185 content::PlatformNotificationData notification_data; |
186 notification_data.title = base::ASCIIToUTF16("My notification's title"); | 186 notification_data.title = base::ASCIIToUTF16("My notification's title"); |
187 notification_data.body = base::ASCIIToUTF16("Hello, world!"); | 187 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
188 notification_data.vibration_pattern = vibration_pattern; | 188 notification_data.vibration_pattern = vibration_pattern; |
189 notification_data.silent = true; | 189 notification_data.silent = true; |
190 notification_data.actions.resize(2); | |
Peter Beverloo
2015/07/31 19:17:51
nit: operator[] will do this for you (that's why i
johnme
2015/07/31 19:38:24
Only for maps, not for vectors!
| |
191 notification_data.actions[0].title = base::ASCIIToUTF16("Button 1"); | |
192 notification_data.actions[1].title = base::ASCIIToUTF16("Button 2"); | |
190 | 193 |
191 MockDesktopNotificationDelegate* delegate | 194 MockDesktopNotificationDelegate* delegate |
192 = new MockDesktopNotificationDelegate(); | 195 = new MockDesktopNotificationDelegate(); |
193 service()->DisplayNotification(profile(), | 196 service()->DisplayNotification(profile(), |
194 GURL("https://chrome.com/"), | 197 GURL("https://chrome.com/"), |
195 SkBitmap(), | 198 SkBitmap(), |
196 notification_data, | 199 notification_data, |
197 make_scoped_ptr(delegate), | 200 make_scoped_ptr(delegate), |
198 nullptr); | 201 nullptr); |
199 | 202 |
200 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 203 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
201 | 204 |
202 const Notification& notification = ui_manager()->GetNotificationAt(0); | 205 const Notification& notification = ui_manager()->GetNotificationAt(0); |
203 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); | 206 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); |
204 EXPECT_EQ("My notification's title", | 207 EXPECT_EQ("My notification's title", |
205 base::UTF16ToUTF8(notification.title())); | 208 base::UTF16ToUTF8(notification.title())); |
206 EXPECT_EQ("Hello, world!", | 209 EXPECT_EQ("Hello, world!", |
207 base::UTF16ToUTF8(notification.message())); | 210 base::UTF16ToUTF8(notification.message())); |
208 | 211 |
209 EXPECT_THAT(notification.vibration_pattern(), | 212 EXPECT_THAT(notification.vibration_pattern(), |
210 testing::ElementsAreArray(kNotificationVibrationPattern)); | 213 testing::ElementsAreArray(kNotificationVibrationPattern)); |
211 | 214 |
212 EXPECT_TRUE(notification.silent()); | 215 EXPECT_TRUE(notification.silent()); |
216 | |
217 const auto& buttons = notification.buttons(); | |
218 ASSERT_EQ(2u, buttons.size()); | |
219 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); | |
220 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); | |
213 } | 221 } |
214 | 222 |
215 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { | 223 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { |
216 base::string16 display_name = | 224 base::string16 display_name = |
217 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); | 225 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); |
218 | 226 |
219 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); | 227 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); |
220 | 228 |
221 // TODO(peter): Include unit tests for the extension-name translation | 229 // TODO(peter): Include unit tests for the extension-name translation |
222 // functionality of DisplayNameForOriginInProcessId. | 230 // functionality of DisplayNameForOriginInProcessId. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 // Verify that the service indicates that permission has been granted. We only | 347 // Verify that the service indicates that permission has been granted. We only |
340 // check the UI thread-method for now, as that's the one guarding the behavior | 348 // check the UI thread-method for now, as that's the one guarding the behavior |
341 // in the browser process. | 349 // in the browser process. |
342 EXPECT_EQ(blink::WebNotificationPermissionAllowed, | 350 EXPECT_EQ(blink::WebNotificationPermissionAllowed, |
343 service()->CheckPermissionOnUIThread(profile(), | 351 service()->CheckPermissionOnUIThread(profile(), |
344 extension->url(), | 352 extension->url(), |
345 kFakeRenderProcessId)); | 353 kFakeRenderProcessId)); |
346 } | 354 } |
347 | 355 |
348 #endif // defined(ENABLE_EXTENSIONS) | 356 #endif // defined(ENABLE_EXTENSIONS) |
OLD | NEW |