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

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

Issue 23440030: GeolocationPermissionContext: only use origin from embedder url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test, some cleanup. Created 7 years, 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 profile()->GetHostContentSettingsMap()->GetContentSetting( 389 profile()->GetHostContentSettingsMap()->GetContentSetting(
390 requesting_frame_0, requesting_frame_0, 390 requesting_frame_0, requesting_frame_0,
391 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 391 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
392 392
393 EXPECT_EQ(CONTENT_SETTING_BLOCK, 393 EXPECT_EQ(CONTENT_SETTING_BLOCK,
394 profile()->GetHostContentSettingsMap()->GetContentSetting( 394 profile()->GetHostContentSettingsMap()->GetContentSetting(
395 requesting_frame_1, requesting_frame_0, 395 requesting_frame_1, requesting_frame_0,
396 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 396 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
397 } 397 }
398 398
399 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
400 GURL url_a("http://www.example.com/geolocation#a");
401 GURL url_b("http://www.example.com/geolocation#b");
402
403 // Navigate to the first url and check permission is requested.
404 NavigateAndCommit(url_a);
405 EXPECT_EQ(0U, infobar_service()->infobar_count());
406 RequestGeolocationPermission(RequestID(0), url_a);
407 ASSERT_EQ(1U, infobar_service()->infobar_count());
408 ConfirmInfoBarDelegate* infobar_delegate =
409 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate();
410 ASSERT_TRUE(infobar_delegate);
411
412 // Change the hash, we'll still be on the same page.
413 NavigateAndCommit(url_b);
414
415 // Accept.
416 infobar_delegate->Accept();
417 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
418 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
419 CheckPermissionMessageSent(0, true);
420
421 // Cleanup.
422 infobar_service()->RemoveInfoBar(infobar_delegate);
423 EXPECT_EQ(1U, closed_infobar_tracker_.size());
424 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate));
425 closed_infobar_tracker_.Clear();
426 delete infobar_delegate;
427 }
428
399 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 429 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
400 GURL requesting_frame("file://example/geolocation.html"); 430 GURL requesting_frame("file://example/geolocation.html");
401 NavigateAndCommit(requesting_frame); 431 NavigateAndCommit(requesting_frame);
402 EXPECT_EQ(0U, infobar_service()->infobar_count()); 432 EXPECT_EQ(0U, infobar_service()->infobar_count());
403 RequestGeolocationPermission(RequestID(0), requesting_frame); 433 RequestGeolocationPermission(RequestID(0), requesting_frame);
404 EXPECT_EQ(1U, infobar_service()->infobar_count()); 434 EXPECT_EQ(1U, infobar_service()->infobar_count());
405 ConfirmInfoBarDelegate* infobar_delegate = 435 ConfirmInfoBarDelegate* infobar_delegate =
406 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); 436 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate();
407 ASSERT_TRUE(infobar_delegate); 437 ASSERT_TRUE(infobar_delegate);
408 // Accept the frame. 438 // Accept the frame.
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 674 details.entry = web_contents()->GetController().GetLastCommittedEntry();
645 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); 675 EXPECT_FALSE(infobar_delegate->ShouldExpire(details));
646 // Ensure the infobar will expire when we commit the pending navigation. 676 // Ensure the infobar will expire when we commit the pending navigation.
647 details.entry = web_contents()->GetController().GetActiveEntry(); 677 details.entry = web_contents()->GetController().GetActiveEntry();
648 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); 678 EXPECT_TRUE(infobar_delegate->ShouldExpire(details));
649 679
650 // Delete the tab contents. 680 // Delete the tab contents.
651 DeleteContents(); 681 DeleteContents();
652 delete infobar_delegate; 682 delete infobar_delegate;
653 } 683 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698