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

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

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Jam nits. Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/test/simple_test_clock.h"
17 #include "base/time/clock.h"
16 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/notifications/desktop_notification_service.h" 22 #include "chrome/browser/notifications/desktop_notification_service.h"
20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
21 #include "chrome/browser/notifications/notification.h" 24 #include "chrome/browser/notifications/notification.h"
22 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/content_settings.h" 30 #include "chrome/common/content_settings.h"
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 browser(), false, "no_such_file.png", "Title2", "Body2", "chat"); 774 browser(), false, "no_such_file.png", "Title2", "Body2", "chat");
772 EXPECT_NE("-1", result); 775 EXPECT_NE("-1", result);
773 776
774 ASSERT_EQ(1, GetNotificationCount()); 777 ASSERT_EQ(1, GetNotificationCount());
775 message_center::NotificationList::Notifications notifications = 778 message_center::NotificationList::Notifications notifications =
776 message_center::MessageCenter::Get()->GetVisibleNotifications(); 779 message_center::MessageCenter::Get()->GetVisibleNotifications();
777 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title()); 780 EXPECT_EQ(base::ASCIIToUTF16("Title2"), (*notifications.rbegin())->title());
778 EXPECT_EQ(base::ASCIIToUTF16("Body2"), 781 EXPECT_EQ(base::ASCIIToUTF16("Body2"),
779 (*notifications.rbegin())->message()); 782 (*notifications.rbegin())->message());
780 } 783 }
784
785 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) {
786 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
787
788 HostContentSettingsMap* settings_map =
789 browser()->profile()->GetHostContentSettingsMap();
790 base::SimpleTestClock* clock = new base::SimpleTestClock();
791 settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock));
792 clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10));
793
794 // Creates a simple notification.
795 AllowAllOrigins();
796 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
797
798 std::string result = CreateSimpleNotification(browser(), true);
799 EXPECT_NE("-1", result);
800
801 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
802 GetTestPageURL().GetOrigin(),
803 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
804 .ToDoubleT(),
805 10);
806
807 clock->Advance(base::TimeDelta::FromSeconds(3));
808
809 result = CreateSimpleNotification(browser(), true);
810 EXPECT_NE("-1", result);
811
812 EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
813 GetTestPageURL().GetOrigin(),
814 CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
815 .ToDoubleT(),
816 13);
817 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698