OLD | NEW |
1 // Copyright (c) 2011 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 "chrome/browser/notifications/desktop_notification_service.h" | |
6 | |
7 #include "base/bind.h" | 5 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 6 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/synchronization/waitable_event.h" | |
11 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" | |
16 | 10 |
17 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { | 11 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { |
18 protected: | 12 protected: |
19 virtual void SetUp() { | 13 virtual void SetUp() { |
20 ChromeRenderViewHostTestHarness::SetUp(); | 14 ChromeRenderViewHostTestHarness::SetUp(); |
21 | |
22 // Creates the destop notification service. | |
23 service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); | |
24 } | 15 } |
25 | |
26 DesktopNotificationService* service_; | |
27 }; | 16 }; |
28 | 17 |
29 | 18 |
30 TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) { | 19 TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) { |
31 service_->GrantPermission(GURL("http://allowed2.com")); | 20 DesktopNotificationProfileUtil::GrantPermission(profile(), |
32 service_->GrantPermission(GURL("http://allowed.com")); | 21 GURL("http://allowed2.com")); |
33 service_->DenyPermission(GURL("http://denied2.com")); | 22 DesktopNotificationProfileUtil::GrantPermission(profile(), |
34 service_->DenyPermission(GURL("http://denied.com")); | 23 GURL("http://allowed.com")); |
| 24 DesktopNotificationProfileUtil::DenyPermission(profile(), |
| 25 GURL("http://denied2.com")); |
| 26 DesktopNotificationProfileUtil::DenyPermission(profile(), |
| 27 GURL("http://denied.com")); |
35 | 28 |
36 ContentSettingsForOneType settings; | 29 ContentSettingsForOneType settings; |
37 service_->GetNotificationsSettings(&settings); | 30 DesktopNotificationProfileUtil::GetNotificationsSettings( |
| 31 profile(), &settings); |
38 // |settings| contains the default setting and 4 exceptions. | 32 // |settings| contains the default setting and 4 exceptions. |
39 ASSERT_EQ(5u, settings.size()); | 33 ASSERT_EQ(5u, settings.size()); |
40 | 34 |
41 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 35 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
42 GURL("http://allowed.com")), | 36 GURL("http://allowed.com")), |
43 settings[0].primary_pattern); | 37 settings[0].primary_pattern); |
44 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 38 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
45 settings[0].setting); | 39 settings[0].setting); |
46 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 40 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
47 GURL("http://allowed2.com")), | 41 GURL("http://allowed2.com")), |
48 settings[1].primary_pattern); | 42 settings[1].primary_pattern); |
49 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 43 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
50 settings[1].setting); | 44 settings[1].setting); |
51 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 45 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
52 GURL("http://denied.com")), | 46 GURL("http://denied.com")), |
53 settings[2].primary_pattern); | 47 settings[2].primary_pattern); |
54 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 48 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
55 settings[2].setting); | 49 settings[2].setting); |
56 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 50 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
57 GURL("http://denied2.com")), | 51 GURL("http://denied2.com")), |
58 settings[3].primary_pattern); | 52 settings[3].primary_pattern); |
59 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 53 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
60 settings[3].setting); | 54 settings[3].setting); |
61 EXPECT_EQ(ContentSettingsPattern::Wildcard(), | 55 EXPECT_EQ(ContentSettingsPattern::Wildcard(), |
62 settings[4].primary_pattern); | 56 settings[4].primary_pattern); |
63 EXPECT_EQ(CONTENT_SETTING_ASK, | 57 EXPECT_EQ(CONTENT_SETTING_ASK, |
64 settings[4].setting); | 58 settings[4].setting); |
65 } | 59 } |
OLD | NEW |