| 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 <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/strings/nullable_string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 15 #include "chrome/browser/notifications/notification_delegate.h" | 16 #include "chrome/browser/notifications/notification_delegate.h" |
| 16 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" |
| 17 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 18 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 std::vector<int> vibration_pattern( | 222 std::vector<int> vibration_pattern( |
| 222 kNotificationVibrationPattern, | 223 kNotificationVibrationPattern, |
| 223 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); | 224 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); |
| 224 | 225 |
| 225 PlatformNotificationData notification_data; | 226 PlatformNotificationData notification_data; |
| 226 notification_data.title = base::ASCIIToUTF16("My notification's title"); | 227 notification_data.title = base::ASCIIToUTF16("My notification's title"); |
| 227 notification_data.body = base::ASCIIToUTF16("Hello, world!"); | 228 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
| 228 notification_data.vibration_pattern = vibration_pattern; | 229 notification_data.vibration_pattern = vibration_pattern; |
| 229 notification_data.silent = true; | 230 notification_data.silent = true; |
| 230 notification_data.actions.resize(2); | 231 notification_data.actions.resize(2); |
| 232 notification_data.actions[0].type = |
| 233 content::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON; |
| 231 notification_data.actions[0].title = base::ASCIIToUTF16("Button 1"); | 234 notification_data.actions[0].title = base::ASCIIToUTF16("Button 1"); |
| 232 notification_data.actions[1].title = base::ASCIIToUTF16("Button 2"); | 235 notification_data.actions[0].placeholder = base::NullableString16(); |
| 236 notification_data.actions[1].type = |
| 237 content::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; |
| 238 notification_data.actions[1].title = base::ASCIIToUTF16("Howdy?"); |
| 239 notification_data.actions[1].placeholder = base::NullableString16( |
| 240 base::ASCIIToUTF16("I'm FLOWEY the FLOWER."), false); |
| 233 | 241 |
| 234 NotificationResources notification_resources; | 242 NotificationResources notification_resources; |
| 235 notification_resources.action_icons.resize(notification_data.actions.size()); | 243 notification_resources.action_icons.resize(notification_data.actions.size()); |
| 236 | 244 |
| 237 service()->DisplayPersistentNotification( | 245 service()->DisplayPersistentNotification( |
| 238 profile(), 0u /* persistent notification */, GURL("https://chrome.com/"), | 246 profile(), 0u /* persistent notification */, GURL("https://chrome.com/"), |
| 239 notification_data, notification_resources); | 247 notification_data, notification_resources); |
| 240 | 248 |
| 241 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 249 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
| 242 | 250 |
| 243 const Notification& notification = ui_manager()->GetNotificationAt(0); | 251 const Notification& notification = ui_manager()->GetNotificationAt(0); |
| 244 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); | 252 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); |
| 245 EXPECT_EQ("My notification's title", base::UTF16ToUTF8(notification.title())); | 253 EXPECT_EQ("My notification's title", base::UTF16ToUTF8(notification.title())); |
| 246 EXPECT_EQ("Hello, world!", base::UTF16ToUTF8(notification.message())); | 254 EXPECT_EQ("Hello, world!", base::UTF16ToUTF8(notification.message())); |
| 247 | 255 |
| 248 EXPECT_THAT(notification.vibration_pattern(), | 256 EXPECT_THAT(notification.vibration_pattern(), |
| 249 testing::ElementsAreArray(kNotificationVibrationPattern)); | 257 testing::ElementsAreArray(kNotificationVibrationPattern)); |
| 250 | 258 |
| 251 EXPECT_TRUE(notification.silent()); | 259 EXPECT_TRUE(notification.silent()); |
| 252 | 260 |
| 253 const auto& buttons = notification.buttons(); | 261 const auto& buttons = notification.buttons(); |
| 254 ASSERT_EQ(2u, buttons.size()); | 262 ASSERT_EQ(2u, buttons.size()); |
| 263 EXPECT_EQ(message_center::BUTTON_INFO_TYPE_BUTTON, buttons[0].type); |
| 255 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); | 264 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); |
| 256 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); | 265 EXPECT_EQ(notification_data.actions[0].placeholder, base::NullableString16()); |
| 266 |
| 267 EXPECT_EQ(message_center::BUTTON_INFO_TYPE_TEXT, buttons[1].type); |
| 268 EXPECT_EQ("Howdy?", base::UTF16ToUTF8(buttons[1].title)); |
| 269 EXPECT_EQ(notification_data.actions[1].placeholder, |
| 270 base::NullableString16(base::ASCIIToUTF16("I'm FLOWEY the FLOWER."), |
| 271 false)); |
| 257 } | 272 } |
| 258 | 273 |
| 259 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { | 274 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { |
| 260 // Both page and persistent notifications should update the last usage | 275 // Both page and persistent notifications should update the last usage |
| 261 // time of the notification permission for the origin. | 276 // time of the notification permission for the origin. |
| 262 GURL origin("https://chrome.com/"); | 277 GURL origin("https://chrome.com/"); |
| 263 base::Time begin_time; | 278 base::Time begin_time; |
| 264 | 279 |
| 265 CreateSimplePageNotification(); | 280 CreateSimplePageNotification(); |
| 266 | 281 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 notification = service()->CreateNotificationFromData( | 414 notification = service()->CreateNotificationFromData( |
| 400 profile(), | 415 profile(), |
| 401 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 416 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
| 402 notification_data, NotificationResources(), | 417 notification_data, NotificationResources(), |
| 403 new MockNotificationDelegate("hello")); | 418 new MockNotificationDelegate("hello")); |
| 404 EXPECT_EQ("NotificationTest", | 419 EXPECT_EQ("NotificationTest", |
| 405 base::UTF16ToUTF8(notification.context_message())); | 420 base::UTF16ToUTF8(notification.context_message())); |
| 406 } | 421 } |
| 407 | 422 |
| 408 #endif // defined(ENABLE_EXTENSIONS) | 423 #endif // defined(ENABLE_EXTENSIONS) |
| OLD | NEW |