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 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 26 27 EXPECT_EQ(CONTENT_SETTING_BLOCK, 28 GetContentSetting(&mock_provider, url, url, 29 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 30 false)); 31 scoped_ptr<base::Value> value_ptr( 32 GetContentSettingValue(&mock_provider, url, url, 33 CONTENT_SETTINGS_TYPE_PLUGINS, 34 "java_plugin", false)); 35 int int_value = -1; 36 value_ptr->GetAsInteger(&int_value); 37 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 38 39 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 40 GetContentSetting(&mock_provider, url, url, 41 CONTENT_SETTINGS_TYPE_PLUGINS, "flash_plugin", 42 false)); 43 EXPECT_EQ(NULL, 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, 49 url, 50 url, 51 CONTENT_SETTINGS_TYPE_GEOLOCATION, 52 std::string(), 53 false)); 54 EXPECT_EQ(NULL, 55 GetContentSettingValue(&mock_provider, 56 url, 57 url, 58 CONTENT_SETTINGS_TYPE_GEOLOCATION, 59 std::string(), 60 false)); 61 62 bool owned = mock_provider.SetWebsiteSetting( 63 pattern, 64 pattern, 65 CONTENT_SETTINGS_TYPE_PLUGINS, 66 "java_plugin", 67 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 68 EXPECT_TRUE(owned); 69 EXPECT_EQ(CONTENT_SETTING_ALLOW, 70 GetContentSetting(&mock_provider, url, url, 71 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 72 false)); 73 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( 78 pattern, 79 pattern, 80 CONTENT_SETTINGS_TYPE_PLUGINS, 81 "java_plugin", 82 value.get()); 83 EXPECT_FALSE(owned); 84 EXPECT_EQ(CONTENT_SETTING_ALLOW, 85 GetContentSetting(&mock_provider, url, url, 86 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 87 false)); 88 89 EXPECT_TRUE(mock_provider.read_only()); 90 91 mock_provider.set_read_only(false); 92 owned = mock_provider.SetWebsiteSetting( 93 pattern, 94 pattern, 95 CONTENT_SETTINGS_TYPE_PLUGINS, 96 "java_plugin", 97 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 98 EXPECT_TRUE(owned); 99 EXPECT_EQ(CONTENT_SETTING_BLOCK, 100 GetContentSetting(&mock_provider, url, url, 101 CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", 102 false)); 103 } 104 105 } // namespace content_settings 106