Index: chrome/browser/media/protected_media_identifier_whitelist_unittest.cc |
diff --git a/chrome/browser/media/protected_media_identifier_whitelist_unittest.cc b/chrome/browser/media/protected_media_identifier_whitelist_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f94a483db564aa0b6afb2fb794948dceb9d5fcc0 |
--- /dev/null |
+++ b/chrome/browser/media/protected_media_identifier_whitelist_unittest.cc |
@@ -0,0 +1,130 @@ |
+// 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_whitelist.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 ProtectedMediaIdentifierWhitelistTest : public testing::Test {}; |
+ |
+TEST_F(ProtectedMediaIdentifierWhitelistTest, NoEffect) { |
+ const GURL requesting("https://example.com"); |
+ const ProtectedMediaIdentifierWhitelist whitelist; |
+ |
+ // The request should not be affected as the whitelist is empty |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting)); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting)); |
+ |
+ // Add the switch value that the whitelist reads from |
+ base::test::ScopedCommandLine scoped_command_line; |
+ base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
+ command_line->AppendSwitch(switches::kUserDataDir); |
xhwang
2017/05/04 19:57:37
Since you already have test fixture (class) Protec
xhwang
2017/05/04 19:57:37
Should use AppendSwitchASCII for kUserDataDir?
Vaage
2017/05/04 21:41:20
Done.
|
+ command_line->AppendSwitchASCII( |
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
+ "example.ca"); |
+ |
+ // The request should not be affected as it was not added to the whitelist |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting)); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting)); |
+} |
+ |
+TEST_F(ProtectedMediaIdentifierWhitelistTest, IgnoresNonAsk) { |
+ const GURL requesting("https://example.com"); |
+ const ProtectedMediaIdentifierWhitelist whitelist; |
+ |
+ // Add the switch value that the whitelist reads from |
+ base::test::ScopedCommandLine scoped_command_line; |
+ base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
+ command_line->AppendSwitch(switches::kUserDataDir); |
+ command_line->AppendSwitchASCII( |
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
+ "example.com"); |
+ |
+ // The whilelist should not change the settings for any non-ask settings |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting)); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting)); |
+} |
+ |
+TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassRequiresUserDataDir) { |
+ const GURL requesting("https://example.com"); |
+ const ProtectedMediaIdentifierWhitelist whitelist; |
+ |
+ // The request should need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ |
+ // Add the switch value that the whitelist reads from |
+ base::test::ScopedCommandLine scoped_command_line; |
+ base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
+ command_line->AppendSwitchASCII( |
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
+ "example.com"); |
+ |
+ // The request should still need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ |
+ // Set the user data dir so the request should no longer need to ask for |
+ // permission |
+ command_line->AppendSwitch(switches::kUserDataDir); |
+ |
+ // The request should no longer need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+} |
+ |
+TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithDomainList) { |
+ const GURL requesting("https://example.com"); |
+ const ProtectedMediaIdentifierWhitelist whitelist; |
+ |
+ // The request should need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ |
+ // Add the switch value that the whitelist reads from |
+ base::test::ScopedCommandLine scoped_command_line; |
+ base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
+ command_line->AppendSwitch(switches::kUserDataDir); |
+ command_line->AppendSwitchASCII( |
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
+ "example.ca,example.com,example.edu"); |
+ |
+ // The request should no longer need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+} |
+ |
+TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagAndSubdomain) { |
+ const GURL requesting("https://subdomain.example.com"); |
+ const ProtectedMediaIdentifierWhitelist whitelist; |
+ |
+ // The request should need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+ |
+ // Add the switch value that the whitelist reads from |
+ base::test::ScopedCommandLine scoped_command_line; |
+ base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); |
+ command_line->AppendSwitch(switches::kUserDataDir); |
+ command_line->AppendSwitchASCII( |
+ switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
+ "example.com"); |
+ |
+ // The request should no longer need to ask for permission |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); |
+} |