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

Side by Side Diff: chrome/browser/media/protected_media_identifier_whitelist_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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/protected_media_identifier_whitelist.h"
6 #include "base/test/scoped_command_line.h"
7 #include "chrome/common/chrome_switches.h"
8 #include "media/base/media_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h"
11
12 class ProtectedMediaIdentifierWhitelistTest : public testing::Test {};
13
14 TEST_F(ProtectedMediaIdentifierWhitelistTest, NoEffect) {
15 const GURL requesting("https://example.com");
16 const ProtectedMediaIdentifierWhitelist whitelist;
17
18 // The request should need to ask for permission
Joey Parrish 2017/05/04 17:06:14 I don't understand this comment in context of the
Vaage 2017/05/04 17:42:30 Done.
19 EXPECT_EQ(CONTENT_SETTING_ALLOW,
20 whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting));
21 EXPECT_EQ(CONTENT_SETTING_ASK,
22 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
23 EXPECT_EQ(CONTENT_SETTING_BLOCK,
24 whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting));
25
26 // Add the switch value that the whitelist reads from
27 base::test::ScopedCommandLine scoped_command_line;
28 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
29 command_line->AppendSwitch(switches::kUserDataDir);
30 command_line->AppendSwitchASCII(
31 switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
32 "example.ca,example.edu");
33
34 // The request should not be affected as it was not added to the whitelist
35 EXPECT_EQ(CONTENT_SETTING_ALLOW,
36 whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting));
37 EXPECT_EQ(CONTENT_SETTING_ASK,
38 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
39 EXPECT_EQ(CONTENT_SETTING_BLOCK,
40 whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting));
41 }
42
43 TEST_F(ProtectedMediaIdentifierWhitelistTest, IgnoresNonAsk) {
44 const GURL requesting("https://example.com");
45 const ProtectedMediaIdentifierWhitelist whitelist;
46
47 // Add the switch value that the whitelist reads from
48 base::test::ScopedCommandLine scoped_command_line;
49 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
50 command_line->AppendSwitch(switches::kUserDataDir);
51 command_line->AppendSwitchASCII(
52 switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
53 "example.com");
54
55 // The whilelist should not change the settings for any non-ask settings
56 EXPECT_EQ(CONTENT_SETTING_ALLOW,
57 whitelist.modifySettingFor(CONTENT_SETTING_ALLOW, requesting));
58 EXPECT_EQ(CONTENT_SETTING_BLOCK,
59 whitelist.modifySettingFor(CONTENT_SETTING_BLOCK, requesting));
60 }
61
62 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassRequiresUserDataDir) {
63 const GURL requesting("https://example.com");
64 const ProtectedMediaIdentifierWhitelist whitelist;
65
66 // The request should need to ask for permission
67 EXPECT_EQ(CONTENT_SETTING_ASK,
68 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
69
70 // Add the switch value that the whitelist reads from
71 base::test::ScopedCommandLine scoped_command_line;
72 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
73 command_line->AppendSwitchASCII(
74 switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
75 "example.ca,example.com,example.edu");
76
77 // The request should still need to ask for permission
78 EXPECT_EQ(CONTENT_SETTING_ASK,
79 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
80
81 // Set the user data dir so the request should no longer need to ask for
82 // permission
83 command_line->AppendSwitch(switches::kUserDataDir);
84
85 EXPECT_EQ(CONTENT_SETTING_ALLOW,
86 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
87 }
88
89 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlag) {
Joey Parrish 2017/05/04 17:06:14 From reading the test, I don't understand the purp
Vaage 2017/05/04 17:42:29 Done.
90 const GURL requesting("https://example.com");
91 const ProtectedMediaIdentifierWhitelist whitelist;
92
93 // The request should need to ask for permission
94 EXPECT_EQ(CONTENT_SETTING_ASK,
95 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
96
97 // Add the switch value that the whitelist reads from
98 base::test::ScopedCommandLine scoped_command_line;
99 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
100 command_line->AppendSwitch(switches::kUserDataDir);
101 command_line->AppendSwitchASCII(
102 switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
103 "example.ca,example.com,example.edu");
104
105 // The request should no longer need to ask for permission
106 EXPECT_EQ(CONTENT_SETTING_ALLOW,
107 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
108 }
109
110 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagAndSubdomain) {
Joey Parrish 2017/05/04 17:06:14 I would love to have Xiaohan's feedback on this pa
Vaage 2017/05/04 17:42:29 I found it easier to work with if I use the domain
111 const GURL requesting("https://subdomain.example.com");
112 const ProtectedMediaIdentifierWhitelist whitelist;
113
114 // The request should need to ask for permission
115 EXPECT_EQ(CONTENT_SETTING_ASK,
116 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
117
118 // Add the switch value that the whitelist reads from
119 base::test::ScopedCommandLine scoped_command_line;
120 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
121 command_line->AppendSwitch(switches::kUserDataDir);
122 command_line->AppendSwitchASCII(
123 switches::kDisableInfobarForProtectedMediaIdentifierForDomain,
124 "example.com");
125
126 // The request should no longer need to ask for permission
127 EXPECT_EQ(CONTENT_SETTING_ALLOW,
128 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting));
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698