Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: chrome/browser/media/webrtc/media_stream_device_permission_context_unittest.cc

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, 68 EXPECT_EQ(CONTENT_SETTING_ASK,
78 permission_context.GetPermissionStatus(insecure_url, insecure_url) 69 permission_context.GetPermissionStatus(insecure_url, insecure_url)
79 .content_setting); 70 .content_setting);
80 71
81 EXPECT_EQ(CONTENT_SETTING_ASK, 72 EXPECT_EQ(CONTENT_SETTING_ASK,
82 permission_context.GetPermissionStatus(insecure_url, secure_url) 73 permission_context.GetPermissionStatus(insecure_url, secure_url)
83 .content_setting); 74 .content_setting);
84 } 75 }
85 76
86 void TestSecureQueryingUrl(ContentSettingsType permission_type) { 77 void TestSecureQueryingUrl(ContentSettingsType content_settings_type) {
87 TestPermissionContext permission_context(profile(), permission_type); 78 TestPermissionContext permission_context(profile(), content_settings_type);
88 GURL secure_url("https://www.example.com"); 79 GURL secure_url("https://www.example.com");
89 80
90 // Check that there is no saved content settings. 81 // Check that there is no saved content settings.
91 EXPECT_EQ(CONTENT_SETTING_ASK, 82 EXPECT_EQ(CONTENT_SETTING_ASK,
92 HostContentSettingsMapFactory::GetForProfile(profile()) 83 HostContentSettingsMapFactory::GetForProfile(profile())
93 ->GetContentSetting(secure_url.GetOrigin(), 84 ->GetContentSetting(secure_url.GetOrigin(),
94 secure_url.GetOrigin(), 85 secure_url.GetOrigin(),
95 permission_type, 86 content_settings_type,
96 std::string())); 87 std::string()));
97 88
98 EXPECT_EQ(CONTENT_SETTING_ASK, 89 EXPECT_EQ(CONTENT_SETTING_ASK,
99 permission_context.GetPermissionStatus(secure_url, secure_url) 90 permission_context.GetPermissionStatus(secure_url, secure_url)
100 .content_setting); 91 .content_setting);
101 } 92 }
102 93
103 private: 94 private:
104 // ChromeRenderViewHostTestHarness: 95 // ChromeRenderViewHostTestHarness:
105 void SetUp() override { 96 void SetUp() override {
(...skipping 22 matching lines...) Expand all
128 119
129 // MEDIASTREAM_MIC permission status should be ask for Secure origin. 120 // MEDIASTREAM_MIC permission status should be ask for Secure origin.
130 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) { 121 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) {
131 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 122 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
132 } 123 }
133 124
134 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin. 125 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin.
135 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) { 126 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) {
136 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 127 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
137 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698