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

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

Issue 2697473002: Remove last usage functions from HostContentSettingsMap and clean up prefs (Closed)
Patch Set: fix up unit test Created 3 years, 10 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 <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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 EXPECT_TRUE(notification.silent()); 284 EXPECT_TRUE(notification.silent());
285 285
286 const auto& buttons = notification.buttons(); 286 const auto& buttons = notification.buttons();
287 ASSERT_EQ(2u, buttons.size()); 287 ASSERT_EQ(2u, buttons.size());
288 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title)); 288 EXPECT_EQ("Button 1", base::UTF16ToUTF8(buttons[0].title));
289 EXPECT_EQ(message_center::ButtonType::BUTTON, buttons[0].type); 289 EXPECT_EQ(message_center::ButtonType::BUTTON, buttons[0].type);
290 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title)); 290 EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title));
291 EXPECT_EQ(message_center::ButtonType::TEXT, buttons[1].type); 291 EXPECT_EQ(message_center::ButtonType::TEXT, buttons[1].type);
292 } 292 }
293 293
294 TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) {
295 // Both page and persistent notifications should update the last usage
296 // time of the notification permission for the origin.
297 GURL origin("https://chrome.com/");
298 base::Time begin_time;
299
300 CreateSimplePageNotification();
301
302 base::Time after_page_notification =
303 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage(
304 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
305 EXPECT_GT(after_page_notification, begin_time);
306
307 // Ensure that there is at least some time between the two calls.
308 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
309
310 service()->DisplayPersistentNotification(
311 profile(), kNotificationId, GURL() /* service_worker_scope */, origin,
312 PlatformNotificationData(), NotificationResources());
313
314 base::Time after_persistent_notification =
315 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage(
316 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
317 EXPECT_GT(after_persistent_notification, after_page_notification);
318 }
319
320 #if BUILDFLAG(ENABLE_EXTENSIONS) 294 #if BUILDFLAG(ENABLE_EXTENSIONS)
321 295
322 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) { 296 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) {
323 base::string16 display_name = service()->DisplayNameForContextMessage( 297 base::string16 display_name = service()->DisplayNameForContextMessage(
324 profile(), GURL("https://chrome.com/")); 298 profile(), GURL("https://chrome.com/"));
325 299
326 EXPECT_TRUE(display_name.empty()); 300 EXPECT_TRUE(display_name.empty());
327 301
328 // Create a mocked extension. 302 // Create a mocked extension.
329 scoped_refptr<extensions::Extension> extension = 303 scoped_refptr<extensions::Extension> extension =
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 profile(), 410 profile(),
437 GURL() /* service_worker_scope */, 411 GURL() /* service_worker_scope */,
438 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), 412 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
439 notification_data, NotificationResources(), 413 notification_data, NotificationResources(),
440 new MockNotificationDelegate("hello")); 414 new MockNotificationDelegate("hello"));
441 EXPECT_EQ("NotificationTest", 415 EXPECT_EQ("NotificationTest",
442 base::UTF16ToUTF8(notification.context_message())); 416 base::UTF16ToUTF8(notification.context_message()));
443 } 417 }
444 418
445 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 419 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698