| Index: chrome/browser/extensions/extension_prefs_unittest.cc
|
| diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc
|
| index c8d1967a70a3efd26e5eb88d3d55f62c1198e218..164df2806449164ed6305e29a8c5db945d1c8bda 100644
|
| --- a/chrome/browser/extensions/extension_prefs_unittest.cc
|
| +++ b/chrome/browser/extensions/extension_prefs_unittest.cc
|
| @@ -144,6 +144,100 @@ class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest {
|
| };
|
| TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {}
|
|
|
| +// Tests the GrantPermissions / GetGrantedPermissions functions.
|
| +class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest {
|
| + public:
|
| + virtual void Initialize() {
|
| + extension_id_ = prefs_.AddExtensionAndReturnId("test");
|
| +
|
| + api_perm_set1_.insert("tabs");
|
| + api_perm_set1_.insert("bookmarks");
|
| + api_perm_set1_.insert("something_random");
|
| +
|
| + api_perm_set2_.insert("history");
|
| + api_perm_set2_.insert("unknown2");
|
| +
|
| + host_perm_set1_.insert("http://*.google.com/*");
|
| + host_perm_set1_.insert("http://example.com/*");
|
| +
|
| + host_perm_set2_.insert("https://*.google.com/*");
|
| + // with duplicate:
|
| + host_perm_set2_.insert("http://*.google.com/*");
|
| +
|
| + std::set_union(api_perm_set1_.begin(), api_perm_set1_.end(),
|
| + api_perm_set2_.begin(), api_perm_set2_.end(),
|
| + std::inserter(api_permissions_, api_permissions_.end()));
|
| +
|
| + std::set_union(host_perm_set1_.begin(), host_perm_set1_.end(),
|
| + host_perm_set2_.begin(), host_perm_set2_.end(),
|
| + std::inserter(host_permissions_, host_permissions_.end()));
|
| +
|
| + std::set<std::string> empty_set;
|
| + std::set<std::string> api_perms;
|
| + std::set<std::string> host_perms;
|
| +
|
| + // Make sure both granted api and host permissions start empty.
|
| + EXPECT_FALSE(prefs()->GetGrantedPermissions(extension_id_,
|
| + &api_perms,
|
| + &host_perms));
|
| +
|
| + EXPECT_TRUE(api_perms.empty());
|
| + EXPECT_TRUE(host_perms.empty());
|
| +
|
| +
|
| + // Add part of the api permissions.
|
| + prefs()->GrantPermissions(extension_id_, api_perm_set1_, empty_set);
|
| + EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_,
|
| + &api_perms,
|
| + &host_perms));
|
| + EXPECT_EQ(api_perm_set1_, api_perms);
|
| + EXPECT_TRUE(host_perms.empty());
|
| + host_perms.clear();
|
| + api_perms.clear();
|
| +
|
| + // Add part of the host permissions.
|
| + prefs()->GrantPermissions(extension_id_, empty_set, host_perm_set1_);
|
| + EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_,
|
| + &api_perms,
|
| + &host_perms));
|
| + EXPECT_EQ(api_perm_set1_, api_perms);
|
| + EXPECT_EQ(host_perm_set1_, host_perms);
|
| + host_perms.clear();
|
| + api_perms.clear();
|
| +
|
| + // Add the rest of both the api and host permissions.
|
| + prefs()->GrantPermissions(extension_id_, api_perm_set2_, host_perm_set2_);
|
| +
|
| + EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_,
|
| + &api_perms,
|
| + &host_perms));
|
| + EXPECT_EQ(api_permissions_, api_perms);
|
| + EXPECT_EQ(host_permissions_, host_perms);
|
| + }
|
| +
|
| + virtual void Verify() {
|
| + std::set<std::string> api_perms;
|
| + std::set<std::string> host_perms;
|
| +
|
| + EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_,
|
| + &api_perms,
|
| + &host_perms));
|
| + EXPECT_EQ(api_permissions_, api_perms);
|
| + EXPECT_EQ(host_permissions_, host_perms);
|
| + }
|
| +
|
| + private:
|
| + std::string extension_id_;
|
| + std::set<std::string> api_perm_set1_;
|
| + std::set<std::string> api_perm_set2_;
|
| + std::set<std::string> host_perm_set1_;
|
| + std::set<std::string> host_perm_set2_;
|
| +
|
| +
|
| + std::set<std::string> api_permissions_;
|
| + std::set<std::string> host_permissions_;
|
| +};
|
| +TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {}
|
|
|
| // Tests the GetVersionString function.
|
| class ExtensionPrefsVersionString : public ExtensionPrefsTest {
|
|
|