Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / extensions / permissions / settings_override_permission_unittest.cc
blobb2cbb4f36fecdf51e07d1742dcb264a91d44e846
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/chrome_manifest_test.h"
11 #include "extensions/common/manifest_constants.h"
12 #include "extensions/common/permissions/permission_message_test_util.h"
13 #include "extensions/common/permissions/permission_set.h"
14 #include "extensions/common/permissions/permissions_data.h"
15 #include "extensions/common/permissions/settings_override_permission.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace extensions {
20 namespace {
22 class SettingsOverridePermissionTest : public ChromeManifestTest {
23 protected:
24 enum Flags {
25 kHomepage = 1,
26 kStartupPages = 1 << 1,
27 kSearchProvider = 1 << 2,
30 scoped_refptr<Extension> GetPermissionSet(uint32 flags) {
31 base::DictionaryValue ext_manifest;
32 ext_manifest.SetString(manifest_keys::kName, "test");
33 ext_manifest.SetString(manifest_keys::kVersion, "0.1");
34 ext_manifest.SetInteger(manifest_keys::kManifestVersion, 2);
36 scoped_ptr<base::DictionaryValue> settings_override(
37 new base::DictionaryValue);
38 if (flags & kHomepage)
39 settings_override->SetString("homepage", "http://www.google.com");
40 if (flags & kStartupPages) {
41 scoped_ptr<base::ListValue> startup_pages(new base::ListValue);
42 startup_pages->AppendString("http://startup.com/startup.html");
43 settings_override->Set("startup_pages", startup_pages.release());
45 if (flags & kSearchProvider) {
46 scoped_ptr<base::DictionaryValue> search_provider(
47 new base::DictionaryValue);
48 search_provider->SetString("search_url", "http://google.com/search.html");
49 search_provider->SetString("name", "test");
50 search_provider->SetString("keyword", "lock");
51 search_provider->SetString("encoding", "UTF-8");
52 search_provider->SetBoolean("is_default", true);
53 search_provider->SetString("favicon_url",
54 "http://wikipedia.org/wiki/Favicon");
55 settings_override->Set("search_provider", search_provider.release());
57 ext_manifest.Set(
58 manifest_keys::kSettingsOverride, settings_override.release());
60 ManifestData manifest(&ext_manifest, "test");
61 return LoadAndExpectSuccess(manifest);
65 TEST_F(SettingsOverridePermissionTest, HomePage) {
66 scoped_refptr<Extension> extension(GetPermissionSet(kHomepage));
67 scoped_refptr<const PermissionSet> permission_set(
68 extension->permissions_data()->active_permissions());
70 #if defined(OS_WIN)
71 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
72 VerifyOnePermissionMessage(extension->permissions_data(),
73 "Change your home page to: google.com/");
74 #else
75 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
76 #endif
78 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
79 EXPECT_FALSE(permission_set->HasAPIPermission(
80 APIPermission::kSearchProvider));
83 TEST_F(SettingsOverridePermissionTest, StartupPages) {
84 scoped_refptr<Extension> extension(GetPermissionSet(kStartupPages));
85 scoped_refptr<const PermissionSet> permission_set(
86 extension->permissions_data()->active_permissions());
88 #if defined(OS_WIN)
89 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
90 VerifyOnePermissionMessage(
91 extension->permissions_data(),
92 "Change your start page to: startup.com/startup.html");
93 #else
94 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
95 #endif
97 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
98 EXPECT_FALSE(permission_set->HasAPIPermission(
99 APIPermission::kSearchProvider));
102 TEST_F(SettingsOverridePermissionTest, SearchSettings) {
103 scoped_refptr<Extension> extension(GetPermissionSet(kSearchProvider));
104 scoped_refptr<const PermissionSet> permission_set(
105 extension->permissions_data()->active_permissions());
107 #if defined(OS_WIN)
108 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
109 VerifyOnePermissionMessage(extension->permissions_data(),
110 "Change your search settings to: google.com");
111 #else
112 EXPECT_FALSE(
113 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
114 #endif
116 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
117 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
120 TEST_F(SettingsOverridePermissionTest, All) {
121 scoped_refptr<Extension> extension(GetPermissionSet(
122 kSearchProvider | kStartupPages | kHomepage));
123 scoped_refptr<const PermissionSet> permission_set(
124 extension->permissions_data()->active_permissions());
126 #if defined(OS_WIN)
127 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
128 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
129 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
130 #else
131 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
132 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
133 EXPECT_FALSE(
134 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
135 #endif
138 TEST_F(SettingsOverridePermissionTest, Some) {
139 scoped_refptr<Extension> extension(GetPermissionSet(
140 kSearchProvider | kHomepage));
141 scoped_refptr<const PermissionSet> permission_set(
142 extension->permissions_data()->active_permissions());
144 #if defined(OS_WIN)
145 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kHomepage));
146 EXPECT_TRUE(permission_set->HasAPIPermission(APIPermission::kSearchProvider));
147 #else
148 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kHomepage));
149 EXPECT_FALSE(
150 permission_set->HasAPIPermission(APIPermission::kSearchProvider));
151 #endif
153 EXPECT_FALSE(permission_set->HasAPIPermission(APIPermission::kStartupPages));
156 } // namespace
158 } // namespace extensions