| 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/media/webrtc/media_stream_device_permission_context.h" | 5 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/permissions/permission_request_id.h" | 12 #include "chrome/browser/permissions/permission_request_id.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "content/public/browser/permission_type.h" | |
| 19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
| 21 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 #if !defined(OS_ANDROID) | 23 #if !defined(OS_ANDROID) |
| 25 #include "chrome/browser/permissions/permission_request_manager.h" | 24 #include "chrome/browser/permissions/permission_request_manager.h" |
| 26 #endif | 25 #endif |
| 27 | 26 |
| 28 namespace { | 27 namespace { |
| 29 class TestPermissionContext : public MediaStreamDevicePermissionContext { | 28 class TestPermissionContext : public MediaStreamDevicePermissionContext { |
| 30 public: | 29 public: |
| 31 TestPermissionContext(Profile* profile, | 30 TestPermissionContext(Profile* profile, |
| 32 const ContentSettingsType permission_type) | 31 const ContentSettingsType content_settings_type) |
| 33 : MediaStreamDevicePermissionContext( | 32 : MediaStreamDevicePermissionContext(profile, content_settings_type) {} |
| 34 profile, | |
| 35 permission_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA | |
| 36 ? content::PermissionType::VIDEO_CAPTURE | |
| 37 : content::PermissionType::AUDIO_CAPTURE, | |
| 38 permission_type) {} | |
| 39 | 33 |
| 40 ~TestPermissionContext() override {} | 34 ~TestPermissionContext() override {} |
| 41 }; | 35 }; |
| 42 | 36 |
| 43 } // anonymous namespace | 37 } // anonymous namespace |
| 44 | 38 |
| 45 // TODO(raymes): many tests in MediaStreamDevicesControllerTest should be | 39 // TODO(raymes): many tests in MediaStreamDevicesControllerTest should be |
| 46 // converted to tests in this file. | 40 // converted to tests in this file. |
| 47 class MediaStreamDevicePermissionContextTests | 41 class MediaStreamDevicePermissionContextTests |
| 48 : public ChromeRenderViewHostTestHarness { | 42 : public ChromeRenderViewHostTestHarness { |
| 49 protected: | 43 protected: |
| 50 MediaStreamDevicePermissionContextTests() = default; | 44 MediaStreamDevicePermissionContextTests() = default; |
| 51 | 45 |
| 52 void TestInsecureQueryingUrl(ContentSettingsType permission_type) { | 46 void TestInsecureQueryingUrl(ContentSettingsType content_settings_type) { |
| 53 TestPermissionContext permission_context(profile(), permission_type); | 47 TestPermissionContext permission_context(profile(), content_settings_type); |
| 54 GURL insecure_url("http://www.example.com"); | 48 GURL insecure_url("http://www.example.com"); |
| 55 GURL secure_url("https://www.example.com"); | 49 GURL secure_url("https://www.example.com"); |
| 56 | 50 |
| 57 // Check that there is no saved content settings. | 51 // Check that there is no saved content settings. |
| 58 EXPECT_EQ(CONTENT_SETTING_ASK, | 52 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 59 HostContentSettingsMapFactory::GetForProfile(profile()) | 53 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 60 ->GetContentSetting(insecure_url.GetOrigin(), | 54 ->GetContentSetting(insecure_url.GetOrigin(), |
| 61 insecure_url.GetOrigin(), | 55 insecure_url.GetOrigin(), |
| 62 permission_type, | 56 content_settings_type, std::string())); |
| 63 std::string())); | |
| 64 EXPECT_EQ(CONTENT_SETTING_ASK, | 57 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 65 HostContentSettingsMapFactory::GetForProfile(profile()) | 58 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 66 ->GetContentSetting(secure_url.GetOrigin(), | 59 ->GetContentSetting(secure_url.GetOrigin(), |
| 67 insecure_url.GetOrigin(), | 60 insecure_url.GetOrigin(), |
| 68 permission_type, | 61 content_settings_type, std::string())); |
| 69 std::string())); | |
| 70 EXPECT_EQ(CONTENT_SETTING_ASK, | 62 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 71 HostContentSettingsMapFactory::GetForProfile(profile()) | 63 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 72 ->GetContentSetting(insecure_url.GetOrigin(), | 64 ->GetContentSetting(insecure_url.GetOrigin(), |
| 73 secure_url.GetOrigin(), | 65 secure_url.GetOrigin(), |
| 74 permission_type, | 66 content_settings_type, std::string())); |
| 75 std::string())); | |
| 76 | 67 |
| 77 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( | 68 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( |
| 78 insecure_url, insecure_url)); | 69 insecure_url, insecure_url)); |
| 79 EXPECT_EQ(CONTENT_SETTING_ASK, | 70 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 80 permission_context.GetPermissionStatus(insecure_url, secure_url)); | 71 permission_context.GetPermissionStatus(insecure_url, secure_url)); |
| 81 } | 72 } |
| 82 | 73 |
| 83 void TestSecureQueryingUrl(ContentSettingsType permission_type) { | 74 void TestSecureQueryingUrl(ContentSettingsType content_settings_type) { |
| 84 TestPermissionContext permission_context(profile(), permission_type); | 75 TestPermissionContext permission_context(profile(), content_settings_type); |
| 85 GURL secure_url("https://www.example.com"); | 76 GURL secure_url("https://www.example.com"); |
| 86 | 77 |
| 87 // Check that there is no saved content settings. | 78 // Check that there is no saved content settings. |
| 88 EXPECT_EQ(CONTENT_SETTING_ASK, | 79 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 89 HostContentSettingsMapFactory::GetForProfile(profile()) | 80 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 90 ->GetContentSetting(secure_url.GetOrigin(), | 81 ->GetContentSetting(secure_url.GetOrigin(), |
| 91 secure_url.GetOrigin(), | 82 secure_url.GetOrigin(), |
| 92 permission_type, | 83 content_settings_type, |
| 93 std::string())); | 84 std::string())); |
| 94 | 85 |
| 95 EXPECT_EQ(CONTENT_SETTING_ASK, | 86 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 96 permission_context.GetPermissionStatus(secure_url, secure_url)); | 87 permission_context.GetPermissionStatus(secure_url, secure_url)); |
| 97 } | 88 } |
| 98 | 89 |
| 99 private: | 90 private: |
| 100 // ChromeRenderViewHostTestHarness: | 91 // ChromeRenderViewHostTestHarness: |
| 101 void SetUp() override { | 92 void SetUp() override { |
| 102 ChromeRenderViewHostTestHarness::SetUp(); | 93 ChromeRenderViewHostTestHarness::SetUp(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 124 | 115 |
| 125 // MEDIASTREAM_MIC permission status should be ask for Secure origin. | 116 // MEDIASTREAM_MIC permission status should be ask for Secure origin. |
| 126 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { | 117 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { |
| 127 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 118 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 128 } | 119 } |
| 129 | 120 |
| 130 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. | 121 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. |
| 131 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { | 122 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { |
| 132 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 123 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 133 } | 124 } |
| OLD | NEW |