| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/content_settings/core/browser/content_settings_usages_state
.h" | 5 #include "components/content_settings/core/browser/content_settings_usages_state
.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 using content::BrowserThread; | 17 using content::BrowserThread; |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL( | 21 ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL( |
| 21 const GURL& url) { | 22 const GURL& url) { |
| 22 ContentSettingsUsagesState::CommittedDetails details; | 23 ContentSettingsUsagesState::CommittedDetails details; |
| 23 details.current_url_valid = true; | 24 details.current_url_valid = true; |
| 24 details.current_url = url; | 25 details.current_url = url; |
| 25 return details; | 26 return details; |
| 26 } | 27 } |
| 27 | 28 |
| 28 class ContentSettingsUsagesStateTests : public testing::Test { | 29 class ContentSettingsUsagesStateTests : public testing::Test { |
| 29 public: | 30 public: |
| 30 ContentSettingsUsagesStateTests() | 31 ContentSettingsUsagesStateTests() |
| 31 : ui_thread_(BrowserThread::UI, &message_loop_) { | 32 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 32 } | 33 } |
| 33 | 34 |
| 34 protected: | 35 protected: |
| 35 void ClearOnNewOrigin(ContentSettingsType type) { | 36 void ClearOnNewOrigin(ContentSettingsType type) { |
| 36 TestingProfile profile; | 37 TestingProfile profile; |
| 37 ContentSettingsUsagesState state(profile.GetHostContentSettingsMap(), type, | 38 ContentSettingsUsagesState state( |
| 38 prefs::kAcceptLanguages, | 39 HostContentSettingsMapFactory::GetForProfile(&profile), |
| 39 profile.GetPrefs()); | 40 type, |
| 41 prefs::kAcceptLanguages, |
| 42 profile.GetPrefs()); |
| 40 GURL url_0("http://www.example.com"); | 43 GURL url_0("http://www.example.com"); |
| 41 | 44 |
| 42 ContentSettingsUsagesState::CommittedDetails details = | 45 ContentSettingsUsagesState::CommittedDetails details = |
| 43 CreateDetailsWithURL(url_0); | 46 CreateDetailsWithURL(url_0); |
| 44 state.DidNavigate(details); | 47 state.DidNavigate(details); |
| 45 | 48 |
| 46 profile.GetHostContentSettingsMap()->SetContentSetting( | 49 HostContentSettingsMapFactory::GetForProfile(&profile)->SetContentSetting( |
| 47 ContentSettingsPattern::FromURLNoWildcard(url_0), | 50 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 48 ContentSettingsPattern::FromURLNoWildcard(url_0), | 51 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 49 type, | 52 type, |
| 50 std::string(), | 53 std::string(), |
| 51 CONTENT_SETTING_ALLOW); | 54 CONTENT_SETTING_ALLOW); |
| 52 state.OnPermissionSet(url_0, true); | 55 state.OnPermissionSet(url_0, true); |
| 53 | 56 |
| 54 GURL url_1("http://www.example1.com"); | 57 GURL url_1("http://www.example1.com"); |
| 55 profile.GetHostContentSettingsMap()->SetContentSetting( | 58 HostContentSettingsMapFactory::GetForProfile(&profile)->SetContentSetting( |
| 56 ContentSettingsPattern::FromURLNoWildcard(url_1), | 59 ContentSettingsPattern::FromURLNoWildcard(url_1), |
| 57 ContentSettingsPattern::FromURLNoWildcard(url_0), | 60 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 58 type, | 61 type, |
| 59 std::string(), | 62 std::string(), |
| 60 CONTENT_SETTING_BLOCK); | 63 CONTENT_SETTING_BLOCK); |
| 61 state.OnPermissionSet(url_1, false); | 64 state.OnPermissionSet(url_1, false); |
| 62 | 65 |
| 63 ContentSettingsUsagesState::StateMap state_map = | 66 ContentSettingsUsagesState::StateMap state_map = |
| 64 state.state_map(); | 67 state.state_map(); |
| 65 EXPECT_EQ(2U, state_map.size()); | 68 EXPECT_EQ(2U, state_map.size()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 134 |
| 132 formatted_host_per_state.clear(); | 135 formatted_host_per_state.clear(); |
| 133 tab_state_flags = 0; | 136 tab_state_flags = 0; |
| 134 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); | 137 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
| 135 EXPECT_TRUE(formatted_host_per_state.empty()); | 138 EXPECT_TRUE(formatted_host_per_state.empty()); |
| 136 EXPECT_EQ(0U, tab_state_flags); | 139 EXPECT_EQ(0U, tab_state_flags); |
| 137 } | 140 } |
| 138 | 141 |
| 139 void ShowPortOnSameHost(ContentSettingsType type) { | 142 void ShowPortOnSameHost(ContentSettingsType type) { |
| 140 TestingProfile profile; | 143 TestingProfile profile; |
| 141 ContentSettingsUsagesState state(profile.GetHostContentSettingsMap(), type, | 144 ContentSettingsUsagesState state( |
| 142 prefs::kAcceptLanguages, | 145 HostContentSettingsMapFactory::GetForProfile(&profile), |
| 143 profile.GetPrefs()); | 146 type, |
| 147 prefs::kAcceptLanguages, |
| 148 profile.GetPrefs()); |
| 144 GURL url_0("http://www.example.com"); | 149 GURL url_0("http://www.example.com"); |
| 145 | 150 |
| 146 ContentSettingsUsagesState::CommittedDetails details = | 151 ContentSettingsUsagesState::CommittedDetails details = |
| 147 CreateDetailsWithURL(url_0); | 152 CreateDetailsWithURL(url_0); |
| 148 state.DidNavigate(details); | 153 state.DidNavigate(details); |
| 149 | 154 |
| 150 profile.GetHostContentSettingsMap()->SetContentSetting( | 155 HostContentSettingsMapFactory::GetForProfile(&profile)->SetContentSetting( |
| 151 ContentSettingsPattern::FromURLNoWildcard(url_0), | 156 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 152 ContentSettingsPattern::FromURLNoWildcard(url_0), | 157 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 153 type, | 158 type, |
| 154 std::string(), | 159 std::string(), |
| 155 CONTENT_SETTING_ALLOW); | 160 CONTENT_SETTING_ALLOW); |
| 156 state.OnPermissionSet(url_0, true); | 161 state.OnPermissionSet(url_0, true); |
| 157 | 162 |
| 158 GURL url_1("https://www.example.com"); | 163 GURL url_1("https://www.example.com"); |
| 159 profile.GetHostContentSettingsMap()->SetContentSetting( | 164 HostContentSettingsMapFactory::GetForProfile(&profile)->SetContentSetting( |
| 160 ContentSettingsPattern::FromURLNoWildcard(url_1), | 165 ContentSettingsPattern::FromURLNoWildcard(url_1), |
| 161 ContentSettingsPattern::FromURLNoWildcard(url_0), | 166 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 162 type, | 167 type, |
| 163 std::string(), | 168 std::string(), |
| 164 CONTENT_SETTING_ALLOW); | 169 CONTENT_SETTING_ALLOW); |
| 165 state.OnPermissionSet(url_1, true); | 170 state.OnPermissionSet(url_1, true); |
| 166 | 171 |
| 167 GURL url_2("http://www.example1.com"); | 172 GURL url_2("http://www.example1.com"); |
| 168 profile.GetHostContentSettingsMap()->SetContentSetting( | 173 HostContentSettingsMapFactory::GetForProfile(&profile)->SetContentSetting( |
| 169 ContentSettingsPattern::FromURLNoWildcard(url_2), | 174 ContentSettingsPattern::FromURLNoWildcard(url_2), |
| 170 ContentSettingsPattern::FromURLNoWildcard(url_0), | 175 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 171 type, | 176 type, |
| 172 std::string(), | 177 std::string(), |
| 173 CONTENT_SETTING_ALLOW); | 178 CONTENT_SETTING_ALLOW); |
| 174 state.OnPermissionSet(url_2, true); | 179 state.OnPermissionSet(url_2, true); |
| 175 | 180 |
| 176 ContentSettingsUsagesState::StateMap state_map = | 181 ContentSettingsUsagesState::StateMap state_map = |
| 177 state.state_map(); | 182 state.state_map(); |
| 178 EXPECT_EQ(3U, state_map.size()); | 183 EXPECT_EQ(3U, state_map.size()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 230 |
| 226 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForGeolocation) { | 231 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForGeolocation) { |
| 227 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 232 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 228 } | 233 } |
| 229 | 234 |
| 230 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForMidi) { | 235 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForMidi) { |
| 231 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 236 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 232 } | 237 } |
| 233 | 238 |
| 234 } // namespace | 239 } // namespace |
| OLD | NEW |