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 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK
));
28 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
29 GetContentSetting(&mock_provider
, url
, url
,
30 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
32 scoped_ptr
<base::Value
> value_ptr(
33 GetContentSettingValue(&mock_provider
, url
, url
,
34 CONTENT_SETTINGS_TYPE_PLUGINS
,
35 "java_plugin", false));
37 value_ptr
->GetAsInteger(&int_value
);
38 EXPECT_EQ(CONTENT_SETTING_BLOCK
, IntToContentSetting(int_value
));
40 EXPECT_EQ(CONTENT_SETTING_DEFAULT
,
41 GetContentSetting(&mock_provider
, url
, url
,
42 CONTENT_SETTINGS_TYPE_PLUGINS
, "flash_plugin",
45 GetContentSettingValue(&mock_provider
, url
, url
,
46 CONTENT_SETTINGS_TYPE_PLUGINS
,
47 "flash_plugin", false));
48 EXPECT_EQ(CONTENT_SETTING_DEFAULT
,
49 GetContentSetting(&mock_provider
,
52 CONTENT_SETTINGS_TYPE_GEOLOCATION
,
56 GetContentSettingValue(&mock_provider
,
59 CONTENT_SETTINGS_TYPE_GEOLOCATION
,
63 bool owned
= mock_provider
.SetWebsiteSetting(
66 CONTENT_SETTINGS_TYPE_PLUGINS
,
68 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW
));
70 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
71 GetContentSetting(&mock_provider
, url
, url
,
72 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
75 mock_provider
.set_read_only(true);
76 scoped_ptr
<base::Value
> value(
77 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK
));
78 owned
= mock_provider
.SetWebsiteSetting(
81 CONTENT_SETTINGS_TYPE_PLUGINS
,
85 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
86 GetContentSetting(&mock_provider
, url
, url
,
87 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
90 EXPECT_TRUE(mock_provider
.read_only());
92 mock_provider
.set_read_only(false);
93 owned
= mock_provider
.SetWebsiteSetting(
96 CONTENT_SETTINGS_TYPE_PLUGINS
,
98 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK
));
100 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
101 GetContentSetting(&mock_provider
, url
, url
,
102 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
106 } // namespace content_settings