| 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/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/notifications/notification_delegate.h" | 9 #include "chrome/browser/notifications/notification_delegate.h" |
| 10 #include "chrome/browser/notifications/notification_test_util.h" | 10 #include "chrome/browser/notifications/notification_test_util.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 testing::ElementsAreArray(kNotificationVibrationPattern)); | 243 testing::ElementsAreArray(kNotificationVibrationPattern)); |
| 244 | 244 |
| 245 EXPECT_TRUE(notification.silent()); | 245 EXPECT_TRUE(notification.silent()); |
| 246 | 246 |
| 247 const auto& buttons = notification.buttons(); | 247 const auto& buttons = notification.buttons(); |
| 248 ASSERT_EQ(2u, buttons.size()); | 248 ASSERT_EQ(2u, buttons.size()); |
| 249 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); | 249 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); |
| 250 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); | 250 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { | |
| 254 // Both page and persistent notifications should update the last usage | |
| 255 // time of the notification permission for the origin. | |
| 256 GURL origin("https://chrome.com/"); | |
| 257 base::Time begin_time; | |
| 258 | |
| 259 CreateSimplePageNotification(); | |
| 260 | |
| 261 base::Time after_page_notification = | |
| 262 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage( | |
| 263 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 264 EXPECT_GT(after_page_notification, begin_time); | |
| 265 | |
| 266 // Ensure that there is at least some time between the two calls. | |
| 267 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | |
| 268 | |
| 269 service()->DisplayPersistentNotification( | |
| 270 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), | |
| 271 content::PlatformNotificationData()); | |
| 272 | |
| 273 base::Time after_persistent_notification = | |
| 274 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage( | |
| 275 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 276 EXPECT_GT(after_persistent_notification, after_page_notification); | |
| 277 } | |
| 278 | |
| 279 #if defined(ENABLE_EXTENSIONS) | 253 #if defined(ENABLE_EXTENSIONS) |
| 280 | 254 |
| 281 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) { | 255 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) { |
| 282 base::string16 display_name = service()->DisplayNameForContextMessage( | 256 base::string16 display_name = service()->DisplayNameForContextMessage( |
| 283 profile(), GURL("https://chrome.com/")); | 257 profile(), GURL("https://chrome.com/")); |
| 284 | 258 |
| 285 EXPECT_TRUE(display_name.empty()); | 259 EXPECT_TRUE(display_name.empty()); |
| 286 | 260 |
| 287 // Create a mocked extension. | 261 // Create a mocked extension. |
| 288 scoped_refptr<extensions::Extension> extension = | 262 scoped_refptr<extensions::Extension> extension = |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 361 |
| 388 notification = service()->CreateNotificationFromData( | 362 notification = service()->CreateNotificationFromData( |
| 389 profile(), | 363 profile(), |
| 390 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 364 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
| 391 SkBitmap(), notification_data, new MockNotificationDelegate("hello")); | 365 SkBitmap(), notification_data, new MockNotificationDelegate("hello")); |
| 392 EXPECT_EQ("NotificationTest", | 366 EXPECT_EQ("NotificationTest", |
| 393 base::UTF16ToUTF8(notification.context_message())); | 367 base::UTF16ToUTF8(notification.context_message())); |
| 394 } | 368 } |
| 395 | 369 |
| 396 #endif // defined(ENABLE_EXTENSIONS) | 370 #endif // defined(ENABLE_EXTENSIONS) |
| OLD | NEW |