| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "components/content_settings/core/common/content_settings_pattern.h" | 7 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 8 #include "components/content_settings/core/test/content_settings_mock_provider.h
" | 8 #include "components/content_settings/core/test/content_settings_mock_provider.h
" |
| 9 #include "components/content_settings/core/test/content_settings_test_utils.h" | 9 #include "components/content_settings/core/test/content_settings_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace content_settings { | 13 namespace content_settings { |
| 14 | 14 |
| 15 TEST(ContentSettingsProviderTest, Mock) { | 15 TEST(ContentSettingsProviderTest, Mock) { |
| 16 ContentSettingsPattern pattern = | 16 ContentSettingsPattern pattern = |
| 17 ContentSettingsPattern::FromString("[*.]youtube.com"); | 17 ContentSettingsPattern::FromString("[*.]youtube.com"); |
| 18 GURL url("http://www.youtube.com"); | 18 GURL url("http://www.youtube.com"); |
| 19 | 19 |
| 20 MockProvider mock_provider(false); | 20 MockProvider mock_provider(false); |
| 21 mock_provider.SetWebsiteSetting( | 21 mock_provider.SetWebsiteSetting( |
| 22 pattern, | 22 pattern, |
| 23 pattern, | 23 pattern, |
| 24 CONTENT_SETTINGS_TYPE_PLUGINS, | 24 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 25 "java_plugin", | 25 "java_plugin", |
| 26 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 26 new base::Value(CONTENT_SETTING_BLOCK)); |
| 27 | 27 |
| 28 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 28 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 29 TestUtils::GetContentSetting(&mock_provider, url, url, | 29 TestUtils::GetContentSetting(&mock_provider, url, url, |
| 30 CONTENT_SETTINGS_TYPE_PLUGINS, | 30 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 31 "java_plugin", false)); | 31 "java_plugin", false)); |
| 32 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( | 32 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( |
| 33 &mock_provider, url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", | 33 &mock_provider, url, url, CONTENT_SETTINGS_TYPE_PLUGINS, "java_plugin", |
| 34 false)); | 34 false)); |
| 35 int int_value = -1; | 35 int int_value = -1; |
| 36 value_ptr->GetAsInteger(&int_value); | 36 value_ptr->GetAsInteger(&int_value); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 std::string(), false)); | 49 std::string(), false)); |
| 50 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( | 50 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
| 51 &mock_provider, url, url, | 51 &mock_provider, url, url, |
| 52 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false)); | 52 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false)); |
| 53 | 53 |
| 54 bool owned = mock_provider.SetWebsiteSetting( | 54 bool owned = mock_provider.SetWebsiteSetting( |
| 55 pattern, | 55 pattern, |
| 56 pattern, | 56 pattern, |
| 57 CONTENT_SETTINGS_TYPE_PLUGINS, | 57 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 58 "java_plugin", | 58 "java_plugin", |
| 59 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 59 new base::Value(CONTENT_SETTING_ALLOW)); |
| 60 EXPECT_TRUE(owned); | 60 EXPECT_TRUE(owned); |
| 61 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 61 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 62 TestUtils::GetContentSetting(&mock_provider, url, url, | 62 TestUtils::GetContentSetting(&mock_provider, url, url, |
| 63 CONTENT_SETTINGS_TYPE_PLUGINS, | 63 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 64 "java_plugin", false)); | 64 "java_plugin", false)); |
| 65 | 65 |
| 66 mock_provider.set_read_only(true); | 66 mock_provider.set_read_only(true); |
| 67 std::unique_ptr<base::Value> value( | 67 std::unique_ptr<base::Value> value( |
| 68 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 68 new base::Value(CONTENT_SETTING_BLOCK)); |
| 69 owned = mock_provider.SetWebsiteSetting( | 69 owned = mock_provider.SetWebsiteSetting( |
| 70 pattern, | 70 pattern, |
| 71 pattern, | 71 pattern, |
| 72 CONTENT_SETTINGS_TYPE_PLUGINS, | 72 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 73 "java_plugin", | 73 "java_plugin", |
| 74 value.get()); | 74 value.get()); |
| 75 EXPECT_FALSE(owned); | 75 EXPECT_FALSE(owned); |
| 76 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 76 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 77 TestUtils::GetContentSetting(&mock_provider, url, url, | 77 TestUtils::GetContentSetting(&mock_provider, url, url, |
| 78 CONTENT_SETTINGS_TYPE_PLUGINS, | 78 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 79 "java_plugin", false)); | 79 "java_plugin", false)); |
| 80 | 80 |
| 81 EXPECT_TRUE(mock_provider.read_only()); | 81 EXPECT_TRUE(mock_provider.read_only()); |
| 82 | 82 |
| 83 mock_provider.set_read_only(false); | 83 mock_provider.set_read_only(false); |
| 84 owned = mock_provider.SetWebsiteSetting( | 84 owned = mock_provider.SetWebsiteSetting( |
| 85 pattern, | 85 pattern, |
| 86 pattern, | 86 pattern, |
| 87 CONTENT_SETTINGS_TYPE_PLUGINS, | 87 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 88 "java_plugin", | 88 "java_plugin", |
| 89 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 89 new base::Value(CONTENT_SETTING_BLOCK)); |
| 90 EXPECT_TRUE(owned); | 90 EXPECT_TRUE(owned); |
| 91 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 91 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 92 TestUtils::GetContentSetting(&mock_provider, url, url, | 92 TestUtils::GetContentSetting(&mock_provider, url, url, |
| 93 CONTENT_SETTINGS_TYPE_PLUGINS, | 93 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 94 "java_plugin", false)); | 94 "java_plugin", false)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace content_settings | 97 } // namespace content_settings |
| OLD | NEW |