Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/extensions/permissions_updater_unittest.cc

Issue 314113010: Remove deprecated permissions functions from Extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_service_unittest.h" 13 #include "chrome/browser/extensions/extension_service_unittest.h"
14 #include "chrome/browser/extensions/permissions_updater.h" 14 #include "chrome/browser/extensions/permissions_updater.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/extension_test_util.h" 16 #include "chrome/common/extensions/extension_test_util.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "extensions/browser/extension_prefs.h" 21 #include "extensions/browser/extension_prefs.h"
22 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
23 #include "extensions/common/permissions/permission_set.h" 23 #include "extensions/common/permissions/permission_set.h"
24 #include "extensions/common/permissions/permissions_data.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 using extension_test_util::LoadManifest; 27 using extension_test_util::LoadManifest;
27 28
28 namespace extensions { 29 namespace extensions {
29 30
30 namespace { 31 namespace {
31 32
32 // A helper class that listens for NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED. 33 // A helper class that listens for NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED.
33 class PermissionsUpdaterListener : public content::NotificationObserver { 34 class PermissionsUpdaterListener : public content::NotificationObserver {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ManifestPermissionSet empty_manifest_permissions; 124 ManifestPermissionSet empty_manifest_permissions;
124 125
125 URLPatternSet default_hosts; 126 URLPatternSet default_hosts;
126 AddPattern(&default_hosts, "http://a.com/*"); 127 AddPattern(&default_hosts, "http://a.com/*");
127 scoped_refptr<PermissionSet> default_permissions = 128 scoped_refptr<PermissionSet> default_permissions =
128 new PermissionSet(default_apis, empty_manifest_permissions, 129 new PermissionSet(default_apis, empty_manifest_permissions,
129 default_hosts, URLPatternSet()); 130 default_hosts, URLPatternSet());
130 131
131 // Make sure it loaded properly. 132 // Make sure it loaded properly.
132 scoped_refptr<const PermissionSet> permissions = 133 scoped_refptr<const PermissionSet> permissions =
133 extension->GetActivePermissions(); 134 extension->permissions_data()->active_permissions();
134 ASSERT_EQ(*default_permissions.get(), 135 ASSERT_EQ(*default_permissions.get(),
135 *extension->GetActivePermissions().get()); 136 *extension->permissions_data()->active_permissions().get());
136 137
137 // Add a few permissions. 138 // Add a few permissions.
138 APIPermissionSet apis; 139 APIPermissionSet apis;
139 apis.insert(APIPermission::kTab); 140 apis.insert(APIPermission::kTab);
140 apis.insert(APIPermission::kNotification); 141 apis.insert(APIPermission::kNotification);
141 URLPatternSet hosts; 142 URLPatternSet hosts;
142 AddPattern(&hosts, "http://*.c.com/*"); 143 AddPattern(&hosts, "http://*.c.com/*");
143 144
144 scoped_refptr<PermissionSet> delta = 145 scoped_refptr<PermissionSet> delta =
145 new PermissionSet(apis, empty_manifest_permissions, 146 new PermissionSet(apis, empty_manifest_permissions,
146 hosts, URLPatternSet()); 147 hosts, URLPatternSet());
147 148
148 PermissionsUpdaterListener listener; 149 PermissionsUpdaterListener listener;
149 PermissionsUpdater updater(profile_.get()); 150 PermissionsUpdater updater(profile_.get());
150 updater.AddPermissions(extension.get(), delta.get()); 151 updater.AddPermissions(extension.get(), delta.get());
151 152
152 listener.Wait(); 153 listener.Wait();
153 154
154 // Verify that the permission notification was sent correctly. 155 // Verify that the permission notification was sent correctly.
155 ASSERT_TRUE(listener.received_notification()); 156 ASSERT_TRUE(listener.received_notification());
156 ASSERT_EQ(extension, listener.extension()); 157 ASSERT_EQ(extension, listener.extension());
157 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason()); 158 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason());
158 ASSERT_EQ(*delta.get(), *listener.permissions()); 159 ASSERT_EQ(*delta.get(), *listener.permissions());
159 160
160 // Make sure the extension's active permissions reflect the change. 161 // Make sure the extension's active permissions reflect the change.
161 scoped_refptr<PermissionSet> active_permissions = 162 scoped_refptr<PermissionSet> active_permissions =
162 PermissionSet::CreateUnion(default_permissions.get(), delta.get()); 163 PermissionSet::CreateUnion(default_permissions.get(), delta.get());
163 ASSERT_EQ(*active_permissions.get(), 164 ASSERT_EQ(*active_permissions.get(),
164 *extension->GetActivePermissions().get()); 165 *extension->permissions_data()->active_permissions().get());
165 166
166 // Verify that the new granted and active permissions were also stored 167 // Verify that the new granted and active permissions were also stored
167 // in the extension preferences. In this case, the granted permissions should 168 // in the extension preferences. In this case, the granted permissions should
168 // be equal to the active permissions. 169 // be equal to the active permissions.
169 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get()); 170 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_.get());
170 scoped_refptr<PermissionSet> granted_permissions = 171 scoped_refptr<PermissionSet> granted_permissions =
171 active_permissions; 172 active_permissions;
172 173
173 scoped_refptr<PermissionSet> from_prefs = 174 scoped_refptr<PermissionSet> from_prefs =
174 prefs->GetActivePermissions(extension->id()); 175 prefs->GetActivePermissions(extension->id());
(...skipping 15 matching lines...) Expand all
190 // Verify that the notification was correct. 191 // Verify that the notification was correct.
191 ASSERT_TRUE(listener.received_notification()); 192 ASSERT_TRUE(listener.received_notification());
192 ASSERT_EQ(extension, listener.extension()); 193 ASSERT_EQ(extension, listener.extension());
193 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); 194 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason());
194 ASSERT_EQ(*delta.get(), *listener.permissions()); 195 ASSERT_EQ(*delta.get(), *listener.permissions());
195 196
196 // Make sure the extension's active permissions reflect the change. 197 // Make sure the extension's active permissions reflect the change.
197 active_permissions = 198 active_permissions =
198 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); 199 PermissionSet::CreateDifference(active_permissions.get(), delta.get());
199 ASSERT_EQ(*active_permissions.get(), 200 ASSERT_EQ(*active_permissions.get(),
200 *extension->GetActivePermissions().get()); 201 *extension->permissions_data()->active_permissions().get());
201 202
202 // Verify that the extension prefs hold the new active permissions and the 203 // Verify that the extension prefs hold the new active permissions and the
203 // same granted permissions. 204 // same granted permissions.
204 from_prefs = prefs->GetActivePermissions(extension->id()); 205 from_prefs = prefs->GetActivePermissions(extension->id());
205 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); 206 ASSERT_EQ(*active_permissions.get(), *from_prefs.get());
206 207
207 from_prefs = prefs->GetGrantedPermissions(extension->id()); 208 from_prefs = prefs->GetGrantedPermissions(extension->id());
208 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get()); 209 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get());
209 } 210 }
210 211
211 } // namespace extensions 212 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/permissions_updater.cc ('k') | chrome/browser/extensions/suggest_permission_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698