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

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

Issue 1311783007: refactor to Introduce AUDIO_CAPTURE and VIDEO_CAPTURE permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/media_stream_device_permission_context.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/permissions/permission_queue_controller.h"
10 #include "chrome/browser/permissions/permission_request_id.h"
11 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "components/content_settings/core/browser/host_content_settings_map.h"
15 #include "components/content_settings/core/common/content_settings.h"
16 #include "components/content_settings/core/common/content_settings_types.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/mock_render_process_host.h"
19 #include "content/public/test/web_contents_tester.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace {
23 class TestPermissionContext : public MediaStreamDevicePermissionContext {
24 public:
25 TestPermissionContext(Profile* profile,
26 const ContentSettingsType permission_type)
27 : MediaStreamDevicePermissionContext(profile, permission_type) {}
28
29 ~TestPermissionContext() override {}
30 };
31
32 } // anonymous namespace
33
34 // TODO(raymes): many tests in MediaStreamDevicesControllerTest should be
35 // converted to tests in this file.
36 class MediaStreamDevicePermissionContextTests
37 : public ChromeRenderViewHostTestHarness {
38 protected:
39 MediaStreamDevicePermissionContextTests() = default;
40
41 void TestInsecureQueryingUrl(ContentSettingsType permission_type) {
42 TestPermissionContext permission_context(profile(), permission_type);
43 GURL insecure_url("http://www.example.com");
44 GURL secure_url("https://www.example.com");
45
46 // Check that there is no saved content settings.
47 EXPECT_EQ(CONTENT_SETTING_ASK,
48 profile()->GetHostContentSettingsMap()->GetContentSetting(
49 insecure_url.GetOrigin(), insecure_url.GetOrigin(),
50 permission_type, std::string()));
51 EXPECT_EQ(CONTENT_SETTING_ASK,
52 profile()->GetHostContentSettingsMap()->GetContentSetting(
53 secure_url.GetOrigin(), insecure_url.GetOrigin(),
54 permission_type, std::string()));
55 EXPECT_EQ(CONTENT_SETTING_ASK,
56 profile()->GetHostContentSettingsMap()->GetContentSetting(
57 insecure_url.GetOrigin(), secure_url.GetOrigin(),
58 permission_type, std::string()));
59
60 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.GetPermissionStatus(
61 insecure_url, insecure_url));
62 EXPECT_EQ(CONTENT_SETTING_ASK,
63 permission_context.GetPermissionStatus(insecure_url, secure_url));
64 }
65
66 void TestSecureQueryingUrl(ContentSettingsType permission_type) {
67 TestPermissionContext permission_context(profile(), permission_type);
68 GURL secure_url("https://www.example.com");
69
70 // Check that there is no saved content settings.
71 EXPECT_EQ(CONTENT_SETTING_ASK,
72 profile()->GetHostContentSettingsMap()->GetContentSetting(
73 secure_url.GetOrigin(), secure_url.GetOrigin(),
74 permission_type, std::string()));
75
76 EXPECT_EQ(CONTENT_SETTING_ASK,
77 permission_context.GetPermissionStatus(secure_url, secure_url));
78 }
79
80 private:
81 // ChromeRenderViewHostTestHarness:
82 void SetUp() override {
83 ChromeRenderViewHostTestHarness::SetUp();
84 InfoBarService::CreateForWebContents(web_contents());
85 PermissionBubbleManager::CreateForWebContents(web_contents());
86 }
87
88 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicePermissionContextTests);
89 };
90
91 // MEDIASTREAM_MIC permission status should be ask for insecure origin to
92 // accommodate the usage case of Flash.
93 TEST_F(MediaStreamDevicePermissionContextTests, TestMicInsecureQueryingUrl) {
94 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
95 }
96
97 // MEDIASTREAM_CAMERA permission status should be ask for insecure origin to
98 // accommodate the usage case of Flash.
99 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraInsecureQueryingUrl) {
100 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
101 }
102
103 // MEDIASTREAM_MIC permission status should be ask for Secure origin.
104 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) {
105 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
106 }
107
108 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin.
109 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) {
110 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698