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

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_BLOCK, permission_context.GetPermissionStatus(
61 insecure_url, insecure_url));
62 EXPECT_EQ(CONTENT_SETTING_BLOCK,
63 permission_context.GetPermissionStatus(insecure_url, secure_url));
64 }
65
66 private:
67 // ChromeRenderViewHostTestHarness:
68 void SetUp() override {
69 ChromeRenderViewHostTestHarness::SetUp();
70 InfoBarService::CreateForWebContents(web_contents());
71 PermissionBubbleManager::CreateForWebContents(web_contents());
72 }
73
74 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicePermissionContextTests);
75 };
76
77 // MEDIASTREAM_MIC permission status should be denied for insecure origin.
78 TEST_F(MediaStreamDevicePermissionContextTests, TestMicInsecureQueryingUrl) {
79 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
80 }
81
82 // MEDIASTREAM_CAMERA permission status should be denied for insecure origin.
83 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraInsecureQueryingUrl) {
84 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
mlamouri (slow - plz ping) 2015/08/28 10:56:21 You didn't add the tests :(
guoweis_left_chromium 2015/08/28 16:16:20 Sorry, it was on my TODO list but forgot to put a
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698