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

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

Issue 7484072: Migrate geolocation settings to host content settings map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 #include <string>
6 7
7 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
10 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
11 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
12 #include "chrome/browser/tab_contents/infobar.h" 13 #include "chrome/browser/tab_contents/infobar.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 15 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/browser/browser_thread.h" 17 #include "content/browser/browser_thread.h"
17 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " 18 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h "
18 #include "content/browser/geolocation/location_arbitrator.h" 19 #include "content/browser/geolocation/location_arbitrator.h"
19 #include "content/browser/geolocation/location_provider.h" 20 #include "content/browser/geolocation/location_provider.h"
20 #include "content/browser/geolocation/mock_location_provider.h" 21 #include "content/browser/geolocation/mock_location_provider.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 contents_wrapper()->RemoveInfoBar(infobar_0); 221 contents_wrapper()->RemoveInfoBar(infobar_0);
221 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 222 EXPECT_EQ(1U, closed_delegate_tracker_.size());
222 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 223 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
223 infobar_0->InfoBarClosed(); 224 infobar_0->InfoBarClosed();
224 } 225 }
225 226
226 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 227 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
227 GURL requesting_frame_0("http://www.example.com/geolocation"); 228 GURL requesting_frame_0("http://www.example.com/geolocation");
228 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 229 GURL requesting_frame_1("http://www.example-2.com/geolocation");
229 EXPECT_EQ(CONTENT_SETTING_ASK, 230 EXPECT_EQ(CONTENT_SETTING_ASK,
230 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 231 profile()->GetHostContentSettingsMap()->GetContentSetting(
231 requesting_frame_0, requesting_frame_0)); 232 requesting_frame_0,
233 requesting_frame_0,
234 CONTENT_SETTINGS_TYPE_GEOLOCATION,
235 std::string()));
232 EXPECT_EQ(CONTENT_SETTING_ASK, 236 EXPECT_EQ(CONTENT_SETTING_ASK,
233 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 237 profile()->GetHostContentSettingsMap()->GetContentSetting(
234 requesting_frame_1, requesting_frame_0)); 238 requesting_frame_1,
239 requesting_frame_0,
240 CONTENT_SETTINGS_TYPE_GEOLOCATION,
241 std::string()));
242
235 243
236 NavigateAndCommit(requesting_frame_0); 244 NavigateAndCommit(requesting_frame_0);
237 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 245 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
238 // Request permission for two frames. 246 // Request permission for two frames.
239 geolocation_permission_context_->RequestGeolocationPermission( 247 geolocation_permission_context_->RequestGeolocationPermission(
240 process_id(), render_id(), bridge_id(), requesting_frame_0); 248 process_id(), render_id(), bridge_id(), requesting_frame_0);
241 geolocation_permission_context_->RequestGeolocationPermission( 249 geolocation_permission_context_->RequestGeolocationPermission(
242 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 250 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
243 // Ensure only one infobar is created. 251 // Ensure only one infobar is created.
244 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); 252 ASSERT_EQ(1U, contents_wrapper()->infobar_count());
(...skipping 25 matching lines...) Expand all
270 infobar_1->Cancel(); 278 infobar_1->Cancel();
271 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 279 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
272 CheckPermissionMessageSent(bridge_id() + 1, false); 280 CheckPermissionMessageSent(bridge_id() + 1, false);
273 contents_wrapper()->RemoveInfoBar(infobar_1); 281 contents_wrapper()->RemoveInfoBar(infobar_1);
274 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 282 EXPECT_EQ(1U, closed_delegate_tracker_.size());
275 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 283 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
276 infobar_1->InfoBarClosed(); 284 infobar_1->InfoBarClosed();
277 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 285 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
278 // Ensure the persisted permissions are ok. 286 // Ensure the persisted permissions are ok.
279 EXPECT_EQ(CONTENT_SETTING_ALLOW, 287 EXPECT_EQ(CONTENT_SETTING_ALLOW,
280 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 288 profile()->GetHostContentSettingsMap()->GetContentSetting(
281 requesting_frame_0, requesting_frame_0)); 289 requesting_frame_0,
290 requesting_frame_0,
291 CONTENT_SETTINGS_TYPE_GEOLOCATION,
292 std::string()));
293
282 EXPECT_EQ(CONTENT_SETTING_BLOCK, 294 EXPECT_EQ(CONTENT_SETTING_BLOCK,
283 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 295 profile()->GetHostContentSettingsMap()->GetContentSetting(
284 requesting_frame_1, requesting_frame_0)); 296 requesting_frame_1,
297 requesting_frame_0,
298 CONTENT_SETTINGS_TYPE_GEOLOCATION,
299 std::string()));
285 } 300 }
286 301
287 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 302 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
288 GURL requesting_frame_0("http://www.example.com/geolocation"); 303 GURL requesting_frame_0("http://www.example.com/geolocation");
289 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 304 GURL requesting_frame_1("http://www.example-2.com/geolocation");
290 EXPECT_EQ(CONTENT_SETTING_ASK, 305 EXPECT_EQ(CONTENT_SETTING_ASK,
291 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 306 profile()->GetHostContentSettingsMap()->GetContentSetting(
292 requesting_frame_0, requesting_frame_0)); 307 requesting_frame_0,
308 requesting_frame_0,
309 CONTENT_SETTINGS_TYPE_GEOLOCATION,
310 std::string()));
311
293 EXPECT_EQ(CONTENT_SETTING_ASK, 312 EXPECT_EQ(CONTENT_SETTING_ASK,
294 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 313 profile()->GetHostContentSettingsMap()->GetContentSetting(
295 requesting_frame_1, requesting_frame_0)); 314 requesting_frame_1,
315 requesting_frame_0,
316 CONTENT_SETTINGS_TYPE_GEOLOCATION,
317 std::string()));
318
296 319
297 NavigateAndCommit(requesting_frame_0); 320 NavigateAndCommit(requesting_frame_0);
298 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 321 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
299 // Request permission for two frames. 322 // Request permission for two frames.
300 geolocation_permission_context_->RequestGeolocationPermission( 323 geolocation_permission_context_->RequestGeolocationPermission(
301 process_id(), render_id(), bridge_id(), requesting_frame_0); 324 process_id(), render_id(), bridge_id(), requesting_frame_0);
302 geolocation_permission_context_->RequestGeolocationPermission( 325 geolocation_permission_context_->RequestGeolocationPermission(
303 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 326 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
304 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); 327 ASSERT_EQ(1U, contents_wrapper()->infobar_count());
305 328
(...skipping 22 matching lines...) Expand all
328 infobar_1->Accept(); 351 infobar_1->Accept();
329 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 352 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
330 CheckPermissionMessageSent(bridge_id() + 1, true); 353 CheckPermissionMessageSent(bridge_id() + 1, true);
331 contents_wrapper()->RemoveInfoBar(infobar_1); 354 contents_wrapper()->RemoveInfoBar(infobar_1);
332 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 355 EXPECT_EQ(1U, closed_delegate_tracker_.size());
333 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 356 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
334 infobar_1->InfoBarClosed(); 357 infobar_1->InfoBarClosed();
335 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 358 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
336 // Ensure the persisted permissions are ok. 359 // Ensure the persisted permissions are ok.
337 EXPECT_EQ(CONTENT_SETTING_ASK, 360 EXPECT_EQ(CONTENT_SETTING_ASK,
338 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 361 profile()->GetHostContentSettingsMap()->GetContentSetting(
339 requesting_frame_0, requesting_frame_0)); 362 requesting_frame_0,
363 requesting_frame_0,
364 CONTENT_SETTINGS_TYPE_GEOLOCATION,
365 std::string()));
366
340 EXPECT_EQ(CONTENT_SETTING_ALLOW, 367 EXPECT_EQ(CONTENT_SETTING_ALLOW,
341 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 368 profile()->GetHostContentSettingsMap()->GetContentSetting(
342 requesting_frame_1, requesting_frame_0)); 369 requesting_frame_1,
370 requesting_frame_0,
371 CONTENT_SETTINGS_TYPE_GEOLOCATION,
372 std::string()));
343 } 373 }
344 374
345 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 375 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
346 GURL invalid_embedder; 376 GURL invalid_embedder;
347 GURL requesting_frame("about:blank"); 377 GURL requesting_frame("about:blank");
348 NavigateAndCommit(invalid_embedder); 378 NavigateAndCommit(invalid_embedder);
349 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 379 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
350 geolocation_permission_context_->RequestGeolocationPermission( 380 geolocation_permission_context_->RequestGeolocationPermission(
351 process_id(), render_id(), bridge_id(), requesting_frame); 381 process_id(), render_id(), bridge_id(), requesting_frame);
352 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 382 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 infobar_1->InfoBarClosed(); 492 infobar_1->InfoBarClosed();
463 493
464 extra_tabs_.reset(); 494 extra_tabs_.reset();
465 } 495 }
466 496
467 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 497 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
468 GURL requesting_frame_0("http://www.example.com/geolocation"); 498 GURL requesting_frame_0("http://www.example.com/geolocation");
469 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 499 GURL requesting_frame_1("http://www.example-2.com/geolocation");
470 EXPECT_EQ( 500 EXPECT_EQ(
471 CONTENT_SETTING_ASK, 501 CONTENT_SETTING_ASK,
472 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 502 profile()->GetHostContentSettingsMap()->GetContentSetting(
473 requesting_frame_0, requesting_frame_0)); 503 requesting_frame_0,
504 requesting_frame_0,
505 CONTENT_SETTINGS_TYPE_GEOLOCATION,
506 std::string()));
507
474 EXPECT_EQ( 508 EXPECT_EQ(
475 CONTENT_SETTING_ASK, 509 CONTENT_SETTING_ASK,
476 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( 510 profile()->GetHostContentSettingsMap()->GetContentSetting(
477 requesting_frame_1, requesting_frame_0)); 511 requesting_frame_1,
512 requesting_frame_0,
513 CONTENT_SETTINGS_TYPE_GEOLOCATION,
514 std::string()));
478 515
479 NavigateAndCommit(requesting_frame_0); 516 NavigateAndCommit(requesting_frame_0);
480 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); 517 EXPECT_EQ(0U, contents_wrapper()->infobar_count());
481 // Request permission for two frames. 518 // Request permission for two frames.
482 geolocation_permission_context_->RequestGeolocationPermission( 519 geolocation_permission_context_->RequestGeolocationPermission(
483 process_id(), render_id(), bridge_id(), requesting_frame_0); 520 process_id(), render_id(), bridge_id(), requesting_frame_0);
484 geolocation_permission_context_->RequestGeolocationPermission( 521 geolocation_permission_context_->RequestGeolocationPermission(
485 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 522 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
486 // Ensure only one infobar is created. 523 // Ensure only one infobar is created.
487 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); 524 ASSERT_EQ(1U, contents_wrapper()->infobar_count());
488 ConfirmInfoBarDelegate* infobar_0 = 525 ConfirmInfoBarDelegate* infobar_0 =
489 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 526 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
490 ASSERT_TRUE(infobar_0); 527 ASSERT_TRUE(infobar_0);
491 528
492 // Delete the tab contents. 529 // Delete the tab contents.
493 DeleteContents(); 530 DeleteContents();
494 infobar_0->InfoBarClosed(); 531 infobar_0->InfoBarClosed();
495 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698