blob: d3bbf7db44b0b9b61362a706391ee2ff39611f4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/notifications/notifications_prefs_cache.h"
#include "base/message_loop.h"
#include "chrome/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
TEST(NotificationsPrefsCacheTest, CanCreate) {
scoped_refptr<NotificationsPrefsCache> cache(new NotificationsPrefsCache());
std::vector<GURL> allowed_origins;
allowed_origins.push_back(GURL("http://allowed.com"));
std::vector<GURL> denied_origins;
denied_origins.push_back(GURL("http://denied.com"));
{
MessageLoop loop;
BrowserThread ui_thread(BrowserThread::UI, &loop);
cache->SetCacheAllowedOrigins(allowed_origins);
cache->SetCacheDeniedOrigins(denied_origins);
cache->SetCacheDefaultContentSetting(CONTENT_SETTING_DEFAULT);
}
cache->set_is_initialized(true);
{
MessageLoop loop;
BrowserThread io_thread(BrowserThread::IO, &loop);
cache->CacheAllowedOrigin(GURL("http://allowed2.com"));
cache->CacheDeniedOrigin(GURL("http://denied2.com"));
EXPECT_EQ(cache->HasPermission(GURL("http://allowed.com")),
WebKit::WebNotificationPresenter::PermissionAllowed);
EXPECT_EQ(cache->HasPermission(GURL("http://allowed2.com")),
WebKit::WebNotificationPresenter::PermissionAllowed);
EXPECT_EQ(cache->HasPermission(GURL("http://denied.com")),
WebKit::WebNotificationPresenter::PermissionDenied);
EXPECT_EQ(cache->HasPermission(GURL("http://denied2.com")),
WebKit::WebNotificationPresenter::PermissionDenied);
EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
WebKit::WebNotificationPresenter::PermissionNotAllowed);
cache->SetCacheDefaultContentSetting(CONTENT_SETTING_ASK);
EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
WebKit::WebNotificationPresenter::PermissionNotAllowed);
cache->SetCacheDefaultContentSetting(CONTENT_SETTING_ALLOW);
EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
WebKit::WebNotificationPresenter::PermissionAllowed);
cache->SetCacheDefaultContentSetting(CONTENT_SETTING_BLOCK);
EXPECT_EQ(cache->HasPermission(GURL("http://unkown.com")),
WebKit::WebNotificationPresenter::PermissionDenied);
}
}
|