| Index: chrome/browser/notifications/desktop_notification_service_unittest.cc
|
| diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc
|
| index a9626e029e90dd086f93208d5633a15423ae5654..f99bf201dc9045ca696d079abad87044e72fc1e0 100644
|
| --- a/chrome/browser/notifications/desktop_notification_service_unittest.cc
|
| +++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc
|
| @@ -15,109 +15,16 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
|
|
|
| -using content::BrowserThread;
|
| -
|
| -namespace {
|
| -
|
| -// The HasPermission method of the DesktopNotificationService wants to be called
|
| -// on the IO thread. This class routes calls to the cache on the IO thread.
|
| -class ThreadProxy : public base::RefCountedThreadSafe<ThreadProxy> {
|
| - public:
|
| - ThreadProxy()
|
| - : io_event_(false, false),
|
| - ui_event_(false, false),
|
| - permission_(WebKit::WebNotificationPresenter::PermissionAllowed) {
|
| - // The current message loop was already initalized by the test superclass.
|
| - ui_thread_.reset(
|
| - new content::TestBrowserThread(BrowserThread::UI,
|
| - base::MessageLoop::current()));
|
| -
|
| - // Create IO thread, start its message loop.
|
| - io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
|
| - io_thread_->Start();
|
| -
|
| - // Calling PauseIOThread() here isn't safe, because the runnable method
|
| - // could complete before the constructor is done, deleting |this|.
|
| - }
|
| -
|
| - // Call the HasPermission method of the DesktopNotificationService on the IO
|
| - // thread and returns the permission setting.
|
| - WebKit::WebNotificationPresenter::Permission ServiceHasPermission(
|
| - DesktopNotificationService* service,
|
| - const GURL& url) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ThreadProxy::ServiceHasPermissionIO, this, service, url));
|
| - io_event_.Signal();
|
| - ui_event_.Wait(); // Wait for IO thread to be done.
|
| - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ThreadProxy::PauseIOThreadIO, this));
|
| -
|
| - return permission_;
|
| - }
|
| -
|
| - void PauseIOThread() {
|
| - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&ThreadProxy::PauseIOThreadIO, this));
|
| - }
|
| -
|
| - void DrainIOThread() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - io_event_.Signal();
|
| - io_thread_->Stop();
|
| - }
|
| -
|
| - private:
|
| - friend class base::RefCountedThreadSafe<ThreadProxy>;
|
| - ~ThreadProxy() {
|
| - DrainIOThread();
|
| - }
|
| -
|
| - void PauseIOThreadIO() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - io_event_.Wait();
|
| - }
|
| -
|
| - void ServiceHasPermissionIO(DesktopNotificationService* service,
|
| - const GURL& url) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - permission_ = service->HasPermission(url);
|
| - ui_event_.Signal();
|
| - }
|
| -
|
| - base::WaitableEvent io_event_;
|
| - base::WaitableEvent ui_event_;
|
| - scoped_ptr<content::TestBrowserThread> ui_thread_;
|
| - scoped_ptr<content::TestBrowserThread> io_thread_;
|
| -
|
| - WebKit::WebNotificationPresenter::Permission permission_;
|
| -};
|
| -
|
| -} // namespace
|
| -
|
| class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness {
|
| - public:
|
| - DesktopNotificationServiceTest() {
|
| - }
|
| -
|
| + protected:
|
| virtual void SetUp() {
|
| ChromeRenderViewHostTestHarness::SetUp();
|
| - proxy_ = new ThreadProxy;
|
| - proxy_->PauseIOThread();
|
|
|
| // Creates the destop notification service.
|
| service_ = DesktopNotificationServiceFactory::GetForProfile(profile());
|
| }
|
|
|
| - virtual void TearDown() {
|
| - // The io thread's waiting on the io_event_ might hold a ref to |proxy_|,
|
| - // preventing its destruction. Clear that ref.
|
| - proxy_->DrainIOThread();
|
| - ChromeRenderViewHostTestHarness::TearDown();
|
| - }
|
| -
|
| DesktopNotificationService* service_;
|
| - scoped_refptr<ThreadProxy> proxy_;
|
| };
|
|
|
| TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) {
|
| @@ -126,36 +33,36 @@ TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) {
|
| EXPECT_EQ(CONTENT_SETTING_ASK,
|
| service_->GetDefaultContentSetting(NULL));
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
|
| - proxy_->ServiceHasPermission(service_, url));
|
| + service_->HasPermission(url));
|
|
|
| service_->GrantPermission(url);
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
|
| - proxy_->ServiceHasPermission(service_, url));
|
| + service_->HasPermission(url));
|
|
|
| service_->DenyPermission(url);
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied,
|
| - proxy_->ServiceHasPermission(service_, url));
|
| + service_->HasPermission(url));
|
|
|
| GURL https_url("https://testurl");
|
| GURL http_url("http://testurl");
|
| EXPECT_EQ(CONTENT_SETTING_ASK,
|
| service_->GetDefaultContentSetting(NULL));
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
|
| - proxy_->ServiceHasPermission(service_, http_url));
|
| + service_->HasPermission(http_url));
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
|
| - proxy_->ServiceHasPermission(service_, https_url));
|
| + service_->HasPermission(https_url));
|
|
|
| service_->GrantPermission(https_url);
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
|
| - proxy_->ServiceHasPermission(service_, http_url));
|
| + service_->HasPermission(http_url));
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
|
| - proxy_->ServiceHasPermission(service_, https_url));
|
| + service_->HasPermission(https_url));
|
|
|
| service_->DenyPermission(http_url);
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied,
|
| - proxy_->ServiceHasPermission(service_, http_url));
|
| + service_->HasPermission(http_url));
|
| EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
|
| - proxy_->ServiceHasPermission(service_, https_url));
|
| + service_->HasPermission(https_url));
|
| }
|
|
|
| TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) {
|
|
|