• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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/notifications_prefs_cache.h"
6 
7 #include "base/message_loop.h"
8 #include "content/browser/browser_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
11 
TEST(NotificationsPrefsCacheTest,CanCreate)12 TEST(NotificationsPrefsCacheTest, CanCreate) {
13   scoped_refptr<NotificationsPrefsCache> cache(new NotificationsPrefsCache());
14   std::vector<GURL> allowed_origins;
15   allowed_origins.push_back(GURL("http://allowed.com"));
16   std::vector<GURL> denied_origins;
17   denied_origins.push_back(GURL("http://denied.com"));
18 
19   {
20     MessageLoop loop;
21     BrowserThread ui_thread(BrowserThread::UI, &loop);
22 
23     cache->SetCacheAllowedOrigins(allowed_origins);
24     cache->SetCacheDeniedOrigins(denied_origins);
25     cache->SetCacheDefaultContentSetting(CONTENT_SETTING_DEFAULT);
26   }
27 
28   cache->set_is_initialized(true);
29 
30   {
31     MessageLoop loop;
32     BrowserThread io_thread(BrowserThread::IO, &loop);
33 
34     cache->CacheAllowedOrigin(GURL("http://allowed2.com"));
35     cache->CacheDeniedOrigin(GURL("http://denied2.com"));
36 
37     EXPECT_EQ(cache->HasPermission(GURL("http://allowed.com")),
38               WebKit::WebNotificationPresenter::PermissionAllowed);
39     EXPECT_EQ(cache->HasPermission(GURL("http://allowed2.com")),
40               WebKit::WebNotificationPresenter::PermissionAllowed);
41 
42     EXPECT_EQ(cache->HasPermission(GURL("http://denied.com")),
43               WebKit::WebNotificationPresenter::PermissionDenied);
44     EXPECT_EQ(cache->HasPermission(GURL("http://denied2.com")),
45               WebKit::WebNotificationPresenter::PermissionDenied);
46 
47     EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
48               WebKit::WebNotificationPresenter::PermissionNotAllowed);
49 
50     cache->SetCacheDefaultContentSetting(CONTENT_SETTING_ASK);
51     EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
52               WebKit::WebNotificationPresenter::PermissionNotAllowed);
53 
54     cache->SetCacheDefaultContentSetting(CONTENT_SETTING_ALLOW);
55     EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
56               WebKit::WebNotificationPresenter::PermissionAllowed);
57 
58     cache->SetCacheDefaultContentSetting(CONTENT_SETTING_BLOCK);
59     EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
60               WebKit::WebNotificationPresenter::PermissionDenied);
61   }
62 }
63 
64