Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / media / media_stream_device_permission_context_unittest.cc
blobb379446356be8a8f29f310e0cfea3d0dc4c8aca3
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.
5 #include "chrome/browser/media/media_stream_device_permission_context.h"
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"
22 namespace {
23 class TestPermissionContext : public MediaStreamDevicePermissionContext {
24 public:
25 TestPermissionContext(Profile* profile,
26 const ContentSettingsType permission_type)
27 : MediaStreamDevicePermissionContext(profile, permission_type) {}
29 ~TestPermissionContext() override {}
32 } // anonymous namespace
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;
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");
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()));
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));
66 void TestSecureQueryingUrl(ContentSettingsType permission_type) {
67 TestPermissionContext permission_context(profile(), permission_type);
68 GURL secure_url("https://www.example.com");
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()));
76 EXPECT_EQ(CONTENT_SETTING_ASK,
77 permission_context.GetPermissionStatus(secure_url, secure_url));
80 private:
81 // ChromeRenderViewHostTestHarness:
82 void SetUp() override {
83 ChromeRenderViewHostTestHarness::SetUp();
84 InfoBarService::CreateForWebContents(web_contents());
85 PermissionBubbleManager::CreateForWebContents(web_contents());
88 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicePermissionContextTests);
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);
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);
103 // MEDIASTREAM_MIC permission status should be ask for Secure origin.
104 TEST_F(MediaStreamDevicePermissionContextTests, TestMicSecureQueryingUrl) {
105 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
108 // MEDIASTREAM_CAMERA permission status should be ask for Secure origin.
109 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraSecureQueryingUrl) {
110 TestSecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);