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"
10 #include "googleurl/src/gurl.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 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
<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
, url
, url
,
50 CONTENT_SETTINGS_TYPE_GEOLOCATION
, "", false));
52 GetContentSettingValue(&mock_provider
, url
, url
,
53 CONTENT_SETTINGS_TYPE_GEOLOCATION
, "",
56 bool owned
= mock_provider
.SetWebsiteSetting(
59 CONTENT_SETTINGS_TYPE_PLUGINS
,
61 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW
));
63 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
64 GetContentSetting(&mock_provider
, url
, url
,
65 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
68 mock_provider
.set_read_only(true);
69 scoped_ptr
<base::Value
> value(
70 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK
));
71 owned
= mock_provider
.SetWebsiteSetting(
74 CONTENT_SETTINGS_TYPE_PLUGINS
,
78 EXPECT_EQ(CONTENT_SETTING_ALLOW
,
79 GetContentSetting(&mock_provider
, url
, url
,
80 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
83 EXPECT_TRUE(mock_provider
.read_only());
85 mock_provider
.set_read_only(false);
86 owned
= mock_provider
.SetWebsiteSetting(
89 CONTENT_SETTINGS_TYPE_PLUGINS
,
91 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK
));
93 EXPECT_EQ(CONTENT_SETTING_BLOCK
,
94 GetContentSetting(&mock_provider
, url
, url
,
95 CONTENT_SETTINGS_TYPE_PLUGINS
, "java_plugin",
99 } // namespace content_settings