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