OLD | NEW |
---|---|
(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 not be affected as the whitelist is empty | |
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); | |
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.
| |
30 command_line->AppendSwitchASCII( | |
31 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
32 "example.ca"); | |
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.com"); | |
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 // The request should no longer need to ask for permission | |
86 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
87 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); | |
88 } | |
89 | |
90 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithDomainList) { | |
91 const GURL requesting("https://example.com"); | |
92 const ProtectedMediaIdentifierWhitelist whitelist; | |
93 | |
94 // The request should need to ask for permission | |
95 EXPECT_EQ(CONTENT_SETTING_ASK, | |
96 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); | |
97 | |
98 // Add the switch value that the whitelist reads from | |
99 base::test::ScopedCommandLine scoped_command_line; | |
100 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); | |
101 command_line->AppendSwitch(switches::kUserDataDir); | |
102 command_line->AppendSwitchASCII( | |
103 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
104 "example.ca,example.com,example.edu"); | |
105 | |
106 // The request should no longer need to ask for permission | |
107 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
108 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); | |
109 } | |
110 | |
111 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagAndSubdomain) { | |
112 const GURL requesting("https://subdomain.example.com"); | |
113 const ProtectedMediaIdentifierWhitelist whitelist; | |
114 | |
115 // The request should need to ask for permission | |
116 EXPECT_EQ(CONTENT_SETTING_ASK, | |
117 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); | |
118 | |
119 // Add the switch value that the whitelist reads from | |
120 base::test::ScopedCommandLine scoped_command_line; | |
121 base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); | |
122 command_line->AppendSwitch(switches::kUserDataDir); | |
123 command_line->AppendSwitchASCII( | |
124 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
125 "example.com"); | |
126 | |
127 // The request should no longer need to ask for permission | |
128 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
129 whitelist.modifySettingFor(CONTENT_SETTING_ASK, requesting)); | |
130 } | |
OLD | NEW |