1 // Copyright (c) 2010 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 "chrome/browser/content_settings/content_settings_mock_provider.h" 8 #include "googleurl/src/gurl.h" 9 10 namespace content_settings { 11 12 TEST(ContentSettingsProviderTest, Mock) { 13 MockDefaultProvider provider(CONTENT_SETTINGS_TYPE_COOKIES, 14 CONTENT_SETTING_ALLOW, 15 false, 16 true); 17 EXPECT_EQ(CONTENT_SETTING_ALLOW, 18 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 19 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 20 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS)); 21 EXPECT_FALSE(provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); 22 EXPECT_FALSE(provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_POPUPS)); 23 provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, 24 CONTENT_SETTING_BLOCK); 25 EXPECT_EQ(CONTENT_SETTING_BLOCK, 26 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 27 28 ContentSettingsPattern pattern("[*.]youtube.com"); 29 GURL url("http://www.youtube.com"); 30 31 MockProvider mock_provider( 32 pattern, 33 pattern, 34 CONTENT_SETTINGS_TYPE_PLUGINS, 35 "java_plugin", 36 CONTENT_SETTING_BLOCK, 37 false, 38 false); 39 40 EXPECT_EQ(CONTENT_SETTING_BLOCK, mock_provider.GetContentSetting( 41 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin")); 42 EXPECT_EQ(CONTENT_SETTING_DEFAULT, mock_provider.GetContentSetting( 43 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "flash_plugin")); 44 EXPECT_EQ(CONTENT_SETTING_DEFAULT, mock_provider.GetContentSetting( 45 url, url, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 46 47 mock_provider.SetContentSetting( 48 pattern, 49 pattern, 50 CONTENT_SETTINGS_TYPE_PLUGINS, 51 "java_plugin", 52 CONTENT_SETTING_ALLOW); 53 EXPECT_EQ(CONTENT_SETTING_ALLOW, mock_provider.GetContentSetting( 54 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin")); 55 56 mock_provider.set_read_only(true); 57 mock_provider.SetContentSetting( 58 pattern, 59 pattern, 60 CONTENT_SETTINGS_TYPE_PLUGINS, 61 "java_plugin", 62 CONTENT_SETTING_BLOCK); 63 EXPECT_EQ(CONTENT_SETTING_ALLOW, mock_provider.GetContentSetting( 64 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin")); 65 66 EXPECT_TRUE(mock_provider.read_only()); 67 mock_provider.set_setting(CONTENT_SETTING_BLOCK); 68 EXPECT_EQ(CONTENT_SETTING_BLOCK, mock_provider.GetContentSetting( 69 url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin")); 70 } 71 72 } // namespace content_settings 73