| OLD | NEW |
| 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/geolocation_content_settings_map.h" | 5 #include <string> |
| 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 #include "chrome/browser/geolocation/geolocation_settings_state.h" | 8 #include "chrome/browser/geolocation/geolocation_settings_state.h" |
| 7 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 8 #include "chrome/test/testing_browser_process_test.h" | 10 #include "chrome/test/testing_browser_process_test.h" |
| 9 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/tab_contents/navigation_details.h" | 12 #include "content/browser/tab_contents/navigation_details.h" |
| 11 #include "content/browser/tab_contents/navigation_entry.h" | 13 #include "content/browser/tab_contents/navigation_entry.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 class GeolocationSettingsStateTests : public TestingBrowserProcessTest { | 18 class GeolocationSettingsStateTests : public TestingBrowserProcessTest { |
| 17 public: | 19 public: |
| 18 GeolocationSettingsStateTests() | 20 GeolocationSettingsStateTests() |
| 19 : ui_thread_(BrowserThread::UI, &message_loop_) { | 21 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 protected: | 24 protected: |
| 23 MessageLoop message_loop_; | 25 MessageLoop message_loop_; |
| 24 BrowserThread ui_thread_; | 26 BrowserThread ui_thread_; |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) { | 29 TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) { |
| 28 TestingProfile profile; | 30 TestingProfile profile; |
| 29 GeolocationSettingsState state(&profile); | 31 GeolocationSettingsState state(&profile); |
| 30 GURL url_0("http://www.example.com"); | 32 GURL url_0("http://www.example.com"); |
| 31 | 33 |
| 32 NavigationEntry entry; | 34 NavigationEntry entry; |
| 33 entry.set_url(url_0); | 35 entry.set_url(url_0); |
| 34 content::LoadCommittedDetails load_committed_details; | 36 content::LoadCommittedDetails load_committed_details; |
| 35 load_committed_details.entry = &entry; | 37 load_committed_details.entry = &entry; |
| 36 state.DidNavigate(load_committed_details); | 38 state.DidNavigate(load_committed_details); |
| 37 | 39 |
| 38 profile.GetGeolocationContentSettingsMap()->SetContentSetting( | 40 profile.GetHostContentSettingsMap()->SetContentSetting( |
| 39 url_0, url_0, CONTENT_SETTING_ALLOW); | 41 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 42 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 43 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 44 std::string(), |
| 45 CONTENT_SETTING_ALLOW); |
| 40 state.OnGeolocationPermissionSet(url_0, true); | 46 state.OnGeolocationPermissionSet(url_0, true); |
| 41 | 47 |
| 42 GURL url_1("http://www.example1.com"); | 48 GURL url_1("http://www.example1.com"); |
| 43 profile.GetGeolocationContentSettingsMap()->SetContentSetting( | 49 profile.GetHostContentSettingsMap()->SetContentSetting( |
| 44 url_1, url_0, CONTENT_SETTING_BLOCK); | 50 ContentSettingsPattern::FromURLNoWildcard(url_1), |
| 51 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 52 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 53 std::string(), |
| 54 CONTENT_SETTING_BLOCK); |
| 45 state.OnGeolocationPermissionSet(url_1, false); | 55 state.OnGeolocationPermissionSet(url_1, false); |
| 46 | 56 |
| 47 GeolocationSettingsState::StateMap state_map = | 57 GeolocationSettingsState::StateMap state_map = |
| 48 state.state_map(); | 58 state.state_map(); |
| 49 EXPECT_EQ(2U, state_map.size()); | 59 EXPECT_EQ(2U, state_map.size()); |
| 50 | 60 |
| 51 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; | 61 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; |
| 52 unsigned int tab_state_flags = 0; | 62 unsigned int tab_state_flags = 0; |
| 53 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); | 63 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
| 54 EXPECT_TRUE(tab_state_flags & | 64 EXPECT_TRUE(tab_state_flags & |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 TestingProfile profile; | 135 TestingProfile profile; |
| 126 GeolocationSettingsState state(&profile); | 136 GeolocationSettingsState state(&profile); |
| 127 GURL url_0("http://www.example.com"); | 137 GURL url_0("http://www.example.com"); |
| 128 | 138 |
| 129 NavigationEntry entry; | 139 NavigationEntry entry; |
| 130 entry.set_url(url_0); | 140 entry.set_url(url_0); |
| 131 content::LoadCommittedDetails load_committed_details; | 141 content::LoadCommittedDetails load_committed_details; |
| 132 load_committed_details.entry = &entry; | 142 load_committed_details.entry = &entry; |
| 133 state.DidNavigate(load_committed_details); | 143 state.DidNavigate(load_committed_details); |
| 134 | 144 |
| 135 profile.GetGeolocationContentSettingsMap()->SetContentSetting( | 145 profile.GetHostContentSettingsMap()->SetContentSetting( |
| 136 url_0, url_0, CONTENT_SETTING_ALLOW); | 146 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 147 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 148 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 149 std::string(), |
| 150 CONTENT_SETTING_ALLOW); |
| 137 state.OnGeolocationPermissionSet(url_0, true); | 151 state.OnGeolocationPermissionSet(url_0, true); |
| 138 | 152 |
| 139 GURL url_1("https://www.example.com"); | 153 GURL url_1("https://www.example.com"); |
| 140 profile.GetGeolocationContentSettingsMap()->SetContentSetting( | 154 profile.GetHostContentSettingsMap()->SetContentSetting( |
| 141 url_1, url_0, CONTENT_SETTING_ALLOW); | 155 ContentSettingsPattern::FromURLNoWildcard(url_1), |
| 156 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 157 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 158 std::string(), |
| 159 CONTENT_SETTING_ALLOW); |
| 142 state.OnGeolocationPermissionSet(url_1, true); | 160 state.OnGeolocationPermissionSet(url_1, true); |
| 143 | 161 |
| 144 GURL url_2("http://www.example1.com"); | 162 GURL url_2("http://www.example1.com"); |
| 145 profile.GetGeolocationContentSettingsMap()->SetContentSetting( | 163 profile.GetHostContentSettingsMap()->SetContentSetting( |
| 146 url_2, url_0, CONTENT_SETTING_ALLOW); | 164 ContentSettingsPattern::FromURLNoWildcard(url_2), |
| 165 ContentSettingsPattern::FromURLNoWildcard(url_0), |
| 166 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 167 std::string(), |
| 168 CONTENT_SETTING_ALLOW); |
| 147 state.OnGeolocationPermissionSet(url_2, true); | 169 state.OnGeolocationPermissionSet(url_2, true); |
| 148 | 170 |
| 149 GeolocationSettingsState::StateMap state_map = | 171 GeolocationSettingsState::StateMap state_map = |
| 150 state.state_map(); | 172 state.state_map(); |
| 151 EXPECT_EQ(3U, state_map.size()); | 173 EXPECT_EQ(3U, state_map.size()); |
| 152 | 174 |
| 153 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; | 175 GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state; |
| 154 unsigned int tab_state_flags = 0; | 176 unsigned int tab_state_flags = 0; |
| 155 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); | 177 state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags); |
| 156 | 178 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( | 200 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 179 url_2.host())); | 201 url_2.host())); |
| 180 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); | 202 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); |
| 181 EXPECT_EQ(1U, | 203 EXPECT_EQ(1U, |
| 182 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( | 204 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( |
| 183 url_1.spec())); | 205 url_1.spec())); |
| 184 } | 206 } |
| 185 | 207 |
| 186 | 208 |
| 187 } // namespace | 209 } // namespace |
| OLD | NEW |