| OLD | NEW |
| 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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/id_map.h" | 15 #include "base/id_map.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "base/test/simple_test_clock.h" | 18 #include "base/test/simple_test_clock.h" |
| 19 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 21 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 22 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 22 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 23 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
| 24 #include "chrome/browser/infobars/infobar_service.h" | 24 #include "chrome/browser/infobars/infobar_service.h" |
| 25 #include "chrome/browser/permissions/permission_infobar_manager.h" |
| 25 #include "chrome/browser/permissions/permission_request_id.h" | 26 #include "chrome/browser/permissions/permission_request_id.h" |
| 26 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" | 27 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" |
| 27 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 28 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 29 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 32 #include "components/content_settings/core/browser/host_content_settings_map.h" | 33 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 33 #include "components/infobars/core/confirm_infobar_delegate.h" | 34 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 34 #include "components/infobars/core/infobar.h" | 35 #include "components/infobars/core/infobar.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 232 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 232 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); | 233 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); |
| 233 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) | 234 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) |
| 234 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); | 235 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); |
| 235 | 236 |
| 236 // Set up required helpers, and make this be as "tabby" as the code requires. | 237 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 237 #if defined(ENABLE_EXTENSIONS) | 238 #if defined(ENABLE_EXTENSIONS) |
| 238 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 239 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
| 239 #endif | 240 #endif |
| 240 InfoBarService::CreateForWebContents(new_tab); | 241 InfoBarService::CreateForWebContents(new_tab); |
| 242 PermissionInfoBarManager::CreateForWebContents(new_tab); |
| 241 if (BubbleEnabled()) { | 243 if (BubbleEnabled()) { |
| 242 PermissionBubbleManager::CreateForWebContents(new_tab); | 244 PermissionBubbleManager::CreateForWebContents(new_tab); |
| 243 PermissionBubbleManager* permission_bubble_manager = | 245 PermissionBubbleManager* permission_bubble_manager = |
| 244 PermissionBubbleManager::FromWebContents(new_tab); | 246 PermissionBubbleManager::FromWebContents(new_tab); |
| 245 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false); | 247 MockPermissionBubbleView::SetFactory(permission_bubble_manager, false); |
| 246 permission_bubble_manager->DisplayPendingRequests(); | 248 permission_bubble_manager->DisplayPendingRequests(); |
| 247 } | 249 } |
| 248 | 250 |
| 249 extra_tabs_.push_back(new_tab); | 251 extra_tabs_.push_back(new_tab); |
| 250 } | 252 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 266 } | 268 } |
| 267 | 269 |
| 268 void GeolocationPermissionContextTests::SetUp() { | 270 void GeolocationPermissionContextTests::SetUp() { |
| 269 ChromeRenderViewHostTestHarness::SetUp(); | 271 ChromeRenderViewHostTestHarness::SetUp(); |
| 270 | 272 |
| 271 // Set up required helpers, and make this be as "tabby" as the code requires. | 273 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 272 #if defined(ENABLE_EXTENSIONS) | 274 #if defined(ENABLE_EXTENSIONS) |
| 273 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 275 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
| 274 #endif | 276 #endif |
| 275 InfoBarService::CreateForWebContents(web_contents()); | 277 InfoBarService::CreateForWebContents(web_contents()); |
| 278 PermissionInfoBarManager::CreateForWebContents(web_contents()); |
| 276 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 279 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 277 geolocation_permission_context_ = | 280 geolocation_permission_context_ = |
| 278 GeolocationPermissionContextFactory::GetForProfile(profile()); | 281 GeolocationPermissionContextFactory::GetForProfile(profile()); |
| 279 #if defined(OS_ANDROID) | 282 #if defined(OS_ANDROID) |
| 280 static_cast<GeolocationPermissionContextAndroid*>( | 283 static_cast<GeolocationPermissionContextAndroid*>( |
| 281 geolocation_permission_context_) | 284 geolocation_permission_context_) |
| 282 ->SetLocationSettingsForTesting( | 285 ->SetLocationSettingsForTesting( |
| 283 scoped_ptr<LocationSettings>(new MockLocationSettings())); | 286 scoped_ptr<LocationSettings>(new MockLocationSettings())); |
| 284 MockLocationSettings::SetLocationStatus(true, true); | 287 MockLocationSettings::SetLocationStatus(true, true); |
| 285 #endif | 288 #endif |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // Accept the permission in tab A0. | 691 // Accept the permission in tab A0. |
| 689 if (BubbleEnabled()) { | 692 if (BubbleEnabled()) { |
| 690 AcceptBubble(manager_a0); | 693 AcceptBubble(manager_a0); |
| 691 } else { | 694 } else { |
| 692 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); | 695 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); |
| 693 ConfirmInfoBarDelegate* infobar_delegate_a0 = | 696 ConfirmInfoBarDelegate* infobar_delegate_a0 = |
| 694 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); | 697 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); |
| 695 ASSERT_TRUE(infobar_delegate_a0); | 698 ASSERT_TRUE(infobar_delegate_a0); |
| 696 infobar_delegate_a0->Accept(); | 699 infobar_delegate_a0->Accept(); |
| 697 infobar_service()->RemoveInfoBar(infobar_a0); | 700 infobar_service()->RemoveInfoBar(infobar_a0); |
| 698 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 701 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 699 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); | 702 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); |
| 700 } | 703 } |
| 701 CheckPermissionMessageSent(0, true); | 704 CheckPermissionMessageSent(0, true); |
| 702 // Because they're the same origin, this will cause tab A1's infobar to | 705 // Because they're the same origin, tab_a1's bubble/infobar should disappear. |
| 703 // disappear. It does not cause the bubble to disappear: crbug.com/443013. | 706 // In the past, infobar used to disappear and bubble did not. |
| 704 // TODO(felt): Update this test when the bubble's behavior is changed. | 707 // Now both have a consistent behviour (albiet broken) of not removing |
| 708 // the bubble/infobar: see crbug.com/443013. |
| 709 // TODO(felt): Update this test when this behavior is changed. |
| 705 if (BubbleEnabled()) | 710 if (BubbleEnabled()) |
| 706 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); | 711 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 707 else | 712 else |
| 708 CheckPermissionMessageSentForTab(1, 0, true); | 713 EXPECT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
| 709 | 714 |
| 710 // Either way, tab B should still have a pending permission request. | 715 // Either way, tab B should still have a pending permission request. |
| 711 if (BubbleEnabled()) | 716 if (BubbleEnabled()) |
| 712 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); | 717 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); |
| 713 else | 718 else |
| 714 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 719 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 715 } | 720 } |
| 716 | 721 |
| 717 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 722 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| 718 GURL url_a("http://www.example.com/geolocation"); | 723 GURL url_a("http://www.example.com/geolocation"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 747 // Accept the first request in tab A1. | 752 // Accept the first request in tab A1. |
| 748 if (BubbleEnabled()) { | 753 if (BubbleEnabled()) { |
| 749 AcceptBubble(manager_a1); | 754 AcceptBubble(manager_a1); |
| 750 } else { | 755 } else { |
| 751 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); | 756 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); |
| 752 ConfirmInfoBarDelegate* infobar_delegate_a1 = | 757 ConfirmInfoBarDelegate* infobar_delegate_a1 = |
| 753 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); | 758 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); |
| 754 ASSERT_TRUE(infobar_delegate_a1); | 759 ASSERT_TRUE(infobar_delegate_a1); |
| 755 infobar_delegate_a1->Accept(); | 760 infobar_delegate_a1->Accept(); |
| 756 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); | 761 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); |
| 757 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 762 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 758 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); | 763 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); |
| 759 } | 764 } |
| 760 CheckPermissionMessageSentForTab(0, 0, true); | 765 CheckPermissionMessageSentForTab(0, 0, true); |
| 761 | 766 |
| 762 // Because they're the same origin, this will cause tab A0's infobar to | 767 // Because they're the same origin, tab_a0's bubble/infobar should disappear. |
| 763 // disappear. It does not cause the bubble to disappear: crbug.com/443013. | 768 // In the past, infobar used to disappear and bubble did not. |
| 764 // TODO(felt): Update this test when the bubble's behavior is changed. | 769 // Now both have a consistent behviour (albiet broken) of not removing |
| 765 if (BubbleEnabled()) { | 770 // the bubble/infobar: see crbug.com/443013. |
| 771 // TODO(felt): Update this test when this behavior is changed. |
| 772 if (BubbleEnabled()) |
| 766 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); | 773 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); |
| 767 } else { | 774 else |
| 768 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 775 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 769 CheckPermissionMessageSent(0, true); | |
| 770 } | |
| 771 | 776 |
| 772 // The second request should now be visible in tab A1. | 777 // The second request should now be visible in tab A1. |
| 773 if (BubbleEnabled()) | 778 if (BubbleEnabled()) |
| 774 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); | 779 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 775 else | 780 else |
| 776 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 781 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 777 | 782 |
| 778 // Accept the second request and check that it's gone. | 783 // Accept the second request and check that it's gone. |
| 779 if (BubbleEnabled()) { | 784 if (BubbleEnabled()) { |
| 780 AcceptBubble(manager_a1); | 785 AcceptBubble(manager_a1); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // it is the embedder. | 959 // it is the embedder. |
| 955 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 960 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 956 requesting_frame_0.GetOrigin(), | 961 requesting_frame_0.GetOrigin(), |
| 957 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 962 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 958 13); | 963 13); |
| 959 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 964 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 960 requesting_frame_0.GetOrigin(), | 965 requesting_frame_0.GetOrigin(), |
| 961 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 966 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 962 11); | 967 11); |
| 963 } | 968 } |
| OLD | NEW |