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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_stream_device_permission_context_unittest.cc
diff --git a/chrome/browser/media/media_stream_device_permission_context_unittest.cc b/chrome/browser/media/media_stream_device_permission_context_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0b957dac36b9ebe2a403c76595e9a0afce08adef
--- /dev/null
+++ b/chrome/browser/media/media_stream_device_permission_context_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/media_stream_device_permission_context.h"
+
+#include "base/bind.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/permissions/permission_queue_controller.h"
+#include "chrome/browser/permissions/permission_request_id.h"
+#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/mock_render_process_host.h"
+#include "content/public/test/web_contents_tester.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class TestPermissionContext : public MediaStreamDevicePermissionContext {
+ public:
+ explicit TestPermissionContext(Profile* profile,
+ const ContentSettingsType permission_type)
xhwang 2015/08/27 19:25:17 s/explicit//
guoweis_left_chromium 2015/08/27 23:18:35 Done.
+ : MediaStreamDevicePermissionContext(profile, permission_type) {}
+
+ ~TestPermissionContext() override {}
+};
+
+} // anonymous namespace
+
+class MediaStreamDevicePermissionContextTests
+ : public ChromeRenderViewHostTestHarness {
+ protected:
+ MediaStreamDevicePermissionContextTests() = default;
+
+ void TestInsecureQueryingUrl(ContentSettingsType permission_type) {
+ TestPermissionContext permission_context(profile(), permission_type);
+ GURL insecure_url("http://www.example.com");
+ GURL secure_url("https://www.example.com");
+
+ // Check that there is no saved content settings.
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ insecure_url.GetOrigin(), insecure_url.GetOrigin(),
+ permission_type, std::string()));
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ secure_url.GetOrigin(), insecure_url.GetOrigin(),
+ permission_type, std::string()));
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ insecure_url.GetOrigin(), secure_url.GetOrigin(),
+ permission_type, std::string()));
+
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.GetPermissionStatus(
+ insecure_url, insecure_url));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ permission_context.GetPermissionStatus(insecure_url, secure_url));
+ }
+
+ private:
+ // ChromeRenderViewHostTestHarness:
+ void SetUp() override {
+ ChromeRenderViewHostTestHarness::SetUp();
+ InfoBarService::CreateForWebContents(web_contents());
+ PermissionBubbleManager::CreateForWebContents(web_contents());
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicePermissionContextTests);
+};
+
+// MEDIASTREAM_MIC permission status should be denied for insecure origin.
+TEST_F(MediaStreamDevicePermissionContextTests, TestMicInsecureQueryingUrl) {
+ TestInsecureQueryingUrl(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
+}
+
+// MEDIASTREAM_CAMERA permission status should be denied for insecure origin.
+TEST_F(MediaStreamDevicePermissionContextTests, TestCameraInsecureQueryingUrl) {
+ 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
+}
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.

Powered by Google App Engine
This is Rietveld 408576698