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. 4 5 #include "testing/gtest/include/gtest/gtest.h" 6 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 "url/gurl.h" 11 12 namespace content_settings { 13 14 TEST(ContentSettingsProviderTest, Mock) { 15 ContentSettingsPattern pattern = 16 ContentSettingsPattern::FromString("[*.]youtube.com"); 17 GURL url("http://www.youtube.com"); 18 19 MockProvider mock_provider(false); 20 mock_provider.SetWebsiteSetting( 21 pattern, 22 pattern, 23 CONTENT_SETTINGS_TYPE_PLUGINS, 24 "java_plugin", 25 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 26 27 28 EXPECT_EQ(CONTENT_SETTING_BLOCK, 29 GetContentSetting(&mock_provider, url, url, 30 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 31 false)); 32 scoped_ptr<Value> value_ptr( 33 GetContentSettingValue(&mock_provider, url, url, 34 CONTENT_SETTINGS_TYPE_PLUGINS, 35 "java_plugin", false)); 36 int int_value = -1; 37 value_ptr->GetAsInteger(&int_value); 38 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 39 40 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 41 GetContentSetting(&mock_provider, url, url, 42 CONTENT_SETTINGS_TYPE_PLUGINS, "flash_plugin", 43 false)); 44 EXPECT_EQ(NULL, 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, 50 url, 51 url, 52 CONTENT_SETTINGS_TYPE_GEOLOCATION, 53 std::string(), 54 false)); 55 EXPECT_EQ(NULL, 56 GetContentSettingValue(&mock_provider, 57 url, 58 url, 59 CONTENT_SETTINGS_TYPE_GEOLOCATION, 60 std::string(), 61 false)); 62 63 bool owned = mock_provider.SetWebsiteSetting( 64 pattern, 65 pattern, 66 CONTENT_SETTINGS_TYPE_PLUGINS, 67 "java_plugin", 68 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); 69 EXPECT_TRUE(owned); 70 EXPECT_EQ(CONTENT_SETTING_ALLOW, 71 GetContentSetting(&mock_provider, url, url, 72 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 73 false)); 74 75 mock_provider.set_read_only(true); 76 scoped_ptr<base::Value> value( 77 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 78 owned = mock_provider.SetWebsiteSetting( 79 pattern, 80 pattern, 81 CONTENT_SETTINGS_TYPE_PLUGINS, 82 "java_plugin", 83 value.get()); 84 EXPECT_FALSE(owned); 85 EXPECT_EQ(CONTENT_SETTING_ALLOW, 86 GetContentSetting(&mock_provider, url, url, 87 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 88 false)); 89 90 EXPECT_TRUE(mock_provider.read_only()); 91 92 mock_provider.set_read_only(false); 93 owned = mock_provider.SetWebsiteSetting( 94 pattern, 95 pattern, 96 CONTENT_SETTINGS_TYPE_PLUGINS, 97 "java_plugin", 98 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); 99 EXPECT_TRUE(owned); 100 EXPECT_EQ(CONTENT_SETTING_BLOCK, 101 GetContentSetting(&mock_provider, url, url, 102 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 103 false)); 104 } 105 106 } // namespace content_settings 107