| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 7 #include "chrome/browser/ui/webui/site_settings_helper.h" | 7 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "components/content_settings/core/browser/host_content_settings_map.h" | 9 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 10 #include "components/content_settings/core/test/content_settings_mock_provider.h
" | 10 #include "components/content_settings/core/test/content_settings_mock_provider.h
" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 nullptr /* filter */, &exceptions); | 60 nullptr /* filter */, &exceptions); |
| 61 EXPECT_EQ(0u, exceptions.GetSize()); | 61 EXPECT_EQ(0u, exceptions.GetSize()); |
| 62 | 62 |
| 63 map->SetDefaultContentSetting(kContentType, CONTENT_SETTING_ALLOW); | 63 map->SetDefaultContentSetting(kContentType, CONTENT_SETTING_ALLOW); |
| 64 | 64 |
| 65 // Add a policy exception. | 65 // Add a policy exception. |
| 66 auto policy_provider = base::MakeUnique<content_settings::MockProvider>(); | 66 auto policy_provider = base::MakeUnique<content_settings::MockProvider>(); |
| 67 policy_provider->SetWebsiteSetting( | 67 policy_provider->SetWebsiteSetting( |
| 68 ContentSettingsPattern::FromString("http://[*.]google.com"), | 68 ContentSettingsPattern::FromString("http://[*.]google.com"), |
| 69 ContentSettingsPattern::Wildcard(), kContentType, "", | 69 ContentSettingsPattern::Wildcard(), kContentType, "", |
| 70 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 70 new base::Value(CONTENT_SETTING_BLOCK)); |
| 71 policy_provider->set_read_only(true); | 71 policy_provider->set_read_only(true); |
| 72 content_settings::TestUtils::OverrideProvider( | 72 content_settings::TestUtils::OverrideProvider( |
| 73 map, std::move(policy_provider), HostContentSettingsMap::POLICY_PROVIDER); | 73 map, std::move(policy_provider), HostContentSettingsMap::POLICY_PROVIDER); |
| 74 | 74 |
| 75 // Add user preferences. | 75 // Add user preferences. |
| 76 AddSetting(map, "http://*", CONTENT_SETTING_BLOCK); | 76 AddSetting(map, "http://*", CONTENT_SETTING_BLOCK); |
| 77 AddSetting(map, "http://maps.google.com", CONTENT_SETTING_BLOCK); | 77 AddSetting(map, "http://maps.google.com", CONTENT_SETTING_BLOCK); |
| 78 AddSetting(map, "http://[*.]google.com", CONTENT_SETTING_ALLOW); | 78 AddSetting(map, "http://[*.]google.com", CONTENT_SETTING_ALLOW); |
| 79 | 79 |
| 80 // Add an extension exception. | 80 // Add an extension exception. |
| 81 auto extension_provider = base::MakeUnique<content_settings::MockProvider>(); | 81 auto extension_provider = base::MakeUnique<content_settings::MockProvider>(); |
| 82 extension_provider->SetWebsiteSetting( | 82 extension_provider->SetWebsiteSetting( |
| 83 ContentSettingsPattern::FromString("http://drive.google.com"), | 83 ContentSettingsPattern::FromString("http://drive.google.com"), |
| 84 ContentSettingsPattern::Wildcard(), kContentType, "", | 84 ContentSettingsPattern::Wildcard(), kContentType, "", |
| 85 new base::FundamentalValue(CONTENT_SETTING_ASK)); | 85 new base::Value(CONTENT_SETTING_ASK)); |
| 86 extension_provider->set_read_only(true); | 86 extension_provider->set_read_only(true); |
| 87 content_settings::TestUtils::OverrideProvider( | 87 content_settings::TestUtils::OverrideProvider( |
| 88 map, std::move(extension_provider), | 88 map, std::move(extension_provider), |
| 89 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER); | 89 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER); |
| 90 | 90 |
| 91 exceptions.Clear(); | 91 exceptions.Clear(); |
| 92 site_settings::GetExceptionsFromHostContentSettingsMap( | 92 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 93 map, kContentType, nullptr /* web_ui */, false /* incognito */, | 93 map, kContentType, nullptr /* web_ui */, false /* incognito */, |
| 94 nullptr /* filter */, &exceptions); | 94 nullptr /* filter */, &exceptions); |
| 95 | 95 |
| 96 EXPECT_EQ(5u, exceptions.GetSize()); | 96 EXPECT_EQ(5u, exceptions.GetSize()); |
| 97 | 97 |
| 98 // The policy exception should be returned first, the extension exception | 98 // The policy exception should be returned first, the extension exception |
| 99 // second and pref exceptions afterwards. | 99 // second and pref exceptions afterwards. |
| 100 // The default content setting should not be returned. | 100 // The default content setting should not be returned. |
| 101 int i = 0; | 101 int i = 0; |
| 102 // From policy provider: | 102 // From policy provider: |
| 103 VerifySetting(exceptions, i++, "http://[*.]google.com", "block"); | 103 VerifySetting(exceptions, i++, "http://[*.]google.com", "block"); |
| 104 // From extension provider: | 104 // From extension provider: |
| 105 VerifySetting(exceptions, i++, "http://drive.google.com", "ask"); | 105 VerifySetting(exceptions, i++, "http://drive.google.com", "ask"); |
| 106 // From user preferences: | 106 // From user preferences: |
| 107 VerifySetting(exceptions, i++, "http://maps.google.com", "block"); | 107 VerifySetting(exceptions, i++, "http://maps.google.com", "block"); |
| 108 VerifySetting(exceptions, i++, "http://[*.]google.com", "allow"); | 108 VerifySetting(exceptions, i++, "http://[*.]google.com", "allow"); |
| 109 VerifySetting(exceptions, i++, "http://*", "block"); | 109 VerifySetting(exceptions, i++, "http://*", "block"); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace site_settings | 112 } // namespace site_settings |
| OLD | NEW |