| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 virtual void Verify() { | 138 virtual void Verify() { |
| 139 EXPECT_EQ(true, prefs()->DidExtensionEscalatePermissions(extension->id())); | 139 EXPECT_EQ(true, prefs()->DidExtensionEscalatePermissions(extension->id())); |
| 140 } | 140 } |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 scoped_refptr<Extension> extension; | 143 scoped_refptr<Extension> extension; |
| 144 }; | 144 }; |
| 145 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} | 145 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} |
| 146 | 146 |
| 147 // Tests the GrantPermissions / GetGrantedPermissions functions. |
| 148 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
| 149 public: |
| 150 virtual void Initialize() { |
| 151 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
| 152 |
| 153 api_perm_set1_.insert("tabs"); |
| 154 api_perm_set1_.insert("bookmarks"); |
| 155 api_perm_set1_.insert("something_random"); |
| 156 |
| 157 api_perm_set2_.insert("history"); |
| 158 api_perm_set2_.insert("unknown2"); |
| 159 |
| 160 host_perm_set1_.insert("http://*.google.com/*"); |
| 161 host_perm_set1_.insert("http://example.com/*"); |
| 162 |
| 163 host_perm_set2_.insert("https://*.google.com/*"); |
| 164 // with duplicate: |
| 165 host_perm_set2_.insert("http://*.google.com/*"); |
| 166 |
| 167 std::set_union(api_perm_set1_.begin(), api_perm_set1_.end(), |
| 168 api_perm_set2_.begin(), api_perm_set2_.end(), |
| 169 std::inserter(api_permissions_, api_permissions_.end())); |
| 170 |
| 171 std::set_union(host_perm_set1_.begin(), host_perm_set1_.end(), |
| 172 host_perm_set2_.begin(), host_perm_set2_.end(), |
| 173 std::inserter(host_permissions_, host_permissions_.end())); |
| 174 |
| 175 std::set<std::string> empty_set; |
| 176 std::set<std::string> api_perms; |
| 177 std::set<std::string> host_perms; |
| 178 |
| 179 // Make sure both granted api and host permissions start empty. |
| 180 EXPECT_FALSE(prefs()->GetGrantedPermissions(extension_id_, |
| 181 &api_perms, |
| 182 &host_perms)); |
| 183 |
| 184 EXPECT_TRUE(api_perms.empty()); |
| 185 EXPECT_TRUE(host_perms.empty()); |
| 186 |
| 187 |
| 188 // Add part of the api permissions. |
| 189 prefs()->GrantPermissions(extension_id_, api_perm_set1_, empty_set); |
| 190 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_, |
| 191 &api_perms, |
| 192 &host_perms)); |
| 193 EXPECT_EQ(api_perm_set1_, api_perms); |
| 194 EXPECT_TRUE(host_perms.empty()); |
| 195 host_perms.clear(); |
| 196 api_perms.clear(); |
| 197 |
| 198 // Add part of the host permissions. |
| 199 prefs()->GrantPermissions(extension_id_, empty_set, host_perm_set1_); |
| 200 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_, |
| 201 &api_perms, |
| 202 &host_perms)); |
| 203 EXPECT_EQ(api_perm_set1_, api_perms); |
| 204 EXPECT_EQ(host_perm_set1_, host_perms); |
| 205 host_perms.clear(); |
| 206 api_perms.clear(); |
| 207 |
| 208 // Add the rest of both the api and host permissions. |
| 209 prefs()->GrantPermissions(extension_id_, api_perm_set2_, host_perm_set2_); |
| 210 |
| 211 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_, |
| 212 &api_perms, |
| 213 &host_perms)); |
| 214 EXPECT_EQ(api_permissions_, api_perms); |
| 215 EXPECT_EQ(host_permissions_, host_perms); |
| 216 } |
| 217 |
| 218 virtual void Verify() { |
| 219 std::set<std::string> api_perms; |
| 220 std::set<std::string> host_perms; |
| 221 |
| 222 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_, |
| 223 &api_perms, |
| 224 &host_perms)); |
| 225 EXPECT_EQ(api_permissions_, api_perms); |
| 226 EXPECT_EQ(host_permissions_, host_perms); |
| 227 } |
| 228 |
| 229 private: |
| 230 std::string extension_id_; |
| 231 std::set<std::string> api_perm_set1_; |
| 232 std::set<std::string> api_perm_set2_; |
| 233 std::set<std::string> host_perm_set1_; |
| 234 std::set<std::string> host_perm_set2_; |
| 235 |
| 236 |
| 237 std::set<std::string> api_permissions_; |
| 238 std::set<std::string> host_permissions_; |
| 239 }; |
| 240 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} |
| 147 | 241 |
| 148 // Tests the GetVersionString function. | 242 // Tests the GetVersionString function. |
| 149 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 243 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
| 150 public: | 244 public: |
| 151 virtual void Initialize() { | 245 virtual void Initialize() { |
| 152 extension = prefs_.AddExtension("test"); | 246 extension = prefs_.AddExtension("test"); |
| 153 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); | 247 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); |
| 154 prefs()->OnExtensionUninstalled(extension->id(), | 248 prefs()->OnExtensionUninstalled(extension->id(), |
| 155 Extension::INTERNAL, false); | 249 Extension::INTERNAL, false); |
| 156 } | 250 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 EXPECT_EQ(launch_index + 1, new_launch_index); | 454 EXPECT_EQ(launch_index + 1, new_launch_index); |
| 361 | 455 |
| 362 // This extension doesn't exist, so it should return -1. | 456 // This extension doesn't exist, so it should return -1. |
| 363 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); | 457 EXPECT_EQ(-1, prefs()->GetAppLaunchIndex("foo")); |
| 364 } | 458 } |
| 365 | 459 |
| 366 private: | 460 private: |
| 367 scoped_refptr<Extension> extension_; | 461 scoped_refptr<Extension> extension_; |
| 368 }; | 462 }; |
| 369 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} | 463 TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} |
| OLD | NEW |