Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 24 class TestPermissionContext : public MediaStreamDevicePermissionContext { | |
| 25 public: | |
| 26 explicit TestPermissionContext(Profile* profile, | |
| 27 const ContentSettingsType permission_type) | |
|
xhwang
2015/08/27 19:25:17
s/explicit//
guoweis_left_chromium
2015/08/27 23:18:35
Done.
| |
| 28 : MediaStreamDevicePermissionContext(profile, permission_type) {} | |
| 29 | |
| 30 ~TestPermissionContext() override {} | |
| 31 }; | |
| 32 | |
| 33 } // anonymous namespace | |
| 34 | |
| 35 class MediaStreamDevicePermissionContextTests | |
| 36 : public ChromeRenderViewHostTestHarness { | |
| 37 protected: | |
| 38 MediaStreamDevicePermissionContextTests() = default; | |
| 39 | |
| 40 void TestInsecureQueryingUrl(ContentSettingsType permission_type) { | |
| 41 TestPermissionContext permission_context(profile(), permission_type); | |
| 42 GURL insecure_url("http://www.example.com"); | |
| 43 GURL secure_url("https://www.example.com"); | |
| 44 | |
| 45 // Check that there is no saved content settings. | |
| 46 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 47 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 48 insecure_url.GetOrigin(), insecure_url.GetOrigin(), | |
| 49 permission_type, std::string())); | |
| 50 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 51 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 52 secure_url.GetOrigin(), insecure_url.GetOrigin(), | |
| 53 permission_type, std::string())); | |
| 54 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 55 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 56 insecure_url.GetOrigin(), secure_url.GetOrigin(), | |
| 57 permission_type, std::string())); | |
| 58 | |
| 59 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus( | |
| 60 insecure_url, insecure_url)); | |
| 61 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 62 permission_context.GetPermissionStatus(insecure_url, secure_url)); | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 // ChromeRenderViewHostTestHarness: | |
| 67 void SetUp() override { | |
| 68 ChromeRenderViewHostTestHarness::SetUp(); | |
| 69 InfoBarService::CreateForWebContents(web_contents()); | |
| 70 PermissionBubbleManager::CreateForWebContents(web_contents()); | |
| 71 } | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicePermissionContextTests); | |
| 74 }; | |
| 75 | |
| 76 // MEDIASTREAM_MIC permission status should be denied for insecure origin. | |
| 77 TEST_F(MediaStreamDevicePermissionContextTests, TestMicInsecureQueryingUrl) { | |
| 78 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 79 } | |
| 80 | |
| 81 // MEDIASTREAM_CAMERA permission status should be denied for insecure origin. | |
| 82 TEST_F(MediaStreamDevicePermissionContextTests, TestCameraInsecureQueryingUrl) { | |
| 83 TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
|
mlamouri (slow - plz ping)
2015/08/27 10:03:40
Can you check that it is working for secure origin
| |
| 84 } | |
|
raymes
2015/08/27 05:54:18
There's a bunch of tests in MediaStreamDevicesCont
guoweis_left_chromium
2015/08/27 23:18:35
Done.
| |
| OLD | NEW |