| 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/media_stream_device_permission_context.h" | 5 #include "chrome/browser/media/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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // TODO(raymes): many tests in MediaStreamDevicesControllerTest should be | 45 // TODO(raymes): many tests in MediaStreamDevicesControllerTest should be |
| 46 // converted to tests in this file. | 46 // converted to tests in this file. |
| 47 class MediaStreamDevicePermissionContextTests | 47 class MediaStreamDevicePermissionContextTests |
| 48 : public ChromeRenderViewHostTestHarness { | 48 : public ChromeRenderViewHostTestHarness { |
| 49 protected: | 49 protected: |
| 50 MediaStreamDevicePermissionContextTests() = default; | 50 MediaStreamDevicePermissionContextTests() = default; |
| 51 | 51 |
| 52 void TestInsecureQueryingUrl(ContentSettingsType permission_type) { | 52 void TestInsecureQueryingUrl(ContentSettingsType permission_type) { |
| 53 TestPermissionContext permission_context(profile(), permission_type); | 53 TestPermissionContext permission_context(profile(), permission_type); |
| 54 GURL insecure_url("http://www.example.com"); | 54 const GURL insecure_url("http://www.example.com"); |
| 55 GURL secure_url("https://www.example.com"); | 55 const GURL secure_url("https://www.example.com"); |
| 56 | 56 |
| 57 // Check that there is no saved content settings. | 57 // Check that there is no saved content settings. |
| 58 EXPECT_EQ(CONTENT_SETTING_ASK, | 58 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 59 HostContentSettingsMapFactory::GetForProfile(profile()) | 59 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 60 ->GetContentSetting(insecure_url.GetOrigin(), | 60 ->GetContentSetting(insecure_url.GetOrigin(), |
| 61 insecure_url.GetOrigin(), | 61 insecure_url.GetOrigin(), |
| 62 permission_type, | 62 permission_type, |
| 63 std::string())); | 63 std::string())); |
| 64 EXPECT_EQ(CONTENT_SETTING_ASK, | 64 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 65 HostContentSettingsMapFactory::GetForProfile(profile()) | 65 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 66 ->GetContentSetting(secure_url.GetOrigin(), | 66 ->GetContentSetting(secure_url.GetOrigin(), |
| 67 insecure_url.GetOrigin(), | 67 insecure_url.GetOrigin(), |
| 68 permission_type, | 68 permission_type, |
| 69 std::string())); | 69 std::string())); |
| 70 EXPECT_EQ(CONTENT_SETTING_ASK, | 70 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 71 HostContentSettingsMapFactory::GetForProfile(profile()) | 71 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 72 ->GetContentSetting(insecure_url.GetOrigin(), | 72 ->GetContentSetting(insecure_url.GetOrigin(), |
| 73 secure_url.GetOrigin(), | 73 secure_url.GetOrigin(), |
| 74 permission_type, | 74 permission_type, |
| 75 std::string())); | 75 std::string())); |
| 76 | 76 |
| 77 const url::Origin insecure_origin(insecure_url); |
| 78 const url::Origin secure_origin(secure_url); |
| 77 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( | 79 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( |
| 78 insecure_url, insecure_url)); | 80 insecure_origin, insecure_origin)); |
| 79 EXPECT_EQ(CONTENT_SETTING_ASK, | 81 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( |
| 80 permission_context.GetPermissionStatus(insecure_url, secure_url)); | 82 insecure_origin, secure_origin)); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void TestSecureQueryingUrl(ContentSettingsType permission_type) { | 85 void TestSecureQueryingUrl(ContentSettingsType permission_type) { |
| 84 TestPermissionContext permission_context(profile(), permission_type); | 86 TestPermissionContext permission_context(profile(), permission_type); |
| 85 GURL secure_url("https://www.example.com"); | 87 GURL secure_url("https://www.example.com"); |
| 86 | 88 |
| 87 // Check that there is no saved content settings. | 89 // Check that there is no saved content settings. |
| 88 EXPECT_EQ(CONTENT_SETTING_ASK, | 90 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 89 HostContentSettingsMapFactory::GetForProfile(profile()) | 91 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 90 ->GetContentSetting(secure_url.GetOrigin(), | 92 ->GetContentSetting(secure_url.GetOrigin(), |
| 91 secure_url.GetOrigin(), | 93 secure_url.GetOrigin(), |
| 92 permission_type, | 94 permission_type, |
| 93 std::string())); | 95 std::string())); |
| 94 | 96 |
| 95 EXPECT_EQ(CONTENT_SETTING_ASK, | 97 const url::Origin secure_origin(secure_url); |
| 96 permission_context.GetPermissionStatus(secure_url, secure_url)); | 98 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus( |
| 99 secure_origin, secure_origin)); |
| 97 } | 100 } |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 // ChromeRenderViewHostTestHarness: | 103 // ChromeRenderViewHostTestHarness: |
| 101 void SetUp() override { | 104 void SetUp() override { |
| 102 ChromeRenderViewHostTestHarness::SetUp(); | 105 ChromeRenderViewHostTestHarness::SetUp(); |
| 103 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
| 104 InfoBarService::CreateForWebContents(web_contents()); | 107 InfoBarService::CreateForWebContents(web_contents()); |
| 105 #else | 108 #else |
| 106 PermissionBubbleManager::CreateForWebContents(web_contents()); | 109 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 124 | 127 |
| 125 // MEDIASTREAM_MIC permission status should be ask for Secure origin. | 128 // MEDIASTREAM_MIC permission status should be ask for Secure origin. |
| 126 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { | 129 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { |
| 127 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 130 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 128 } | 131 } |
| 129 | 132 |
| 130 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. | 133 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. |
| 131 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { | 134 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { |
| 132 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 135 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 133 } | 136 } |
| OLD | NEW |