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 "extension_prefs_unittest.h" | 5 #include "extension_prefs_unittest.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
15 #include "chrome/browser/extensions/extension_pref_value_map.h" | 15 #include "chrome/browser/extensions/extension_pref_value_map.h" |
16 #include "chrome/browser/prefs/pref_change_registrar.h" | 16 #include "chrome/browser/prefs/pref_change_registrar.h" |
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/extensions/extension_manifest_constants.h" | 19 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 20 #include "chrome/common/extensions/permissions/permissions_info.h" |
20 #include "chrome/common/extensions/permissions/permission_set.h" | 21 #include "chrome/common/extensions/permissions/permission_set.h" |
21 #include "chrome/common/string_ordinal.h" | 22 #include "chrome/common/string_ordinal.h" |
22 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
23 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
24 #include "content/public/test/mock_notification_observer.h" | 25 #include "content/public/test/mock_notification_observer.h" |
25 | 26 |
26 using base::Time; | 27 using base::Time; |
27 using base::TimeDelta; | 28 using base::TimeDelta; |
28 using content::BrowserThread; | 29 using content::BrowserThread; |
29 | 30 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 256 |
256 private: | 257 private: |
257 scoped_refptr<Extension> extension; | 258 scoped_refptr<Extension> extension; |
258 }; | 259 }; |
259 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} | 260 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} |
260 | 261 |
261 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. | 262 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. |
262 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { | 263 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
263 public: | 264 public: |
264 virtual void Initialize() { | 265 virtual void Initialize() { |
| 266 scoped_refptr<APIPermissionDetail> detail; |
| 267 APIPermission* permission = |
| 268 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 269 |
265 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 270 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
266 | 271 |
267 api_perm_set1_.insert(APIPermission::kTab); | 272 api_perm_set1_.insert(APIPermission::kTab); |
268 api_perm_set1_.insert(APIPermission::kBookmark); | 273 api_perm_set1_.insert(APIPermission::kBookmark); |
| 274 detail = permission->CreateDetail(); |
| 275 { |
| 276 scoped_ptr<ListValue> value(new ListValue()); |
| 277 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 278 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 279 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 280 if (!detail->FromValue(value.get())) |
| 281 NOTREACHED(); |
| 282 } |
| 283 api_perm_set1_.insert(detail); |
269 | 284 |
270 api_perm_set2_.insert(APIPermission::kHistory); | 285 api_perm_set2_.insert(APIPermission::kHistory); |
271 | 286 |
272 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); | 287 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); |
273 AddPattern(&ehost_perm_set1_, "http://example.com/*"); | 288 AddPattern(&ehost_perm_set1_, "http://example.com/*"); |
274 AddPattern(&ehost_perm_set1_, "chrome://favicon/*"); | 289 AddPattern(&ehost_perm_set1_, "chrome://favicon/*"); |
275 | 290 |
276 AddPattern(&ehost_perm_set2_, "https://*.google.com/*"); | 291 AddPattern(&ehost_perm_set2_, "https://*.google.com/*"); |
277 // with duplicate: | 292 // with duplicate: |
278 AddPattern(&ehost_perm_set2_, "http://*.google.com/*"); | 293 AddPattern(&ehost_perm_set2_, "http://*.google.com/*"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 granted_permissions->scriptable_hosts()); | 358 granted_permissions->scriptable_hosts()); |
344 | 359 |
345 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, | 360 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, |
346 &effective_permissions_); | 361 &effective_permissions_); |
347 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 362 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
348 | 363 |
349 // Add the rest of the permissions. | 364 // Add the rest of the permissions. |
350 permissions = new PermissionSet( | 365 permissions = new PermissionSet( |
351 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_); | 366 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_); |
352 | 367 |
353 std::set_union(expected_apis.begin(), expected_apis.end(), | 368 APIPermissionSet::Union(expected_apis, api_perm_set2_, &api_permissions_); |
354 api_perm_set2_.begin(), api_perm_set2_.end(), | |
355 std::inserter(api_permissions_, api_permissions_.begin())); | |
356 | 369 |
357 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 370 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
358 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 371 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
359 EXPECT_TRUE(granted_permissions.get()); | 372 EXPECT_TRUE(granted_permissions.get()); |
360 EXPECT_FALSE(granted_permissions->IsEmpty()); | 373 EXPECT_FALSE(granted_permissions->IsEmpty()); |
361 EXPECT_EQ(api_permissions_, granted_permissions->apis()); | 374 EXPECT_EQ(api_permissions_, granted_permissions->apis()); |
362 EXPECT_EQ(ehost_permissions_, | 375 EXPECT_EQ(ehost_permissions_, |
363 granted_permissions->explicit_hosts()); | 376 granted_permissions->explicit_hosts()); |
364 EXPECT_EQ(shost_permissions_, | 377 EXPECT_EQ(shost_permissions_, |
365 granted_permissions->scriptable_hosts()); | 378 granted_permissions->scriptable_hosts()); |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 EXPECT_EQ(string16(), error16); | 1270 EXPECT_EQ(string16(), error16); |
1258 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); | 1271 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); |
1259 EXPECT_EQ(string16(), error16); | 1272 EXPECT_EQ(string16(), error16); |
1260 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); | 1273 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); |
1261 EXPECT_EQ(string16(), error16); | 1274 EXPECT_EQ(string16(), error16); |
1262 } | 1275 } |
1263 }; | 1276 }; |
1264 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} | 1277 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} |
1265 | 1278 |
1266 } // namespace extensions | 1279 } // namespace extensions |
OLD | NEW |