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.
5 #include "testing/gtest/include/gtest/gtest.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/content_settings/content_settings_mock_provider.h"
9 #include "chrome/browser/content_settings/content_settings_utils.h"
12 namespace content_settings
{
14 TEST(ContentSettingsProviderTest
, Mock
) {
15 ContentSettingsPattern pattern
=
16 ContentSettingsPattern::FromString("[*.]youtube.com");
17 GURL
url("http://www.youtube.com");
19 MockProvider
mock_provider(false);
20 mock_provider
.SetWebsiteSetting(
23 CONTENT_SETTINGS_TYPE_PLUGINS
,
25 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
27 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
28 GetContentSetting(&mock_provider
, url
, url
,
29 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
31 scoped_ptr
<base::Value
> value_ptr(
32 GetContentSettingValue(&mock_provider
, url
, url
,
33 CONTENT_SETTINGS_TYPE_PLUGINS
,
34 "java_plugin", false));
36 value_ptr
->GetAsInteger(&int_value
);
37 EXPECT_EQ(CONTENT_SETTING_BLOCK
, IntToContentSetting(int_value
));
39 EXPECT_EQ(CONTENT_SETTING_DEFAULT
,
40 GetContentSetting(&mock_provider
, url
, url
,
41 CONTENT_SETTINGS_TYPE_PLUGINS
, "flash_plugin",
44 GetContentSettingValue(&mock_provider
, url
, url
,
45 CONTENT_SETTINGS_TYPE_PLUGINS
,
46 "flash_plugin", false));
47 EXPECT_EQ(CONTENT_SETTING_DEFAULT
,
48 GetContentSetting(&mock_provider
,
51 CONTENT_SETTINGS_TYPE_GEOLOCATION
,
55 GetContentSettingValue(&mock_provider
,
58 CONTENT_SETTINGS_TYPE_GEOLOCATION
,
62 bool owned
= mock_provider
.SetWebsiteSetting(
65 CONTENT_SETTINGS_TYPE_PLUGINS
,
67 new base::FundamentalValue(CONTENT_SETTING_ALLOW
));
69 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
70 GetContentSetting(&mock_provider
, url
, url
,
71 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
74 mock_provider
.set_read_only(true);
75 scoped_ptr
<base::Value
> value(
76 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
77 owned
= mock_provider
.SetWebsiteSetting(
80 CONTENT_SETTINGS_TYPE_PLUGINS
,
84 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
85 GetContentSetting(&mock_provider
, url
, url
,
86 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
89 EXPECT_TRUE(mock_provider
.read_only());
91 mock_provider
.set_read_only(false);
92 owned
= mock_provider
.SetWebsiteSetting(
95 CONTENT_SETTINGS_TYPE_PLUGINS
,
97 new base::FundamentalValue(CONTENT_SETTING_BLOCK
));
99 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
100 GetContentSetting(&mock_provider
, url
, url
,
101 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
105 } // namespace content_settings