| OLD | NEW |
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // AddPermissions. | 112 // AddPermissions. |
| 113 TEST_F(PermissionsUpdaterTest, AddAndRemovePermissions) { | 113 TEST_F(PermissionsUpdaterTest, AddAndRemovePermissions) { |
| 114 InitializeEmptyExtensionService(); | 114 InitializeEmptyExtensionService(); |
| 115 | 115 |
| 116 // Load the test extension. | 116 // Load the test extension. |
| 117 scoped_refptr<Extension> extension = LoadOurManifest(); | 117 scoped_refptr<Extension> extension = LoadOurManifest(); |
| 118 ASSERT_TRUE(extension.get()); | 118 ASSERT_TRUE(extension.get()); |
| 119 | 119 |
| 120 APIPermissionSet default_apis; | 120 APIPermissionSet default_apis; |
| 121 default_apis.insert(APIPermission::kManagement); | 121 default_apis.insert(APIPermission::kManagement); |
| 122 ManifestPermissionSet empty_manifest_permissions; |
| 123 |
| 122 URLPatternSet default_hosts; | 124 URLPatternSet default_hosts; |
| 123 AddPattern(&default_hosts, "http://a.com/*"); | 125 AddPattern(&default_hosts, "http://a.com/*"); |
| 124 scoped_refptr<PermissionSet> default_permissions = | 126 scoped_refptr<PermissionSet> default_permissions = |
| 125 new PermissionSet(default_apis, default_hosts, URLPatternSet()); | 127 new PermissionSet(default_apis, empty_manifest_permissions, |
| 128 default_hosts, URLPatternSet()); |
| 126 | 129 |
| 127 // Make sure it loaded properly. | 130 // Make sure it loaded properly. |
| 128 scoped_refptr<const PermissionSet> permissions = | 131 scoped_refptr<const PermissionSet> permissions = |
| 129 extension->GetActivePermissions(); | 132 extension->GetActivePermissions(); |
| 130 ASSERT_EQ(*default_permissions.get(), | 133 ASSERT_EQ(*default_permissions.get(), |
| 131 *extension->GetActivePermissions().get()); | 134 *extension->GetActivePermissions().get()); |
| 132 | 135 |
| 133 // Add a few permissions. | 136 // Add a few permissions. |
| 134 APIPermissionSet apis; | 137 APIPermissionSet apis; |
| 135 apis.insert(APIPermission::kTab); | 138 apis.insert(APIPermission::kTab); |
| 136 apis.insert(APIPermission::kNotification); | 139 apis.insert(APIPermission::kNotification); |
| 137 URLPatternSet hosts; | 140 URLPatternSet hosts; |
| 138 AddPattern(&hosts, "http://*.c.com/*"); | 141 AddPattern(&hosts, "http://*.c.com/*"); |
| 139 | 142 |
| 140 scoped_refptr<PermissionSet> delta = | 143 scoped_refptr<PermissionSet> delta = |
| 141 new PermissionSet(apis, hosts, URLPatternSet()); | 144 new PermissionSet(apis, empty_manifest_permissions, |
| 145 hosts, URLPatternSet()); |
| 142 | 146 |
| 143 PermissionsUpdaterListener listener; | 147 PermissionsUpdaterListener listener; |
| 144 PermissionsUpdater updater(profile_.get()); | 148 PermissionsUpdater updater(profile_.get()); |
| 145 updater.AddPermissions(extension.get(), delta.get()); | 149 updater.AddPermissions(extension.get(), delta.get()); |
| 146 | 150 |
| 147 listener.Wait(); | 151 listener.Wait(); |
| 148 | 152 |
| 149 // Verify that the permission notification was sent correctly. | 153 // Verify that the permission notification was sent correctly. |
| 150 ASSERT_TRUE(listener.received_notification()); | 154 ASSERT_TRUE(listener.received_notification()); |
| 151 ASSERT_EQ(extension, listener.extension()); | 155 ASSERT_EQ(extension, listener.extension()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 scoped_refptr<PermissionSet> from_prefs = | 172 scoped_refptr<PermissionSet> from_prefs = |
| 169 prefs->GetActivePermissions(extension->id()); | 173 prefs->GetActivePermissions(extension->id()); |
| 170 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); | 174 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); |
| 171 | 175 |
| 172 from_prefs = prefs->GetGrantedPermissions(extension->id()); | 176 from_prefs = prefs->GetGrantedPermissions(extension->id()); |
| 173 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); | 177 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); |
| 174 | 178 |
| 175 // In the second part of the test, we'll remove the permissions that we | 179 // In the second part of the test, we'll remove the permissions that we |
| 176 // just added except for 'notification'. | 180 // just added except for 'notification'. |
| 177 apis.erase(APIPermission::kNotification); | 181 apis.erase(APIPermission::kNotification); |
| 178 delta = new PermissionSet(apis, hosts, URLPatternSet()); | 182 delta = new PermissionSet(apis, empty_manifest_permissions, |
| 183 hosts, URLPatternSet()); |
| 179 | 184 |
| 180 listener.Reset(); | 185 listener.Reset(); |
| 181 updater.RemovePermissions(extension.get(), delta.get()); | 186 updater.RemovePermissions(extension.get(), delta.get()); |
| 182 listener.Wait(); | 187 listener.Wait(); |
| 183 | 188 |
| 184 // Verify that the notification was correct. | 189 // Verify that the notification was correct. |
| 185 ASSERT_TRUE(listener.received_notification()); | 190 ASSERT_TRUE(listener.received_notification()); |
| 186 ASSERT_EQ(extension, listener.extension()); | 191 ASSERT_EQ(extension, listener.extension()); |
| 187 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); | 192 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); |
| 188 ASSERT_EQ(*delta.get(), *listener.permissions()); | 193 ASSERT_EQ(*delta.get(), *listener.permissions()); |
| 189 | 194 |
| 190 // Make sure the extension's active permissions reflect the change. | 195 // Make sure the extension's active permissions reflect the change. |
| 191 active_permissions = | 196 active_permissions = |
| 192 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); | 197 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); |
| 193 ASSERT_EQ(*active_permissions.get(), | 198 ASSERT_EQ(*active_permissions.get(), |
| 194 *extension->GetActivePermissions().get()); | 199 *extension->GetActivePermissions().get()); |
| 195 | 200 |
| 196 // Verify that the extension prefs hold the new active permissions and the | 201 // Verify that the extension prefs hold the new active permissions and the |
| 197 // same granted permissions. | 202 // same granted permissions. |
| 198 from_prefs = prefs->GetActivePermissions(extension->id()); | 203 from_prefs = prefs->GetActivePermissions(extension->id()); |
| 199 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); | 204 ASSERT_EQ(*active_permissions.get(), *from_prefs.get()); |
| 200 | 205 |
| 201 from_prefs = prefs->GetGrantedPermissions(extension->id()); | 206 from_prefs = prefs->GetGrantedPermissions(extension->id()); |
| 202 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get()); | 207 ASSERT_EQ(*granted_permissions.get(), *from_prefs.get()); |
| 203 } | 208 } |
| 204 | 209 |
| 205 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |