Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / settings_override_permission_unittest.cc
blobd5b9a0457dca2fa290d88856cc733fc65f89aa20
1 // Copyright 2013 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.
5 // These tests make sure SettingsOverridePermission values are set correctly.
7 #include "base/basictypes.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
11 #include "extensions/common/manifest_constants.h"
12 #include "extensions/common/permissions/permission_set.h"
13 #include "extensions/common/permissions/permissions_data.h"
14 #include "extensions/common/permissions/settings_override_permission.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace extensions {
19 namespace {
21 class SettingsOverridePermissionTest : public ExtensionManifestTest {
22 protected:
23 enum Flags {
24 kHomepage = 1,
25 kStartupPages = 1 << 1,
26 kSearchProvider = 1 << 2,
29 scoped_refptr<Extension> GetPermissionSet(uint32 flags) {
30 base::DictionaryValue ext_manifest;
31 ext_manifest.SetString(manifest_keys::kName, "test");
32 ext_manifest.SetString(manifest_keys::kVersion, "0.1");
33 ext_manifest.SetInteger(manifest_keys::kManifestVersion, 2);
35 scoped_ptr<base::DictionaryValue> settings_override(
36 new base::DictionaryValue);
37 if (flags & kHomepage)
38 settings_override->SetString("homepage", "http://www.google.com");
39 if (flags & kStartupPages) {
40 scoped_ptr<base::ListValue> startup_pages(new base::ListValue);
41 startup_pages->AppendString("http://startup.com/startup.html");
42 settings_override->Set("startup_pages", startup_pages.release());
44 if (flags & kSearchProvider) {
45 scoped_ptr<base::DictionaryValue> search_provider(
46 new base::DictionaryValue);
47 search_provider->SetString("search_url", "http://google.com/search.html");
48 search_provider->SetString("name", "test");
49 search_provider->SetString("keyword", "lock");
50 search_provider->SetString("encoding", "UTF-8");
51 search_provider->SetBoolean("is_default", true);
52 search_provider->SetString("favicon_url",
53 "http://wikipedia.org/wiki/Favicon");
54 settings_override->Set("search_provider", search_provider.release());
56 ext_manifest.Set(
57 manifest_keys::kSettingsOverride, settings_override.release());
59 Manifest manifest(&ext_manifest, "test");
60 return LoadAndExpectSuccess(manifest);
64 TEST_F(SettingsOverridePermissionTest, HomePage) {
65 scoped_refptr<Extension> extension(GetPermissionSet(kHomepage));
66 scoped_refptr<const PermissionSet> permission_set(
67 extension->GetActivePermissions());
69 #if defined(OS_WIN)
70 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
71 std::vector<base::string16> warnings =
72 PermissionsData::GetPermissionMessageStrings(extension.get());
73 ASSERT_EQ(1u, warnings.size());
74 EXPECT_EQ("Change your home page to: google.com/",
75 base::UTF16ToUTF8(warnings[0]));
77 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
78 EXPECT_FALSE(permission_set->HasAPIPermission(
79 APIPermission::kSearchProvider));
80 #else
81 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
82 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
83 EXPECT_FALSE(
84 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
85 #endif
88 TEST_F(SettingsOverridePermissionTest, StartupPages) {
89 scoped_refptr<Extension> extension(GetPermissionSet(kStartupPages));
90 scoped_refptr<const PermissionSet> permission_set(
91 extension->GetActivePermissions());
93 #if defined(OS_WIN)
94 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
95 std::vector<base::string16> warnings =
96 PermissionsData::GetPermissionMessageStrings(extension.get());
97 ASSERT_EQ(1u, warnings.size());
98 EXPECT_EQ("Change your start page to: startup.com/startup.html",
99 base::UTF16ToUTF8(warnings[0]));
101 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
102 EXPECT_FALSE(permission_set->HasAPIPermission(
103 APIPermission::kSearchProvider));
104 #else
105 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
106 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
107 EXPECT_FALSE(
108 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
109 #endif
112 TEST_F(SettingsOverridePermissionTest, SearchSettings) {
113 scoped_refptr<Extension> extension(GetPermissionSet(kSearchProvider));
114 scoped_refptr<const PermissionSet> permission_set(
115 extension->GetActivePermissions());
117 #if defined(OS_WIN)
118 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
119 std::vector<base::string16> warnings =
120 PermissionsData::GetPermissionMessageStrings(extension.get());
121 ASSERT_EQ(1u, warnings.size());
122 EXPECT_EQ("Change your search settings to: google.com",
123 base::UTF16ToUTF8(warnings[0]));
125 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
126 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
127 #else
128 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
129 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
130 EXPECT_FALSE(
131 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
132 #endif
135 TEST_F(SettingsOverridePermissionTest, All) {
136 scoped_refptr<Extension> extension(GetPermissionSet(
137 kSearchProvider | kStartupPages | kHomepage));
138 scoped_refptr<const PermissionSet> permission_set(
139 extension->GetActivePermissions());
141 #if defined(OS_WIN)
142 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
143 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
144 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
145 #else
146 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
147 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
148 EXPECT_FALSE(
149 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
150 #endif
153 TEST_F(SettingsOverridePermissionTest, Some) {
154 scoped_refptr<Extension> extension(GetPermissionSet(
155 kSearchProvider | kHomepage));
156 scoped_refptr<const PermissionSet> permission_set(
157 extension->GetActivePermissions());
159 #if defined(OS_WIN)
160 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
161 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
162 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
163 #else
164 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
165 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
166 EXPECT_FALSE(
167 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
168 #endif
171 } // namespace
173 } // namespace extensions