summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/permissions/permission_set_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/extensions/permissions/permission_set_unittest.cc')
-rw-r--r--chrome/common/extensions/permissions/permission_set_unittest.cc109
1 files changed, 39 insertions, 70 deletions
diff --git a/chrome/common/extensions/permissions/permission_set_unittest.cc b/chrome/common/extensions/permissions/permission_set_unittest.cc
index e684d35..b0b7235 100644
--- a/chrome/common/extensions/permissions/permission_set_unittest.cc
+++ b/chrome/common/extensions/permissions/permission_set_unittest.cc
@@ -751,12 +751,6 @@ TEST(PermissionsTest, PermissionMessages) {
const APIPermissionInfo* permission_info = i->info();
EXPECT_TRUE(permission_info != NULL);
- // Always skip permissions that cannot be in the manifest.
- scoped_ptr<const APIPermission> permission(
- permission_info->CreateAPIPermission());
- if (permission->ManifestEntryForbidden())
- continue;
-
if (skip.count(i->id())) {
EXPECT_EQ(PermissionMessage::kNone, permission_info->message_id())
<< "unexpected message_id for " << permission_info->name();
@@ -1014,15 +1008,12 @@ TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
ASSERT_EQ(0u, warnings.size());
}
-TEST(PermissionsTest, GetDistinctHostsForDisplay) {
- scoped_refptr<PermissionSet> perm_set;
- APIPermissionSet empty_perms;
+TEST(PermissionsTest, GetDistinctHosts) {
+ URLPatternSet explicit_hosts;
std::set<std::string> expected;
expected.insert("www.foo.com");
expected.insert("www.bar.com");
expected.insert("www.baz.com");
- URLPatternSet explicit_hosts;
- URLPatternSet scriptable_hosts;
{
SCOPED_TRACE("no dupes");
@@ -1034,9 +1025,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path"));
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1047,9 +1037,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1058,9 +1047,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
// Add a pattern that differs only by scheme. This should be filtered out.
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path"));
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1069,9 +1057,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
// Add some dupes by path.
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath"));
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1086,9 +1073,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
expected.insert("monkey.www.bar.com");
expected.insert("bar.com");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1117,9 +1103,8 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
expected.insert("www.foo.xyzzy");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
@@ -1130,15 +1115,16 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
expected.insert("*.google.com");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
{
SCOPED_TRACE("scriptable hosts");
+
+ APIPermissionSet empty_perms;
explicit_hosts.ClearPatterns();
- scriptable_hosts.ClearPatterns();
+ URLPatternSet scriptable_hosts;
expected.clear();
explicit_hosts.AddPattern(
@@ -1149,32 +1135,30 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay) {
expected.insert("*.google.com");
expected.insert("*.example.com");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ scoped_refptr<PermissionSet> perm_set(new PermissionSet(
+ empty_perms, explicit_hosts, scriptable_hosts));
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(perm_set->effective_hosts(),
+ true, true));
}
{
// We don't display warnings for file URLs because they are off by default.
SCOPED_TRACE("file urls");
+
explicit_hosts.ClearPatterns();
- scriptable_hosts.ClearPatterns();
expected.clear();
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_FILE, "file:///*"));
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
}
-TEST(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
- scoped_refptr<PermissionSet> perm_set;
- APIPermissionSet empty_perms;
+TEST(PermissionsTest, GetDistinctHosts_ComIsBestRcd) {
URLPatternSet explicit_hosts;
- URLPatternSet scriptable_hosts;
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
explicit_hosts.AddPattern(
@@ -1190,16 +1174,12 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
std::set<std::string> expected;
expected.insert("www.foo.com");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
-TEST(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
- scoped_refptr<PermissionSet> perm_set;
- APIPermissionSet empty_perms;
+TEST(PermissionsTest, GetDistinctHosts_NetIs2ndBestRcd) {
URLPatternSet explicit_hosts;
- URLPatternSet scriptable_hosts;
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
explicit_hosts.AddPattern(
@@ -1214,17 +1194,12 @@ TEST(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
std::set<std::string> expected;
expected.insert("www.foo.net");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
-TEST(PermissionsTest,
- GetDistinctHostsForDisplay_OrgIs3rdBestRcd) {
- scoped_refptr<PermissionSet> perm_set;
- APIPermissionSet empty_perms;
+TEST(PermissionsTest, GetDistinctHosts_OrgIs3rdBestRcd) {
URLPatternSet explicit_hosts;
- URLPatternSet scriptable_hosts;
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
explicit_hosts.AddPattern(
@@ -1238,17 +1213,12 @@ TEST(PermissionsTest,
std::set<std::string> expected;
expected.insert("www.foo.org");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
-TEST(PermissionsTest,
- GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) {
- scoped_refptr<PermissionSet> perm_set;
- APIPermissionSet empty_perms;
+TEST(PermissionsTest, GetDistinctHosts_FirstInListIs4thBestRcd) {
URLPatternSet explicit_hosts;
- URLPatternSet scriptable_hosts;
explicit_hosts.AddPattern(
URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
// No http://www.foo.org/path
@@ -1261,9 +1231,8 @@ TEST(PermissionsTest,
std::set<std::string> expected;
expected.insert("www.foo.ca");
- perm_set = new PermissionSet(
- empty_perms, explicit_hosts, scriptable_hosts);
- EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
+ EXPECT_EQ(expected,
+ PermissionSet::GetDistinctHosts(explicit_hosts, true, true));
}
TEST(PermissionsTest, HasLessHostPrivilegesThan) {