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

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

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 APIPermissionSet default_apis; 120 APIPermissionSet default_apis;
121 default_apis.insert(APIPermission::kManagement); 121 default_apis.insert(APIPermission::kManagement);
122 URLPatternSet default_hosts; 122 URLPatternSet default_hosts;
123 AddPattern(&default_hosts, "http://a.com/*"); 123 AddPattern(&default_hosts, "http://a.com/*");
124 scoped_refptr<PermissionSet> default_permissions = 124 scoped_refptr<PermissionSet> default_permissions =
125 new PermissionSet(default_apis, default_hosts, URLPatternSet()); 125 new PermissionSet(default_apis, default_hosts, URLPatternSet());
126 126
127 // Make sure it loaded properly. 127 // Make sure it loaded properly.
128 scoped_refptr<const PermissionSet> permissions = 128 scoped_refptr<const PermissionSet> permissions =
129 extension->GetActivePermissions(); 129 extension->GetActivePermissions();
130 ASSERT_EQ(*default_permissions.get(), *extension->GetActivePermissions()); 130 ASSERT_EQ(*default_permissions.get(),
131 *extension->GetActivePermissions().get());
131 132
132 // Add a few permissions. 133 // Add a few permissions.
133 APIPermissionSet apis; 134 APIPermissionSet apis;
134 apis.insert(APIPermission::kTab); 135 apis.insert(APIPermission::kTab);
135 apis.insert(APIPermission::kNotification); 136 apis.insert(APIPermission::kNotification);
136 URLPatternSet hosts; 137 URLPatternSet hosts;
137 AddPattern(&hosts, "http://*.c.com/*"); 138 AddPattern(&hosts, "http://*.c.com/*");
138 139
139 scoped_refptr<PermissionSet> delta = 140 scoped_refptr<PermissionSet> delta =
140 new PermissionSet(apis, hosts, URLPatternSet()); 141 new PermissionSet(apis, hosts, URLPatternSet());
141 142
142 PermissionsUpdaterListener listener; 143 PermissionsUpdaterListener listener;
143 PermissionsUpdater updater(profile_.get()); 144 PermissionsUpdater updater(profile_.get());
144 updater.AddPermissions(extension.get(), delta.get()); 145 updater.AddPermissions(extension.get(), delta.get());
145 146
146 listener.Wait(); 147 listener.Wait();
147 148
148 // Verify that the permission notification was sent correctly. 149 // Verify that the permission notification was sent correctly.
149 ASSERT_TRUE(listener.received_notification()); 150 ASSERT_TRUE(listener.received_notification());
150 ASSERT_EQ(extension, listener.extension()); 151 ASSERT_EQ(extension, listener.extension());
151 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason()); 152 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason());
152 ASSERT_EQ(*delta.get(), *listener.permissions()); 153 ASSERT_EQ(*delta.get(), *listener.permissions());
153 154
154 // Make sure the extension's active permissions reflect the change. 155 // Make sure the extension's active permissions reflect the change.
155 scoped_refptr<PermissionSet> active_permissions = 156 scoped_refptr<PermissionSet> active_permissions =
156 PermissionSet::CreateUnion(default_permissions.get(), delta.get()); 157 PermissionSet::CreateUnion(default_permissions.get(), delta.get());
157 ASSERT_EQ(*active_permissions.get(), *extension->GetActivePermissions()); 158 ASSERT_EQ(*active_permissions.get(),
159 *extension->GetActivePermissions().get());
158 160
159 // Verify that the new granted and active permissions were also stored 161 // Verify that the new granted and active permissions were also stored
160 // in the extension preferences. In this case, the granted permissions should 162 // in the extension preferences. In this case, the granted permissions should
161 // be equal to the active permissions. 163 // be equal to the active permissions.
162 ExtensionPrefs* prefs = service_->extension_prefs(); 164 ExtensionPrefs* prefs = service_->extension_prefs();
163 scoped_refptr<PermissionSet> granted_permissions = 165 scoped_refptr<PermissionSet> granted_permissions =
164 active_permissions; 166 active_permissions;
165 167
166 scoped_refptr<PermissionSet> from_prefs = 168 scoped_refptr<PermissionSet> from_prefs =
167 prefs->GetActivePermissions(extension->id()); 169 prefs->GetActivePermissions(extension->id());
(...skipping 13 matching lines...) Expand all
181 183
182 // Verify that the notification was correct. 184 // Verify that the notification was correct.
183 ASSERT_TRUE(listener.received_notification()); 185 ASSERT_TRUE(listener.received_notification());
184 ASSERT_EQ(extension, listener.extension()); 186 ASSERT_EQ(extension, listener.extension());
185 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); 187 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason());
186 ASSERT_EQ(*delta.get(), *listener.permissions()); 188 ASSERT_EQ(*delta.get(), *listener.permissions());
187 189
188 // Make sure the extension's active permissions reflect the change. 190 // Make sure the extension's active permissions reflect the change.
189 active_permissions = 191 active_permissions =
190 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); 192 PermissionSet::CreateDifference(active_permissions.get(), delta.get());
191 ASSERT_EQ(*active_permissions.get(), *extension->GetActivePermissions()); 193 ASSERT_EQ(*active_permissions.get(),
194 *extension->GetActivePermissions().get());
192 195
193 // Verify that the extension prefs hold the new active permissions and the 196 // Verify that the extension prefs hold the new active permissions and the
194 // same granted permissions. 197 // same granted permissions.
195 from_prefs = prefs->GetActivePermissions(extension->id()); 198 from_prefs = prefs->GetActivePermissions(extension->id());
196 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); 199 ASSERT_EQ(*active_permissions.get(), *from_prefs.get());
197 200
198 from_prefs = prefs->GetGrantedPermissions(extension->id()); 201 from_prefs = prefs->GetGrantedPermissions(extension->id());
199 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get()); 202 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get());
200 } 203 }
201 204
202 } // namespace extensions 205 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/permissions_updater.cc ('k') | chrome/browser/extensions/sandboxed_unpacker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698