Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc

Issue 1033004: Adds GeolocationContentSettingsMap. (Closed)
Patch Set: Uses "RequestingOriginSettings" and allows empty embedder as a wildcard. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
6
7 #include "chrome/test/testing_profile.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10
11 namespace {
12
13 class GeolocationContentSettingsMapTests : public testing::Test {
14 public:
15 GeolocationContentSettingsMapTests()
16 : ui_thread_(ChromeThread::UI, &message_loop_) {
Peter Kasting 2010/03/18 20:59:20 Nit: This still needs to be indented 4 rather than
17 }
18
19 protected:
20 MessageLoop message_loop_;
21 ChromeThread ui_thread_;
22 };
23
24 TEST_F(GeolocationContentSettingsMapTests, DefaultValues) {
25 TestingProfile profile;
26 GeolocationContentSettingsMap* geolocation_content_settings_map =
27 profile.GetGeolocationContentSettingsMap();
28
29 // Check setting defaults.
30 EXPECT_EQ(CONTENT_SETTING_ASK,
31 geolocation_content_settings_map->GetDefaultContentSetting());
32 geolocation_content_settings_map->SetDefaultContentSetting(
33 CONTENT_SETTING_BLOCK);
34 EXPECT_EQ(CONTENT_SETTING_BLOCK,
35 geolocation_content_settings_map->GetDefaultContentSetting());
36 }
37
38 TEST_F(GeolocationContentSettingsMapTests, Embedder) {
39 TestingProfile profile;
40 GeolocationContentSettingsMap* geolocation_content_settings_map =
41 profile.GetGeolocationContentSettingsMap();
42 GURL embedder_0("http://www.toplevel0.com/foo/bar");
43 GURL origin_0(embedder_0);
44 EXPECT_EQ(CONTENT_SETTING_ASK,
45 geolocation_content_settings_map->GetContentSetting(
46 embedder_0, origin_0));
47 // Now set the permission for origin_0.
48 geolocation_content_settings_map->SetContentSetting(
49 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
50 EXPECT_EQ(CONTENT_SETTING_ALLOW,
51 geolocation_content_settings_map->GetContentSetting(
52 embedder_0, origin_0));
53
54 GURL origin_1("http://www.frame0.com/foo/bar");
55 EXPECT_EQ(CONTENT_SETTING_ASK,
56 geolocation_content_settings_map->GetContentSetting(
57 embedder_0, origin_1));
58 // Now set the permission for only the origin_1.
59 geolocation_content_settings_map->SetContentSetting(
60 embedder_0, origin_1, CONTENT_SETTING_ALLOW);
61 EXPECT_EQ(CONTENT_SETTING_ALLOW,
62 geolocation_content_settings_map->GetContentSetting(
63 embedder_0, origin_0));
64 EXPECT_EQ(CONTENT_SETTING_ALLOW,
65 geolocation_content_settings_map->GetContentSetting(
66 embedder_0, origin_1));
67 // Block only origin_1.
68 geolocation_content_settings_map->SetContentSetting(
69 embedder_0, origin_1, CONTENT_SETTING_BLOCK);
70 EXPECT_EQ(CONTENT_SETTING_BLOCK,
71 geolocation_content_settings_map->GetContentSetting(
72 embedder_0, origin_1));
73 EXPECT_EQ(CONTENT_SETTING_ALLOW,
74 geolocation_content_settings_map->GetContentSetting(
75 embedder_0, origin_0));
76 }
77
78 TEST_F(GeolocationContentSettingsMapTests, MultipleEmbeddersAndOrigins) {
79 TestingProfile profile;
80 GeolocationContentSettingsMap* geolocation_content_settings_map =
81 profile.GetGeolocationContentSettingsMap();
82 GURL embedder_0("http://www.toplevel0.com/foo/bar");
83 GURL origin_0("http://www.iframe0.com/foo/bar");
84 GURL origin_1("http://www.iframe1.co.uk/bar/foo");
85 EXPECT_EQ(CONTENT_SETTING_ASK,
86 geolocation_content_settings_map->GetContentSetting(
87 embedder_0, origin_0));
88 EXPECT_EQ(CONTENT_SETTING_ASK,
89 geolocation_content_settings_map->GetContentSetting(
90 embedder_0, origin_1));
91 // Now set the permission for only one origin.
92 geolocation_content_settings_map->SetContentSetting(
93 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
94 EXPECT_EQ(CONTENT_SETTING_ALLOW,
95 geolocation_content_settings_map->GetContentSetting(
96 embedder_0, origin_0));
97 EXPECT_EQ(CONTENT_SETTING_ASK,
98 geolocation_content_settings_map->GetContentSetting(
99 embedder_0, origin_1));
100 // Set the permission for the other origin.
101 geolocation_content_settings_map->SetContentSetting(
102 embedder_0, origin_1, CONTENT_SETTING_ALLOW);
103 EXPECT_EQ(CONTENT_SETTING_ALLOW,
104 geolocation_content_settings_map->GetContentSetting(
105 embedder_0, origin_1));
106 // Check they're not allowed on a different embedder.
107 GURL embedder_1("http://www.toplevel1.com/foo/bar");
108 EXPECT_EQ(CONTENT_SETTING_ASK,
109 geolocation_content_settings_map->GetContentSetting(
110 embedder_1, origin_0));
111 EXPECT_EQ(CONTENT_SETTING_ASK,
112 geolocation_content_settings_map->GetContentSetting(
113 embedder_1, origin_1));
114 // Check all settings are valid.
115 GeolocationContentSettingsMap::RequestingOriginSettings
116 requesting_origin_settings =
117 geolocation_content_settings_map->requesting_origin_settings();
118 EXPECT_EQ(0U, requesting_origin_settings.count(origin_0));
119 EXPECT_EQ(1U, requesting_origin_settings.count(origin_0.GetOrigin()));
120 GeolocationContentSettingsMap::EmbedderSettings embedder_settings =
121 requesting_origin_settings[origin_0.GetOrigin()];
122 EXPECT_EQ(CONTENT_SETTING_ALLOW,
123 embedder_settings[embedder_0.GetOrigin()]);
124
125 EXPECT_EQ(0U, requesting_origin_settings.count(origin_1));
126 EXPECT_EQ(1U, requesting_origin_settings.count(origin_1.GetOrigin()));
127 embedder_settings =
128 requesting_origin_settings[origin_1.GetOrigin()];
129 EXPECT_EQ(CONTENT_SETTING_ALLOW, embedder_settings[embedder_0.GetOrigin()]);
130 // Block origin_1 on the first embedder and add it to the second.
131 geolocation_content_settings_map->SetContentSetting(
132 embedder_0, origin_1, CONTENT_SETTING_BLOCK);
133 geolocation_content_settings_map->SetContentSetting(
134 embedder_1, origin_1, CONTENT_SETTING_ALLOW);
135 EXPECT_EQ(CONTENT_SETTING_BLOCK,
136 geolocation_content_settings_map->GetContentSetting(embedder_0,
137 origin_1));
138 EXPECT_EQ(CONTENT_SETTING_ALLOW,
139 geolocation_content_settings_map->GetContentSetting(embedder_1,
140 origin_1));
141 }
142
143 TEST_F(GeolocationContentSettingsMapTests, SetContentSettingDefault) {
144 TestingProfile profile;
145 GeolocationContentSettingsMap* geolocation_content_settings_map =
146 profile.GetGeolocationContentSettingsMap();
147 GURL embedder_0("http://www.toplevel0.com/foo/bar");
148 GURL origin_0(embedder_0);
149 geolocation_content_settings_map->SetContentSetting(
150 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
151 EXPECT_EQ(CONTENT_SETTING_ALLOW,
152 geolocation_content_settings_map->GetContentSetting(
153 embedder_0, origin_0));
154 // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed.
155 geolocation_content_settings_map->SetContentSetting(
156 embedder_0, origin_0, CONTENT_SETTING_DEFAULT);
157 EXPECT_EQ(CONTENT_SETTING_ASK,
158 geolocation_content_settings_map->GetContentSetting(
159 embedder_0, origin_0));
160 }
161
162 TEST_F(GeolocationContentSettingsMapTests, Reset) {
163 TestingProfile profile;
164 GeolocationContentSettingsMap* geolocation_content_settings_map =
165 profile.GetGeolocationContentSettingsMap();
166 GURL embedder_0("http://www.toplevel0.com/foo/bar");
167 GURL origin_0("http://www.iframe0.com/foo/bar");
168 geolocation_content_settings_map->SetContentSetting(
169 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
170 EXPECT_EQ(CONTENT_SETTING_ALLOW,
171 geolocation_content_settings_map->GetContentSetting(
172 embedder_0, origin_0));
173 GeolocationContentSettingsMap::RequestingOriginSettings
174 requesting_origin_settings =
175 geolocation_content_settings_map->requesting_origin_settings();
176 EXPECT_EQ(1U, requesting_origin_settings.size());
177
178 // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed.
179 geolocation_content_settings_map->SetContentSetting(
180 embedder_0, origin_0, CONTENT_SETTING_DEFAULT);
181 EXPECT_EQ(CONTENT_SETTING_ASK,
182 geolocation_content_settings_map->GetContentSetting(
183 embedder_0, origin_0));
184 requesting_origin_settings =
185 geolocation_content_settings_map->requesting_origin_settings();
186 EXPECT_TRUE(requesting_origin_settings.empty());
187 }
188
189 TEST_F(GeolocationContentSettingsMapTests, ClearsWhenSettingBackToDefault) {
190 TestingProfile profile;
191 GeolocationContentSettingsMap* geolocation_content_settings_map =
192 profile.GetGeolocationContentSettingsMap();
193 GURL embedder_0("http://www.toplevel0.com/foo/bar");
194 GURL origin_0("http://www.iframe0.com/foo/bar");
195 GURL origin_1("http://www.iframe1.com/foo/bar");
196 geolocation_content_settings_map->SetContentSetting(
197 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
198 EXPECT_EQ(CONTENT_SETTING_ALLOW,
199 geolocation_content_settings_map->GetContentSetting(
200 embedder_0, origin_0));
201 GeolocationContentSettingsMap::RequestingOriginSettings
202 requesting_origin_settings =
203 geolocation_content_settings_map->requesting_origin_settings();
204 EXPECT_EQ(1U, requesting_origin_settings.size());
205
206 geolocation_content_settings_map->SetContentSetting(
207 embedder_0, origin_1, CONTENT_SETTING_ALLOW);
208 EXPECT_EQ(CONTENT_SETTING_ALLOW,
209 geolocation_content_settings_map->GetContentSetting(
210 embedder_0, origin_1));
211 requesting_origin_settings =
212 geolocation_content_settings_map->requesting_origin_settings();
213 EXPECT_EQ(2U, requesting_origin_settings.size());
214 EXPECT_EQ(1U, requesting_origin_settings[origin_0.GetOrigin()].size());
215 EXPECT_EQ(1U, requesting_origin_settings[origin_1.GetOrigin()].size());
216
217 // Set to default.
218 geolocation_content_settings_map->SetContentSetting(
219 embedder_0, origin_0, CONTENT_SETTING_DEFAULT);
220 requesting_origin_settings =
221 geolocation_content_settings_map->requesting_origin_settings();
222 EXPECT_EQ(1U, requesting_origin_settings.size());
223
224 geolocation_content_settings_map->SetContentSetting(
225 embedder_0, origin_1, CONTENT_SETTING_DEFAULT);
226 requesting_origin_settings =
227 geolocation_content_settings_map->requesting_origin_settings();
228 EXPECT_TRUE(requesting_origin_settings.empty());
229 }
230
231 TEST_F(GeolocationContentSettingsMapTests, WildCardForEmptyEmbedder) {
232 TestingProfile profile;
233 GeolocationContentSettingsMap* geolocation_content_settings_map =
234 profile.GetGeolocationContentSettingsMap();
235 GURL empty_embedder;
236 GURL embedder_0("http://www.toplevel0.com/foo/bar");
237 GURL other_embedder("http://www.toplevel1.com/foo/bar");
238 GURL origin_0("http://www.iframe0.com/foo/bar");
239 geolocation_content_settings_map->SetContentSetting(
240 embedder_0, origin_0, CONTENT_SETTING_BLOCK);
241 geolocation_content_settings_map->SetContentSetting(
242 empty_embedder, origin_0, CONTENT_SETTING_ALLOW);
243 EXPECT_EQ(CONTENT_SETTING_BLOCK,
244 geolocation_content_settings_map->GetContentSetting(
245 embedder_0, origin_0));
246 EXPECT_EQ(CONTENT_SETTING_ALLOW,
247 geolocation_content_settings_map->GetContentSetting(
248 empty_embedder, origin_0));
249 EXPECT_EQ(CONTENT_SETTING_ALLOW,
250 geolocation_content_settings_map->GetContentSetting(
251 other_embedder, origin_0));
252
253 // Change the wildcard behavior.
254 geolocation_content_settings_map->SetContentSetting(
255 embedder_0, origin_0, CONTENT_SETTING_ALLOW);
256 geolocation_content_settings_map->SetContentSetting(
257 empty_embedder, origin_0, CONTENT_SETTING_BLOCK);
258 EXPECT_EQ(CONTENT_SETTING_ALLOW,
259 geolocation_content_settings_map->GetContentSetting(
260 embedder_0, origin_0));
261 EXPECT_EQ(CONTENT_SETTING_BLOCK,
262 geolocation_content_settings_map->GetContentSetting(
263 empty_embedder, origin_0));
264 EXPECT_EQ(CONTENT_SETTING_BLOCK,
265 geolocation_content_settings_map->GetContentSetting(
266 other_embedder, origin_0));
267 }
268
269 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698