| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const char kDefaultPref3[] = "default pref 3"; | 37 const char kDefaultPref3[] = "default pref 3"; |
| 38 const char kDefaultPref4[] = "default pref 4"; | 38 const char kDefaultPref4[] = "default pref 4"; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 42 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 43 int schemes = URLPattern::SCHEME_ALL; | 43 int schemes = URLPattern::SCHEME_ALL; |
| 44 extent->AddPattern(URLPattern(schemes, pattern)); | 44 extent->AddPattern(URLPattern(schemes, pattern)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static void AssertEqualExtents(const URLPatternSet& extent1, | |
| 48 const URLPatternSet& extent2) { | |
| 49 URLPatternList patterns1 = extent1.patterns(); | |
| 50 URLPatternList patterns2 = extent2.patterns(); | |
| 51 EXPECT_EQ(patterns1.size(), patterns2.size()); | |
| 52 | |
| 53 std::set<std::string> strings1; | |
| 54 for (size_t i = 0; i < patterns1.size(); ++i) | |
| 55 strings1.insert(patterns1.at(i).GetAsString()); | |
| 56 | |
| 57 std::set<std::string> strings2; | |
| 58 for (size_t i = 0; i < patterns2.size(); ++i) | |
| 59 strings2.insert(patterns2.at(i).GetAsString()); | |
| 60 | |
| 61 EXPECT_EQ(strings1, strings2); | |
| 62 } | |
| 63 | |
| 64 // Base class for tests. | 47 // Base class for tests. |
| 65 class ExtensionPrefsTest : public testing::Test { | 48 class ExtensionPrefsTest : public testing::Test { |
| 66 public: | 49 public: |
| 67 ExtensionPrefsTest() | 50 ExtensionPrefsTest() |
| 68 : ui_thread_(BrowserThread::UI, &message_loop_), | 51 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 69 file_thread_(BrowserThread::FILE, &message_loop_) { | 52 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 70 } | 53 } |
| 71 | 54 |
| 72 // This function will get called once, and is the right place to do operations | 55 // This function will get called once, and is the right place to do operations |
| 73 // on ExtensionPrefs that write data. | 56 // on ExtensionPrefs that write data. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 granted_permissions.reset(); | 241 granted_permissions.reset(); |
| 259 | 242 |
| 260 // Add part of the explicit host permissions. | 243 // Add part of the explicit host permissions. |
| 261 permissions.reset(new ExtensionPermissionSet( | 244 permissions.reset(new ExtensionPermissionSet( |
| 262 empty_set, ehost_perm_set1_, empty_extent)); | 245 empty_set, ehost_perm_set1_, empty_extent)); |
| 263 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 246 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 264 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); | 247 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); |
| 265 EXPECT_FALSE(granted_permissions->IsEmpty()); | 248 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 266 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 249 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 267 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 250 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 268 AssertEqualExtents(ehost_perm_set1_, | 251 EXPECT_EQ(ehost_perm_set1_, |
| 269 granted_permissions->explicit_hosts()); | 252 granted_permissions->explicit_hosts()); |
| 270 AssertEqualExtents(ehost_perm_set1_, | 253 EXPECT_EQ(ehost_perm_set1_, |
| 271 granted_permissions->effective_hosts()); | 254 granted_permissions->effective_hosts()); |
| 272 | 255 |
| 273 // Add part of the scriptable host permissions. | 256 // Add part of the scriptable host permissions. |
| 274 permissions.reset(new ExtensionPermissionSet( | 257 permissions.reset(new ExtensionPermissionSet( |
| 275 empty_set, empty_extent, shost_perm_set1_)); | 258 empty_set, empty_extent, shost_perm_set1_)); |
| 276 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 259 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 277 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); | 260 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); |
| 278 EXPECT_FALSE(granted_permissions->IsEmpty()); | 261 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 279 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 262 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 280 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 263 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 281 AssertEqualExtents(ehost_perm_set1_, | 264 EXPECT_EQ(ehost_perm_set1_, |
| 282 granted_permissions->explicit_hosts()); | 265 granted_permissions->explicit_hosts()); |
| 283 AssertEqualExtents(shost_perm_set1_, | 266 EXPECT_EQ(shost_perm_set1_, |
| 284 granted_permissions->scriptable_hosts()); | 267 granted_permissions->scriptable_hosts()); |
| 268 |
| 285 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, | 269 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, |
| 286 &effective_permissions_); | 270 &effective_permissions_); |
| 287 AssertEqualExtents(effective_permissions_, | 271 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
| 288 granted_permissions->effective_hosts()); | |
| 289 | 272 |
| 290 // Add the rest of both the permissions. | 273 // Add the rest of both the permissions. |
| 291 permissions.reset(new ExtensionPermissionSet( | 274 permissions.reset(new ExtensionPermissionSet( |
| 292 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_)); | 275 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_)); |
| 293 | 276 |
| 294 std::set_union(expected_apis.begin(), expected_apis.end(), | 277 std::set_union(expected_apis.begin(), expected_apis.end(), |
| 295 api_perm_set2_.begin(), api_perm_set2_.end(), | 278 api_perm_set2_.begin(), api_perm_set2_.end(), |
| 296 std::inserter(api_permissions_, api_permissions_.begin())); | 279 std::inserter(api_permissions_, api_permissions_.begin())); |
| 297 | 280 |
| 298 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 281 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 299 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); | 282 granted_permissions.reset(prefs()->GetGrantedPermissions(extension_id_)); |
| 300 EXPECT_TRUE(granted_permissions.get()); | 283 EXPECT_TRUE(granted_permissions.get()); |
| 301 EXPECT_FALSE(granted_permissions->IsEmpty()); | 284 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 302 EXPECT_EQ(api_permissions_, granted_permissions->apis()); | 285 EXPECT_EQ(api_permissions_, granted_permissions->apis()); |
| 303 AssertEqualExtents(ehost_permissions_, | 286 EXPECT_EQ(ehost_permissions_, |
| 304 granted_permissions->explicit_hosts()); | 287 granted_permissions->explicit_hosts()); |
| 305 AssertEqualExtents(shost_permissions_, | 288 EXPECT_EQ(shost_permissions_, |
| 306 granted_permissions->scriptable_hosts()); | 289 granted_permissions->scriptable_hosts()); |
| 307 effective_permissions_.ClearPatterns(); | 290 effective_permissions_.ClearPatterns(); |
| 308 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_, | 291 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_, |
| 309 &effective_permissions_); | 292 &effective_permissions_); |
| 310 AssertEqualExtents(effective_permissions_, | 293 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
| 311 granted_permissions->effective_hosts()); | |
| 312 } | 294 } |
| 313 | 295 |
| 314 virtual void Verify() { | 296 virtual void Verify() { |
| 315 scoped_ptr<ExtensionPermissionSet> permissions( | 297 scoped_ptr<ExtensionPermissionSet> permissions( |
| 316 prefs()->GetGrantedPermissions(extension_id_)); | 298 prefs()->GetGrantedPermissions(extension_id_)); |
| 317 EXPECT_TRUE(permissions.get()); | 299 EXPECT_TRUE(permissions.get()); |
| 318 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); | 300 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); |
| 319 EXPECT_EQ(api_permissions_, permissions->apis()); | 301 EXPECT_EQ(api_permissions_, permissions->apis()); |
| 320 AssertEqualExtents(ehost_permissions_, permissions->explicit_hosts()); | 302 EXPECT_EQ(ehost_permissions_, |
| 321 AssertEqualExtents(shost_permissions_, permissions->scriptable_hosts()); | 303 permissions->explicit_hosts()); |
| 304 EXPECT_EQ(shost_permissions_, |
| 305 permissions->scriptable_hosts()); |
| 322 } | 306 } |
| 323 | 307 |
| 324 private: | 308 private: |
| 325 std::string extension_id_; | 309 std::string extension_id_; |
| 326 ExtensionAPIPermissionSet api_perm_set1_; | 310 ExtensionAPIPermissionSet api_perm_set1_; |
| 327 ExtensionAPIPermissionSet api_perm_set2_; | 311 ExtensionAPIPermissionSet api_perm_set2_; |
| 328 URLPatternSet ehost_perm_set1_; | 312 URLPatternSet ehost_perm_set1_; |
| 329 URLPatternSet ehost_perm_set2_; | 313 URLPatternSet ehost_perm_set2_; |
| 330 URLPatternSet shost_perm_set1_; | 314 URLPatternSet shost_perm_set1_; |
| 331 URLPatternSet shost_perm_set2_; | 315 URLPatternSet shost_perm_set2_; |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 testing::Mock::VerifyAndClearExpectations(v1i); | 983 testing::Mock::VerifyAndClearExpectations(v1i); |
| 1000 testing::Mock::VerifyAndClearExpectations(v2); | 984 testing::Mock::VerifyAndClearExpectations(v2); |
| 1001 testing::Mock::VerifyAndClearExpectations(v2i); | 985 testing::Mock::VerifyAndClearExpectations(v2i); |
| 1002 } | 986 } |
| 1003 | 987 |
| 1004 virtual void Verify() { | 988 virtual void Verify() { |
| 1005 } | 989 } |
| 1006 }; | 990 }; |
| 1007 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 991 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 1008 ExtensionPrefsSetExtensionControlledPref) {} | 992 ExtensionPrefsSetExtensionControlledPref) {} |
| OLD | NEW |