OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
11 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 11 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
13 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
14 #include "content/browser/renderer_host/test_render_view_host.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresen
ter.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresen
ter.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // The HasPermission method of the DesktopNotificationService wants to be called | 20 // The HasPermission method of the DesktopNotificationService wants to be called |
21 // on the IO thread. This class routes calls to the cache on the IO thread. | 21 // on the IO thread. This class routes calls to the cache on the IO thread. |
22 class ThreadProxy : public base::RefCountedThreadSafe<ThreadProxy> { | 22 class ThreadProxy : public base::RefCountedThreadSafe<ThreadProxy> { |
23 public: | 23 public: |
24 ThreadProxy() | 24 ThreadProxy() |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 base::WaitableEvent io_event_; | 86 base::WaitableEvent io_event_; |
87 base::WaitableEvent ui_event_; | 87 base::WaitableEvent ui_event_; |
88 scoped_ptr<BrowserThread> ui_thread_; | 88 scoped_ptr<BrowserThread> ui_thread_; |
89 scoped_ptr<BrowserThread> io_thread_; | 89 scoped_ptr<BrowserThread> io_thread_; |
90 | 90 |
91 WebKit::WebNotificationPresenter::Permission permission_; | 91 WebKit::WebNotificationPresenter::Permission permission_; |
92 }; | 92 }; |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 class DesktopNotificationServiceTest : public RenderViewHostTestHarness { | 96 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { |
97 public: | 97 public: |
98 DesktopNotificationServiceTest() { | 98 DesktopNotificationServiceTest() { |
99 } | 99 } |
100 | 100 |
101 virtual void SetUp() { | 101 virtual void SetUp() { |
102 RenderViewHostTestHarness::SetUp(); | 102 ChromeRenderViewHostTestHarness::SetUp(); |
103 proxy_ = new ThreadProxy; | 103 proxy_ = new ThreadProxy; |
104 proxy_->PauseIOThread(); | 104 proxy_->PauseIOThread(); |
105 | 105 |
106 // Creates the destop notification service. | 106 // Creates the destop notification service. |
107 service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); | 107 service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); |
108 } | 108 } |
109 | 109 |
110 virtual void TearDown() { | 110 virtual void TearDown() { |
111 // The io thread's waiting on the io_event_ might hold a ref to |proxy_|, | 111 // The io thread's waiting on the io_event_ might hold a ref to |proxy_|, |
112 // preventing its destruction. Clear that ref. | 112 // preventing its destruction. Clear that ref. |
113 proxy_->DrainIOThread(); | 113 proxy_->DrainIOThread(); |
114 RenderViewHostTestHarness::TearDown(); | 114 ChromeRenderViewHostTestHarness::TearDown(); |
115 } | 115 } |
116 | 116 |
117 DesktopNotificationService* service_; | 117 DesktopNotificationService* service_; |
118 scoped_refptr<ThreadProxy> proxy_; | 118 scoped_refptr<ThreadProxy> proxy_; |
119 }; | 119 }; |
120 | 120 |
121 TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) { | 121 TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) { |
122 GURL url("file:///html/test.html"); | 122 GURL url("file:///html/test.html"); |
123 | 123 |
124 EXPECT_EQ(CONTENT_SETTING_ASK, | 124 EXPECT_EQ(CONTENT_SETTING_ASK, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 GURL("http://denied.com")), | 180 GURL("http://denied.com")), |
181 settings[2].a); | 181 settings[2].a); |
182 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 182 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
183 settings[2].c); | 183 settings[2].c); |
184 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 184 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
185 GURL("http://denied2.com")), | 185 GURL("http://denied2.com")), |
186 settings[3].a); | 186 settings[3].a); |
187 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 187 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
188 settings[3].c); | 188 settings[3].c); |
189 } | 189 } |
OLD | NEW |