forked from mindaptiv/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protected_media_identifier_permission_context_unittest.cc
75 lines (59 loc) · 2.67 KB
/
protected_media_identifier_permission_context_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 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_permission_context.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 ProtectedMediaIdentifierPermissionContextTest : public testing::Test {
public:
ProtectedMediaIdentifierPermissionContextTest()
: requesting_origin_("https://example.com"),
requesting_sub_domain_origin_("https://subdomain.example.com") {
command_line_ = scoped_command_line_.GetProcessCommandLine();
}
bool IsOriginWhitelisted(const GURL& origin) {
return ProtectedMediaIdentifierPermissionContext::IsOriginWhitelisted(
origin);
}
GURL requesting_origin_;
GURL requesting_sub_domain_origin_;
base::test::ScopedCommandLine scoped_command_line_;
base::CommandLine* command_line_;
};
TEST_F(ProtectedMediaIdentifierPermissionContextTest,
BypassWithFlagWithSingleDomain) {
// The request should need to ask for permission
ASSERT_FALSE(IsOriginWhitelisted(requesting_origin_));
// Add the switch value that the
// ProtectedMediaIdentifierPermissionContext reads from
command_line_->AppendSwitchASCII(
switches::kUnsafelyAllowProtectedMediaIdentifierForDomain, "example.com");
// The request should no longer need to ask for permission
ASSERT_TRUE(IsOriginWhitelisted(requesting_origin_));
}
TEST_F(ProtectedMediaIdentifierPermissionContextTest,
BypassWithFlagWithDomainList) {
// The request should need to ask for permission
ASSERT_FALSE(IsOriginWhitelisted(requesting_origin_));
// Add the switch value that the
// ProtectedMediaIdentifierPermissionContext reads from
command_line_->AppendSwitchASCII(
switches::kUnsafelyAllowProtectedMediaIdentifierForDomain,
"example.ca,example.com,example.edu");
// The request should no longer need to ask for permission
ASSERT_TRUE(IsOriginWhitelisted(requesting_origin_));
}
TEST_F(ProtectedMediaIdentifierPermissionContextTest,
BypassWithFlagAndSubdomain) {
// The request should need to ask for permission
ASSERT_FALSE(IsOriginWhitelisted(requesting_sub_domain_origin_));
// Add the switch value that the
// ProtectedMediaIdentifierPermissionContext reads from
command_line_->AppendSwitchASCII(
switches::kUnsafelyAllowProtectedMediaIdentifierForDomain, "example.com");
// The request should no longer need to ask for permission
ASSERT_TRUE(IsOriginWhitelisted(requesting_sub_domain_origin_));
}