| 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_result.h" | 11 #include "chrome/browser/permissions/permission_result.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "content/public/browser/permission_type.h" | 15 #include "content/public/browser/permission_type.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "device/vr/features/features.h" | 17 #include "device/vr/features/features.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 #if BUILDFLAG(ENABLE_VR) | 20 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 21 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | 21 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" |
| 22 #endif // BUILDFLAG(ENABLE_VR) | 22 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 23 | 23 |
| 24 using blink::mojom::PermissionStatus; | 24 using blink::mojom::PermissionStatus; |
| 25 using content::PermissionType; | 25 using content::PermissionType; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 #if BUILDFLAG(ENABLE_VR) | 29 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 30 int kNoPendingOperation = -1; | 30 int kNoPendingOperation = -1; |
| 31 #endif // BUILDFLAG(ENABLE_VR) | 31 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 32 | 32 |
| 33 class PermissionManagerTestingProfile final : public TestingProfile { | 33 class PermissionManagerTestingProfile final : public TestingProfile { |
| 34 public: | 34 public: |
| 35 PermissionManagerTestingProfile() {} | 35 PermissionManagerTestingProfile() {} |
| 36 ~PermissionManagerTestingProfile() override {} | 36 ~PermissionManagerTestingProfile() override {} |
| 37 | 37 |
| 38 PermissionManager* GetPermissionManager() override { | 38 PermissionManager* GetPermissionManager() override { |
| 39 return PermissionManagerFactory::GetForProfile(this); | 39 return PermissionManagerFactory::GetForProfile(this); |
| 40 } | 40 } |
| 41 | 41 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 393 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 394 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), | 394 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), |
| 395 CONTENT_SETTING_ALLOW); | 395 CONTENT_SETTING_ALLOW); |
| 396 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); | 396 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); |
| 397 | 397 |
| 398 EXPECT_FALSE(callback_called()); | 398 EXPECT_FALSE(callback_called()); |
| 399 | 399 |
| 400 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); | 400 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); |
| 401 } | 401 } |
| 402 | 402 |
| 403 #if BUILDFLAG(ENABLE_VR) | 403 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| 404 TEST_F(PermissionManagerTest, SuppressPermissionRequests) { | 404 TEST_F(PermissionManagerTest, SuppressPermissionRequests) { |
| 405 content::WebContents* contents = web_contents(); | 405 content::WebContents* contents = web_contents(); |
| 406 vr_shell::VrTabHelper::CreateForWebContents(contents); | 406 vr_shell::VrTabHelper::CreateForWebContents(contents); |
| 407 NavigateAndCommit(url()); | 407 NavigateAndCommit(url()); |
| 408 | 408 |
| 409 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); | 409 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); |
| 410 GetPermissionManager()->RequestPermission( | 410 GetPermissionManager()->RequestPermission( |
| 411 PermissionType::NOTIFICATIONS, main_rfh(), url(), true, | 411 PermissionType::NOTIFICATIONS, main_rfh(), url(), true, |
| 412 base::Bind(&PermissionManagerTest::OnPermissionChange, | 412 base::Bind(&PermissionManagerTest::OnPermissionChange, |
| 413 base::Unretained(this))); | 413 base::Unretained(this))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 427 EXPECT_EQ(PermissionStatus::DENIED, callback_result()); | 427 EXPECT_EQ(PermissionStatus::DENIED, callback_result()); |
| 428 | 428 |
| 429 vr_tab_helper->SetIsInVr(false); | 429 vr_tab_helper->SetIsInVr(false); |
| 430 GetPermissionManager()->RequestPermission( | 430 GetPermissionManager()->RequestPermission( |
| 431 PermissionType::NOTIFICATIONS, main_rfh(), url(), false, | 431 PermissionType::NOTIFICATIONS, main_rfh(), url(), false, |
| 432 base::Bind(&PermissionManagerTest::OnPermissionChange, | 432 base::Bind(&PermissionManagerTest::OnPermissionChange, |
| 433 base::Unretained(this))); | 433 base::Unretained(this))); |
| 434 EXPECT_TRUE(callback_called()); | 434 EXPECT_TRUE(callback_called()); |
| 435 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); | 435 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); |
| 436 } | 436 } |
| 437 #endif // BUILDFLAG(ENABLE_VR) | 437 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) |
| OLD | NEW |