| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/permissions/permission_manager.h" | 5 #include "chrome/browser/permissions/permission_manager.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/permissions/permission_manager_factory.h" | 10 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 11 #include "chrome/browser/permissions/permission_request_manager.h" |
| 11 #include "chrome/browser/permissions/permission_result.h" | 12 #include "chrome/browser/permissions/permission_result.h" |
| 13 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "content/public/browser/permission_type.h" | 17 #include "content/public/browser/permission_type.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "device/vr/features/features.h" | 19 #include "device/vr/features/features.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 21 |
| 20 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) | 22 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 21 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | 23 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return callback_called_; | 100 return callback_called_; |
| 99 } | 101 } |
| 100 | 102 |
| 101 PermissionStatus callback_result() const { return callback_result_; } | 103 PermissionStatus callback_result() const { return callback_result_; } |
| 102 | 104 |
| 103 void Reset() { | 105 void Reset() { |
| 104 callback_called_ = false; | 106 callback_called_ = false; |
| 105 callback_result_ = PermissionStatus::ASK; | 107 callback_result_ = PermissionStatus::ASK; |
| 106 } | 108 } |
| 107 | 109 |
| 110 bool PendingRequestsEmpty() { |
| 111 return GetPermissionManager()->pending_requests_.IsEmpty(); |
| 112 } |
| 113 |
| 108 private: | 114 private: |
| 109 void SetUp() override { | 115 void SetUp() override { |
| 110 ChromeRenderViewHostTestHarness::SetUp(); | 116 ChromeRenderViewHostTestHarness::SetUp(); |
| 111 profile_.reset(new PermissionManagerTestingProfile()); | 117 profile_.reset(new PermissionManagerTestingProfile()); |
| 112 } | 118 } |
| 113 | 119 |
| 114 void TearDown() override { | 120 void TearDown() override { |
| 115 profile_.reset(); | 121 profile_.reset(); |
| 116 ChromeRenderViewHostTestHarness::TearDown(); | 122 ChromeRenderViewHostTestHarness::TearDown(); |
| 117 } | 123 } |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 434 |
| 429 vr_tab_helper->SetIsInVr(false); | 435 vr_tab_helper->SetIsInVr(false); |
| 430 GetPermissionManager()->RequestPermission( | 436 GetPermissionManager()->RequestPermission( |
| 431 PermissionType::NOTIFICATIONS, main_rfh(), url(), false, | 437 PermissionType::NOTIFICATIONS, main_rfh(), url(), false, |
| 432 base::Bind(&PermissionManagerTest::OnPermissionChange, | 438 base::Bind(&PermissionManagerTest::OnPermissionChange, |
| 433 base::Unretained(this))); | 439 base::Unretained(this))); |
| 434 EXPECT_TRUE(callback_called()); | 440 EXPECT_TRUE(callback_called()); |
| 435 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); | 441 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); |
| 436 } | 442 } |
| 437 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) | 443 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 444 |
| 445 TEST_F(PermissionManagerTest, PermissionIgnoredCleanup) { |
| 446 content::WebContents* contents = web_contents(); |
| 447 PermissionRequestManager::CreateForWebContents(contents); |
| 448 PermissionRequestManager* manager = |
| 449 PermissionRequestManager::FromWebContents(contents); |
| 450 auto prompt_factory = base::MakeUnique<MockPermissionPromptFactory>(manager); |
| 451 manager->DisplayPendingRequests(); |
| 452 |
| 453 NavigateAndCommit(url()); |
| 454 |
| 455 GetPermissionManager()->RequestPermission( |
| 456 PermissionType::VIDEO_CAPTURE, main_rfh(), url(), /*user_gesture=*/true, |
| 457 base::Bind(&PermissionManagerTest::OnPermissionChange, |
| 458 base::Unretained(this))); |
| 459 |
| 460 EXPECT_FALSE(PendingRequestsEmpty()); |
| 461 |
| 462 NavigateAndCommit(GURL("https://foobar.com")); |
| 463 |
| 464 EXPECT_FALSE(callback_called()); |
| 465 EXPECT_TRUE(PendingRequestsEmpty()); |
| 466 } |
| OLD | NEW |