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

Unified Diff: chrome/browser/media/protected_media_identifier_permission_context_unittest.cc

Issue 2816773002: Added switch for bypassing protected media identifier permission (Closed)
Patch Set: Added switch for bypassing permissions Created 3 years, 7 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/protected_media_identifier_permission_context_unittest.cc
diff --git a/chrome/browser/media/protected_media_identifier_permission_context_unittest.cc b/chrome/browser/media/protected_media_identifier_permission_context_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3c329159f8361957d6838a1e22a59d2f2427956
--- /dev/null
+++ b/chrome/browser/media/protected_media_identifier_permission_context_unittest.cc
@@ -0,0 +1,113 @@
+// Copyright 2017 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/protected_media_identifier_permission_context.h"
+
+#include "base/test/scoped_command_line.h"
+#include "chrome/common/chrome_switches.h"
+#include "media/base/media_switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+class ProtectedMediaIdentifierPermissionContextTest : public testing::Test {
+ public:
+ ProtectedMediaIdentifierPermissionContextTest()
+ : requesting_domain_("https://example.com"),
+ requesting_sub_domain_("https://subdomain.example.com") {
+ command_line_ = scoped_command_line_.GetProcessCommandLine();
+ }
+
+ GURL requesting_domain_;
+ GURL requesting_sub_domain_;
+
+ base::test::ScopedCommandLine scoped_command_line_;
+ base::CommandLine* command_line_;
+};
+
+TEST_F(ProtectedMediaIdentifierPermissionContextTest,
+ BypassWithFlagWithSingleDomain) {
+ // The request should need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+
+ // Add the switch value that the
+ // ProtectedMediaIdentifierPermissionContext::reads from
+ command_line_->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing");
+ command_line_->AppendSwitchASCII(
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
+ "example.com");
+
+ // The request should no longer need to ask for permission
+ ASSERT_TRUE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+}
+
+TEST_F(ProtectedMediaIdentifierPermissionContextTest,
+ BypassWithFlagWithDomainList) {
+ // The request should need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+
+ // Add the switch value that the
+ // ProtectedMediaIdentifierPermissionContext::reads from
+ command_line_->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing");
+ command_line_->AppendSwitchASCII(
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
+ "example.ca,example.com,example.edu");
+
+ // The request should no longer need to ask for permission
+ ASSERT_TRUE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+}
+
+TEST_F(ProtectedMediaIdentifierPermissionContextTest,
+ BypassWithFlagAndSubdomain) {
+ // The request should need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_sub_domain_));
+
+ // Add the switch value that the
+ // ProtectedMediaIdentifierPermissionContext::reads from
+ command_line_->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing");
+ command_line_->AppendSwitchASCII(
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
+ "example.com");
+
+ // The request should no longer need to ask for permission
+ ASSERT_TRUE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_sub_domain_));
+}
+
+TEST_F(ProtectedMediaIdentifierPermissionContextTest,
+ BypassRequiresUserDataDir) {
+ // The request should need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+
+ // Add the switch value that the
+ // ProtectedMediaIdentifierPermissionContext::reads from
+ command_line_->AppendSwitchASCII(
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
+ "example.com");
+
+ // The request should still need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+
+ // Set the user data dir switch but do not give it a value, this should still
+ // require the request to ask for permission.
+ command_line_->AppendSwitch(switches::kUserDataDir);
+
+ // The request should still need to ask for permission
+ ASSERT_FALSE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+
+ // Set the user data dir so the request should no longer need to ask for
+ // permission
+ command_line_->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing");
+
+ // The request should no longer need to ask for permission
+ ASSERT_TRUE(ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
+ requesting_domain_));
+}

Powered by Google App Engine
This is Rietveld 408576698