Chromium Code Reviews| 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..3e04cf5375c8d514c9d2eb47ce650957683b9a1b |
| --- /dev/null |
| +++ b/chrome/browser/media/protected_media_identifier_whitelist_unittest.cc |
| @@ -0,0 +1,89 @@ |
| +// 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" |
|
xhwang
2017/05/04 22:10:59
style: add an empty line here
|
| +#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 { |
| + public: |
| + GURL requestingDomain; |
| + GURL requestingSubDomain; |
|
xhwang
2017/05/04 22:10:59
style: requesting_domain_
Vaage
2017/05/05 16:10:03
Done.
|
| + |
| + base::test::ScopedCommandLine scoped_command_line; |
| + base::CommandLine* command_line; |
|
xhwang
2017/05/04 22:10:59
style: command_line_
Vaage
2017/05/05 16:10:03
Done.
|
| + |
| + ProtectedMediaIdentifierWhitelist whitelist; |
| + |
| + ProtectedMediaIdentifierWhitelistTest() |
| + : requestingDomain("https://example.com"), |
| + requestingSubDomain("https://subdomain.example.com") { |
| + command_line = scoped_command_line.GetProcessCommandLine(); |
| + } |
|
xhwang
2017/05/04 22:10:59
style: put methods to be above variables.
Vaage
2017/05/05 16:10:03
Done.
|
| +}; |
| + |
| +TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithSingleDomain) { |
| + // The request should need to ask for permission |
| + ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); |
| + |
| + // Add the switch value that the whitelist 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(whitelist.IsOriginWhitelisted(requestingDomain)); |
| +} |
| + |
| +TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagWithDomainList) { |
| + // The request should need to ask for permission |
| + ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); |
| + |
| + // Add the switch value that the whitelist 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(whitelist.IsOriginWhitelisted(requestingDomain)); |
| +} |
| + |
| +TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassWithFlagAndSubdomain) { |
| + // The request should need to ask for permission |
| + ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingSubDomain)); |
| + |
| + // Add the switch value that the whitelist 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(whitelist.IsOriginWhitelisted(requestingSubDomain)); |
| +} |
| + |
| +TEST_F(ProtectedMediaIdentifierWhitelistTest, BypassRequiresUserDataDir) { |
| + // The request should need to ask for permission |
| + ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); |
| + |
| + // Add the switch value that the whitelist reads from |
| + command_line->AppendSwitchASCII( |
| + switches::kDisableInfobarForProtectedMediaIdentifierForDomain, |
| + "example.com"); |
| + |
| + // The request should still need to ask for permission |
| + ASSERT_FALSE(whitelist.IsOriginWhitelisted(requestingDomain)); |
| + |
| + // Set the user data dir so the request should no longer need to ask for |
| + // permission |
| + 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.
|
| + |
| + // The request should no longer need to ask for permission |
| + ASSERT_TRUE(whitelist.IsOriginWhitelisted(requestingDomain)); |
| +} |