15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/browser/notifications/desktop_notification_profile_util.h"
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/chrome_render_view_host_test_harness.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_profile.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness {
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected:
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUp() {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ChromeRenderViewHostTestHarness::SetUp();
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) {
205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DesktopNotificationProfileUtil::GrantPermission(profile(),
215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                  GURL("http://allowed2.com"));
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DesktopNotificationProfileUtil::GrantPermission(profile(),
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                  GURL("http://allowed.com"));
245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DesktopNotificationProfileUtil::DenyPermission(profile(),
255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                 GURL("http://denied2.com"));
265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DesktopNotificationProfileUtil::DenyPermission(profile(),
275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                 GURL("http://denied.com"));
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ContentSettingsForOneType settings;
305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DesktopNotificationProfileUtil::GetNotificationsSettings(
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      profile(), &settings);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |settings| contains the default setting and 4 exceptions.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(5u, settings.size());
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                GURL("http://allowed.com")),
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[0].primary_pattern);
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(CONTENT_SETTING_ALLOW,
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[0].setting);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                GURL("http://allowed2.com")),
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[1].primary_pattern);
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(CONTENT_SETTING_ALLOW,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[1].setting);
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                GURL("http://denied.com")),
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[2].primary_pattern);
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(CONTENT_SETTING_BLOCK,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[2].setting);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                GURL("http://denied2.com")),
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[3].primary_pattern);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(CONTENT_SETTING_BLOCK,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[3].setting);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(ContentSettingsPattern::Wildcard(),
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[4].primary_pattern);
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(CONTENT_SETTING_ASK,
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            settings[4].setting);
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
60