Chromium Code Reviews| 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" | |
|
xhwang
2017/05/04 22:10:59
style: add an empty line here
| |
| 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 public: | |
| 14 GURL requestingDomain; | |
| 15 GURL requestingSubDomain; | |
|
xhwang
2017/05/04 22:10:59
style: requesting_domain_
Vaage
2017/05/05 16:10:03
Done.
| |
| 16 | |
| 17 base::test::ScopedCommandLine scoped_command_line; | |
| 18 base::CommandLine* command_line; | |
|
xhwang
2017/05/04 22:10:59
style: command_line_
Vaage
2017/05/05 16:10:03
Done.
| |
| 19 | |
| 20 ProtectedMediaIdentifierWhitelist whitelist; | |
| 21 | |
| 22 ProtectedMediaIdentifierWhitelistTest() | |
| 23 : requestingDomain("https://example.com"), | |
| 24 requestingSubDomain("https://subdomain.example.com") { | |
| 25 command_line = scoped_command_line.GetProcessCommandLine(); | |
| 26 } | |
|
xhwang
2017/05/04 22:10:59
style: put methods to be above variables.
Vaage
2017/05/05 16:10:03
Done.
| |
| 27 }; | |
| 28 | |
| 29 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithSingleDomain) { | |
| 30 // The request should need to ask for permission | |
| 31 ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 32 | |
| 33 // Add the switch value that the whitelist reads from | |
| 34 command_line->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing"); | |
| 35 command_line->AppendSwitchASCII( | |
| 36 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
| 37 "example.com"); | |
| 38 | |
| 39 // The request should no longer need to ask for permission | |
| 40 ASSERT_TRUE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 41 } | |
| 42 | |
| 43 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithDomainList) { | |
| 44 // The request should need to ask for permission | |
| 45 ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 46 | |
| 47 // Add the switch value that the whitelist reads from | |
| 48 command_line->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing"); | |
| 49 command_line->AppendSwitchASCII( | |
| 50 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
| 51 "example.ca,example.com,example.edu"); | |
| 52 | |
| 53 // The request should no longer need to ask for permission | |
| 54 ASSERT_TRUE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 55 } | |
| 56 | |
| 57 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagAndSubdomain) { | |
| 58 // The request should need to ask for permission | |
| 59 ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingSubDomain)); | |
| 60 | |
| 61 // Add the switch value that the whitelist reads from | |
| 62 command_line->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing"); | |
| 63 command_line->AppendSwitchASCII( | |
| 64 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
| 65 "example.com"); | |
| 66 | |
| 67 // The request should no longer need to ask for permission | |
| 68 ASSERT_TRUE(whitelist.IsOriginWhitelisted(requestingSubDomain)); | |
| 69 } | |
| 70 | |
| 71 TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassRequiresUserDataDir) { | |
| 72 // The request should need to ask for permission | |
| 73 ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 74 | |
| 75 // Add the switch value that the whitelist reads from | |
| 76 command_line->AppendSwitchASCII( | |
| 77 switches::kDisableInfobarForProtectedMediaIdentifierForDomain, | |
| 78 "example.com"); | |
| 79 | |
| 80 // The request should still need to ask for permission | |
| 81 ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 82 | |
| 83 // Set the user data dir so the request should no longer need to ask for | |
| 84 // permission | |
| 85 command_line->AppendSwitchASCII(switches::kUserDataDir, "/dir/for/testing"); | |
|
xhwang
2017/05/04 22:10:59
Also add a test that kUserDataDir is appended with
Vaage
2017/05/05 16:10:03
Done.
| |
| 86 | |
| 87 // The request should no longer need to ask for permission | |
| 88 ASSERT_TRUE(whitelist.IsOriginWhitelisted(requestingDomain)); | |
| 89 } | |
| OLD | NEW |