1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/desktop_notification_service.h"
8 #include "base/memory/scoped_ptr.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"
13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/web/WebNotificationPresenter.h"
18 class DesktopNotificationServiceTest
: public ChromeRenderViewHostTestHarness
{
20 virtual void SetUp() {
21 ChromeRenderViewHostTestHarness::SetUp();
23 // Creates the destop notification service.
24 service_
= DesktopNotificationServiceFactory::GetForProfile(profile());
27 DesktopNotificationService
* service_
;
31 TEST_F(DesktopNotificationServiceTest
, GetNotificationsSettings
) {
32 service_
->GrantPermission(GURL("http://allowed2.com"));
33 service_
->GrantPermission(GURL("http://allowed.com"));
34 service_
->DenyPermission(GURL("http://denied2.com"));
35 service_
->DenyPermission(GURL("http://denied.com"));
37 ContentSettingsForOneType settings
;
38 service_
->GetNotificationsSettings(&settings
);
39 // |settings| contains the default setting and 4 exceptions.
40 ASSERT_EQ(5u, settings
.size());
42 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
43 GURL("http://allowed.com")),
44 settings
[0].primary_pattern
);
45 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
47 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
48 GURL("http://allowed2.com")),
49 settings
[1].primary_pattern
);
50 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
52 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
53 GURL("http://denied.com")),
54 settings
[2].primary_pattern
);
55 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
57 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
58 GURL("http://denied2.com")),
59 settings
[3].primary_pattern
);
60 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
62 EXPECT_EQ(ContentSettingsPattern::Wildcard(),
63 settings
[4].primary_pattern
);
64 EXPECT_EQ(CONTENT_SETTING_ASK
,