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