Home | History | Annotate | Download | only in notifications
      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.
      4 
      5 #include "chrome/browser/notifications/desktop_notification_service.h"
      6 
      7 #include "base/bind.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"
     17 
     18 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness {
     19  protected:
     20   virtual void SetUp() {
     21     ChromeRenderViewHostTestHarness::SetUp();
     22 
     23     // Creates the destop notification service.
     24     service_ = DesktopNotificationServiceFactory::GetForProfile(profile());
     25   }
     26 
     27   DesktopNotificationService* service_;
     28 };
     29 
     30 
     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"));
     36 
     37   ContentSettingsForOneType settings;
     38   service_->GetNotificationsSettings(&settings);
     39   // |settings| contains the default setting and 4 exceptions.
     40   ASSERT_EQ(5u, settings.size());
     41 
     42   EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
     43                 GURL("http://allowed.com")),
     44             settings[0].primary_pattern);
     45   EXPECT_EQ(CONTENT_SETTING_ALLOW,
     46             settings[0].setting);
     47   EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
     48                 GURL("http://allowed2.com")),
     49             settings[1].primary_pattern);
     50   EXPECT_EQ(CONTENT_SETTING_ALLOW,
     51             settings[1].setting);
     52   EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
     53                 GURL("http://denied.com")),
     54             settings[2].primary_pattern);
     55   EXPECT_EQ(CONTENT_SETTING_BLOCK,
     56             settings[2].setting);
     57   EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(
     58                 GURL("http://denied2.com")),
     59             settings[3].primary_pattern);
     60   EXPECT_EQ(CONTENT_SETTING_BLOCK,
     61             settings[3].setting);
     62   EXPECT_EQ(ContentSettingsPattern::Wildcard(),
     63             settings[4].primary_pattern);
     64   EXPECT_EQ(CONTENT_SETTING_ASK,
     65             settings[4].setting);
     66 }
     67