Chromium Code Reviews| 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/threading/sequenced_worker_pool.h" | |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/api/prefs/pref_change_registrar.h" | 15 #include "chrome/browser/api/prefs/pref_change_registrar.h" |
| 15 #include "chrome/browser/extensions/extension_pref_value_map.h" | 16 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/extensions/extension_manifest_constants.h" | 20 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 20 #include "chrome/common/extensions/permissions/permission_set.h" | 21 #include "chrome/common/extensions/permissions/permission_set.h" |
| 21 #include "chrome/common/extensions/permissions/permissions_info.h" | 22 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 22 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 46 namespace extensions { | 47 namespace extensions { |
| 47 | 48 |
| 48 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 49 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 49 int schemes = URLPattern::SCHEME_ALL; | 50 int schemes = URLPattern::SCHEME_ALL; |
| 50 extent->AddPattern(URLPattern(schemes, pattern)); | 51 extent->AddPattern(URLPattern(schemes, pattern)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ExtensionPrefsTest::ExtensionPrefsTest() | 54 ExtensionPrefsTest::ExtensionPrefsTest() |
| 54 : ui_thread_(BrowserThread::UI, &message_loop_), | 55 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 55 file_thread_(BrowserThread::FILE, &message_loop_) { | 56 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 57 blocking_pool_ = new base::SequencedWorkerPool(1, "ExtensionTestBlocking"); | |
| 58 prefs_.reset(new TestExtensionPrefs(blocking_pool_)); | |
|
akalin
2012/10/18 23:52:24
you can use message_loop_.message_loop_proxy() (se
zel
2012/10/19 01:20:32
Done.
zel
2012/10/19 01:20:32
Done.
zel
2012/10/19 01:20:32
Done.
| |
| 56 } | 59 } |
| 57 | 60 |
| 58 ExtensionPrefsTest::~ExtensionPrefsTest() {} | 61 ExtensionPrefsTest::~ExtensionPrefsTest() { |
| 62 prefs_.reset(NULL); | |
| 63 blocking_pool_->Shutdown(); | |
| 64 } | |
| 59 | 65 |
| 60 void ExtensionPrefsTest::RegisterPreferences() {} | 66 void ExtensionPrefsTest::RegisterPreferences() {} |
| 61 | 67 |
| 62 void ExtensionPrefsTest::SetUp() { | 68 void ExtensionPrefsTest::SetUp() { |
| 63 RegisterPreferences(); | 69 RegisterPreferences(); |
| 64 Initialize(); | 70 Initialize(); |
| 65 } | 71 } |
| 66 | 72 |
| 67 void ExtensionPrefsTest::TearDown() { | 73 void ExtensionPrefsTest::TearDown() { |
| 68 Verify(); | 74 Verify(); |
| 69 | 75 |
| 70 // Reset ExtensionPrefs, and re-verify. | 76 // Reset ExtensionPrefs, and re-verify. |
| 71 prefs_.RecreateExtensionPrefs(); | 77 prefs_->RecreateExtensionPrefs(); |
| 72 RegisterPreferences(); | 78 RegisterPreferences(); |
| 73 Verify(); | 79 Verify(); |
| 80 prefs_->pref_service()->CommitPendingWrite(); | |
| 81 blocking_pool_->FlushForTesting(); | |
|
akalin
2012/10/18 23:52:24
can use message_loop_.RunAllPending() here
zel
2012/10/19 01:20:32
Done.
zel
2012/10/19 01:20:32
Done.
zel
2012/10/19 01:20:32
Done.
| |
| 74 } | 82 } |
| 75 | 83 |
| 76 // Tests the LastPingDay/SetLastPingDay functions. | 84 // Tests the LastPingDay/SetLastPingDay functions. |
| 77 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { | 85 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { |
| 78 public: | 86 public: |
| 79 ExtensionPrefsLastPingDay() | 87 ExtensionPrefsLastPingDay() |
| 80 : extension_time_(Time::Now() - TimeDelta::FromHours(4)), | 88 : extension_time_(Time::Now() - TimeDelta::FromHours(4)), |
| 81 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} | 89 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} |
| 82 | 90 |
| 83 virtual void Initialize() { | 91 virtual void Initialize() { |
| 84 extension_id_ = prefs_.AddExtensionAndReturnId("last_ping_day"); | 92 extension_id_ = prefs_->AddExtensionAndReturnId("last_ping_day"); |
| 85 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); | 93 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); |
| 86 prefs()->SetLastPingDay(extension_id_, extension_time_); | 94 prefs()->SetLastPingDay(extension_id_, extension_time_); |
| 87 prefs()->SetBlacklistLastPingDay(blacklist_time_); | 95 prefs()->SetBlacklistLastPingDay(blacklist_time_); |
| 88 } | 96 } |
| 89 | 97 |
| 90 virtual void Verify() { | 98 virtual void Verify() { |
| 91 Time result = prefs()->LastPingDay(extension_id_); | 99 Time result = prefs()->LastPingDay(extension_id_); |
| 92 EXPECT_FALSE(result.is_null()); | 100 EXPECT_FALSE(result.is_null()); |
| 93 EXPECT_TRUE(result == extension_time_); | 101 EXPECT_TRUE(result == extension_time_); |
| 94 result = prefs()->BlacklistLastPingDay(); | 102 result = prefs()->BlacklistLastPingDay(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 112 permission.has_permission = has_access; | 120 permission.has_permission = has_access; |
| 113 vector->push_back(permission); | 121 vector->push_back(permission); |
| 114 } | 122 } |
| 115 | 123 |
| 116 } // namspace | 124 } // namspace |
| 117 | 125 |
| 118 // Test the MediaGalleries permissions functions. | 126 // Test the MediaGalleries permissions functions. |
| 119 class MediaGalleriesPermissions : public ExtensionPrefsTest { | 127 class MediaGalleriesPermissions : public ExtensionPrefsTest { |
| 120 public: | 128 public: |
| 121 virtual void Initialize() { | 129 virtual void Initialize() { |
| 122 extension1_id_ = prefs_.AddExtensionAndReturnId("test1"); | 130 extension1_id_ = prefs_->AddExtensionAndReturnId("test1"); |
| 123 extension2_id_ = prefs_.AddExtensionAndReturnId("test2"); | 131 extension2_id_ = prefs_->AddExtensionAndReturnId("test2"); |
| 124 extension3_id_ = prefs_.AddExtensionAndReturnId("test3"); | 132 extension3_id_ = prefs_->AddExtensionAndReturnId("test3"); |
| 125 // Id4 isn't used to ensure that an empty permission list is ok. | 133 // Id4 isn't used to ensure that an empty permission list is ok. |
| 126 extension4_id_ = prefs_.AddExtensionAndReturnId("test4"); | 134 extension4_id_ = prefs_->AddExtensionAndReturnId("test4"); |
| 127 Verify(); | 135 Verify(); |
| 128 | 136 |
| 129 prefs()->SetMediaGalleryPermission(extension1_id_, 1, false); | 137 prefs()->SetMediaGalleryPermission(extension1_id_, 1, false); |
| 130 AddGalleryPermission(1, false, &extension1_expectation_); | 138 AddGalleryPermission(1, false, &extension1_expectation_); |
| 131 Verify(); | 139 Verify(); |
| 132 | 140 |
| 133 prefs()->SetMediaGalleryPermission(extension1_id_, 2, true); | 141 prefs()->SetMediaGalleryPermission(extension1_id_, 2, true); |
| 134 AddGalleryPermission(2, true, &extension1_expectation_); | 142 AddGalleryPermission(2, true, &extension1_expectation_); |
| 135 Verify(); | 143 Verify(); |
| 136 | 144 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 std::vector<chrome::MediaGalleryPermission> extension2_expectation_; | 204 std::vector<chrome::MediaGalleryPermission> extension2_expectation_; |
| 197 std::vector<chrome::MediaGalleryPermission> extension3_expectation_; | 205 std::vector<chrome::MediaGalleryPermission> extension3_expectation_; |
| 198 std::vector<chrome::MediaGalleryPermission> extension4_expectation_; | 206 std::vector<chrome::MediaGalleryPermission> extension4_expectation_; |
| 199 }; | 207 }; |
| 200 TEST_F(MediaGalleriesPermissions, MediaGalleries) {} | 208 TEST_F(MediaGalleriesPermissions, MediaGalleries) {} |
| 201 | 209 |
| 202 // Tests the GetToolbarOrder/SetToolbarOrder functions. | 210 // Tests the GetToolbarOrder/SetToolbarOrder functions. |
| 203 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { | 211 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { |
| 204 public: | 212 public: |
| 205 virtual void Initialize() { | 213 virtual void Initialize() { |
| 206 list_.push_back(prefs_.AddExtensionAndReturnId("1")); | 214 list_.push_back(prefs_->AddExtensionAndReturnId("1")); |
| 207 list_.push_back(prefs_.AddExtensionAndReturnId("2")); | 215 list_.push_back(prefs_->AddExtensionAndReturnId("2")); |
| 208 list_.push_back(prefs_.AddExtensionAndReturnId("3")); | 216 list_.push_back(prefs_->AddExtensionAndReturnId("3")); |
| 209 std::vector<std::string> before_list = prefs()->GetToolbarOrder(); | 217 std::vector<std::string> before_list = prefs()->GetToolbarOrder(); |
| 210 EXPECT_TRUE(before_list.empty()); | 218 EXPECT_TRUE(before_list.empty()); |
| 211 prefs()->SetToolbarOrder(list_); | 219 prefs()->SetToolbarOrder(list_); |
| 212 } | 220 } |
| 213 | 221 |
| 214 virtual void Verify() { | 222 virtual void Verify() { |
| 215 std::vector<std::string> result = prefs()->GetToolbarOrder(); | 223 std::vector<std::string> result = prefs()->GetToolbarOrder(); |
| 216 ASSERT_EQ(list_.size(), result.size()); | 224 ASSERT_EQ(list_.size(), result.size()); |
| 217 for (size_t i = 0; i < list_.size(); i++) { | 225 for (size_t i = 0; i < list_.size(); i++) { |
| 218 EXPECT_EQ(list_[i], result[i]); | 226 EXPECT_EQ(list_[i], result[i]); |
| 219 } | 227 } |
| 220 } | 228 } |
| 221 | 229 |
| 222 private: | 230 private: |
| 223 std::vector<std::string> list_; | 231 std::vector<std::string> list_; |
| 224 }; | 232 }; |
| 225 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} | 233 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} |
| 226 | 234 |
| 227 | 235 |
| 228 // Tests the IsExtensionDisabled/SetExtensionState functions. | 236 // Tests the IsExtensionDisabled/SetExtensionState functions. |
| 229 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { | 237 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { |
| 230 public: | 238 public: |
| 231 virtual void Initialize() { | 239 virtual void Initialize() { |
| 232 extension = prefs_.AddExtension("test"); | 240 extension = prefs_->AddExtension("test"); |
| 233 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); | 241 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); |
| 234 } | 242 } |
| 235 | 243 |
| 236 virtual void Verify() { | 244 virtual void Verify() { |
| 237 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); | 245 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); |
| 238 } | 246 } |
| 239 | 247 |
| 240 private: | 248 private: |
| 241 scoped_refptr<Extension> extension; | 249 scoped_refptr<Extension> extension; |
| 242 }; | 250 }; |
| 243 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} | 251 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} |
| 244 | 252 |
| 245 | 253 |
| 246 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { | 254 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { |
| 247 public: | 255 public: |
| 248 virtual void Initialize() { | 256 virtual void Initialize() { |
| 249 extension = prefs_.AddExtension("test"); | 257 extension = prefs_->AddExtension("test"); |
| 250 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); | 258 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); |
| 251 } | 259 } |
| 252 | 260 |
| 253 virtual void Verify() { | 261 virtual void Verify() { |
| 254 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); | 262 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); |
| 255 } | 263 } |
| 256 | 264 |
| 257 private: | 265 private: |
| 258 scoped_refptr<Extension> extension; | 266 scoped_refptr<Extension> extension; |
| 259 }; | 267 }; |
| 260 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} | 268 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} |
| 261 | 269 |
| 262 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. | 270 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. |
| 263 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { | 271 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
| 264 public: | 272 public: |
| 265 virtual void Initialize() { | 273 virtual void Initialize() { |
| 266 const APIPermissionInfo* permission_info = | 274 const APIPermissionInfo* permission_info = |
| 267 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 275 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 268 | 276 |
| 269 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 277 extension_id_ = prefs_->AddExtensionAndReturnId("test"); |
| 270 | 278 |
| 271 api_perm_set1_.insert(APIPermission::kTab); | 279 api_perm_set1_.insert(APIPermission::kTab); |
| 272 api_perm_set1_.insert(APIPermission::kBookmark); | 280 api_perm_set1_.insert(APIPermission::kBookmark); |
| 273 scoped_ptr<APIPermission> permission( | 281 scoped_ptr<APIPermission> permission( |
| 274 permission_info->CreateAPIPermission()); | 282 permission_info->CreateAPIPermission()); |
| 275 { | 283 { |
| 276 scoped_ptr<ListValue> value(new ListValue()); | 284 scoped_ptr<ListValue> value(new ListValue()); |
| 277 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); | 285 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 278 value->Append(Value::CreateStringValue("udp-bind::8080")); | 286 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 279 value->Append(Value::CreateStringValue("udp-send-to::8888")); | 287 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 URLPatternSet ehost_permissions_; | 415 URLPatternSet ehost_permissions_; |
| 408 URLPatternSet shost_permissions_; | 416 URLPatternSet shost_permissions_; |
| 409 URLPatternSet effective_permissions_; | 417 URLPatternSet effective_permissions_; |
| 410 }; | 418 }; |
| 411 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} | 419 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} |
| 412 | 420 |
| 413 // Tests the SetActivePermissions / GetActivePermissions functions. | 421 // Tests the SetActivePermissions / GetActivePermissions functions. |
| 414 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { | 422 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { |
| 415 public: | 423 public: |
| 416 virtual void Initialize() { | 424 virtual void Initialize() { |
| 417 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 425 extension_id_ = prefs_->AddExtensionAndReturnId("test"); |
| 418 | 426 |
| 419 APIPermissionSet api_perms; | 427 APIPermissionSet api_perms; |
| 420 api_perms.insert(APIPermission::kTab); | 428 api_perms.insert(APIPermission::kTab); |
| 421 api_perms.insert(APIPermission::kBookmark); | 429 api_perms.insert(APIPermission::kBookmark); |
| 422 api_perms.insert(APIPermission::kHistory); | 430 api_perms.insert(APIPermission::kHistory); |
| 423 | 431 |
| 424 URLPatternSet ehosts; | 432 URLPatternSet ehosts; |
| 425 AddPattern(&ehosts, "http://*.google.com/*"); | 433 AddPattern(&ehosts, "http://*.google.com/*"); |
| 426 AddPattern(&ehosts, "http://example.com/*"); | 434 AddPattern(&ehosts, "http://example.com/*"); |
| 427 AddPattern(&ehosts, "chrome://favicon/*"); | 435 AddPattern(&ehosts, "chrome://favicon/*"); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 455 private: | 463 private: |
| 456 std::string extension_id_; | 464 std::string extension_id_; |
| 457 scoped_refptr<PermissionSet> active_perms_; | 465 scoped_refptr<PermissionSet> active_perms_; |
| 458 }; | 466 }; |
| 459 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} | 467 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} |
| 460 | 468 |
| 461 // Tests the GetVersionString function. | 469 // Tests the GetVersionString function. |
| 462 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 470 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
| 463 public: | 471 public: |
| 464 virtual void Initialize() { | 472 virtual void Initialize() { |
| 465 extension = prefs_.AddExtension("test"); | 473 extension = prefs_->AddExtension("test"); |
| 466 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); | 474 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); |
| 467 prefs()->OnExtensionUninstalled(extension->id(), | 475 prefs()->OnExtensionUninstalled(extension->id(), |
| 468 Extension::INTERNAL, false); | 476 Extension::INTERNAL, false); |
| 469 } | 477 } |
| 470 | 478 |
| 471 virtual void Verify() { | 479 virtual void Verify() { |
| 472 EXPECT_EQ("", prefs()->GetVersionString(extension->id())); | 480 EXPECT_EQ("", prefs()->GetVersionString(extension->id())); |
| 473 } | 481 } |
| 474 | 482 |
| 475 private: | 483 private: |
| 476 scoped_refptr<Extension> extension; | 484 scoped_refptr<Extension> extension; |
| 477 }; | 485 }; |
| 478 TEST_F(ExtensionPrefsVersionString, VersionString) {} | 486 TEST_F(ExtensionPrefsVersionString, VersionString) {} |
| 479 | 487 |
| 480 // Tests various areas of blacklist functionality. | 488 // Tests various areas of blacklist functionality. |
| 481 class ExtensionPrefsBlacklist : public ExtensionPrefsTest { | 489 class ExtensionPrefsBlacklist : public ExtensionPrefsTest { |
| 482 public: | 490 public: |
| 483 virtual void Initialize() { | 491 virtual void Initialize() { |
| 484 not_installed_id_ = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 492 not_installed_id_ = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 485 | 493 |
| 486 // Install 5 extensions. | 494 // Install 5 extensions. |
| 487 for (int i = 0; i < 5; i++) { | 495 for (int i = 0; i < 5; i++) { |
| 488 std::string name = "test" + base::IntToString(i); | 496 std::string name = "test" + base::IntToString(i); |
| 489 extensions_.push_back(prefs_.AddExtension(name)); | 497 extensions_.push_back(prefs_->AddExtension(name)); |
| 490 } | 498 } |
| 491 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); | 499 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); |
| 492 | 500 |
| 493 ExtensionList::const_iterator iter; | 501 ExtensionList::const_iterator iter; |
| 494 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { | 502 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { |
| 495 EXPECT_TRUE(prefs()->UserMayLoad(*iter, NULL)); | 503 EXPECT_TRUE(prefs()->UserMayLoad(*iter, NULL)); |
| 496 } | 504 } |
| 497 // Blacklist one installed and one not-installed extension id. | 505 // Blacklist one installed and one not-installed extension id. |
| 498 std::set<std::string> blacklisted_ids; | 506 std::set<std::string> blacklisted_ids; |
| 499 blacklisted_ids.insert(extensions_[0]->id()); | 507 blacklisted_ids.insert(extensions_[0]->id()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 TEST_F(ExtensionPrefsBlacklist, Blacklist) {} | 539 TEST_F(ExtensionPrefsBlacklist, Blacklist) {} |
| 532 | 540 |
| 533 class ExtensionPrefsAcknowledgment : public ExtensionPrefsTest { | 541 class ExtensionPrefsAcknowledgment : public ExtensionPrefsTest { |
| 534 public: | 542 public: |
| 535 virtual void Initialize() { | 543 virtual void Initialize() { |
| 536 not_installed_id_ = "pghjnghklobnfoidcldiidjjjhkeeaoi"; | 544 not_installed_id_ = "pghjnghklobnfoidcldiidjjjhkeeaoi"; |
| 537 | 545 |
| 538 // Install some extensions. | 546 // Install some extensions. |
| 539 for (int i = 0; i < 5; i++) { | 547 for (int i = 0; i < 5; i++) { |
| 540 std::string name = "test" + base::IntToString(i); | 548 std::string name = "test" + base::IntToString(i); |
| 541 extensions_.push_back(prefs_.AddExtension(name)); | 549 extensions_.push_back(prefs_->AddExtension(name)); |
| 542 } | 550 } |
| 543 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); | 551 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); |
| 544 | 552 |
| 545 ExtensionList::const_iterator iter; | 553 ExtensionList::const_iterator iter; |
| 546 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { | 554 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { |
| 547 std::string id = (*iter)->id(); | 555 std::string id = (*iter)->id(); |
| 548 EXPECT_FALSE(prefs()->IsExternalExtensionAcknowledged(id)); | 556 EXPECT_FALSE(prefs()->IsExternalExtensionAcknowledged(id)); |
| 549 EXPECT_FALSE(prefs()->IsBlacklistedExtensionAcknowledged(id)); | 557 EXPECT_FALSE(prefs()->IsBlacklistedExtensionAcknowledged(id)); |
| 550 EXPECT_FALSE(prefs()->IsOrphanedExtensionAcknowledged(id)); | 558 EXPECT_FALSE(prefs()->IsOrphanedExtensionAcknowledged(id)); |
| 551 if (external_id_.empty()) { | 559 if (external_id_.empty()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 }; | 614 }; |
| 607 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {} | 615 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {} |
| 608 | 616 |
| 609 // Tests force hiding browser actions. | 617 // Tests force hiding browser actions. |
| 610 class ExtensionPrefsHidingBrowserActions : public ExtensionPrefsTest { | 618 class ExtensionPrefsHidingBrowserActions : public ExtensionPrefsTest { |
| 611 public: | 619 public: |
| 612 virtual void Initialize() { | 620 virtual void Initialize() { |
| 613 // Install 5 extensions. | 621 // Install 5 extensions. |
| 614 for (int i = 0; i < 5; i++) { | 622 for (int i = 0; i < 5; i++) { |
| 615 std::string name = "test" + base::IntToString(i); | 623 std::string name = "test" + base::IntToString(i); |
| 616 extensions_.push_back(prefs_.AddExtension(name)); | 624 extensions_.push_back(prefs_->AddExtension(name)); |
| 617 } | 625 } |
| 618 | 626 |
| 619 ExtensionList::const_iterator iter; | 627 ExtensionList::const_iterator iter; |
| 620 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) | 628 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) |
| 621 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter)); | 629 EXPECT_TRUE(prefs()->GetBrowserActionVisibility(*iter)); |
| 622 | 630 |
| 623 prefs()->SetBrowserActionVisibility(extensions_[0], false); | 631 prefs()->SetBrowserActionVisibility(extensions_[0], false); |
| 624 prefs()->SetBrowserActionVisibility(extensions_[1], true); | 632 prefs()->SetBrowserActionVisibility(extensions_[1], true); |
| 625 } | 633 } |
| 626 | 634 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 &fetch_time)); | 671 &fetch_time)); |
| 664 ASSERT_EQ(crx_path.value(), | 672 ASSERT_EQ(crx_path.value(), |
| 665 basedir_.AppendASCII(base::IntToString(num)).value()); | 673 basedir_.AppendASCII(base::IntToString(num)).value()); |
| 666 ASSERT_EQ("1." + base::IntToString(num), version); | 674 ASSERT_EQ("1." + base::IntToString(num), version); |
| 667 ASSERT_TRUE(fetch_time == now_ + TimeDelta::FromSeconds(num)); | 675 ASSERT_TRUE(fetch_time == now_ + TimeDelta::FromSeconds(num)); |
| 668 } | 676 } |
| 669 | 677 |
| 670 virtual void Initialize() { | 678 virtual void Initialize() { |
| 671 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); | 679 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); |
| 672 now_ = Time::Now(); | 680 now_ = Time::Now(); |
| 673 id1_ = prefs_.AddExtensionAndReturnId("1"); | 681 id1_ = prefs_->AddExtensionAndReturnId("1"); |
| 674 id2_ = prefs_.AddExtensionAndReturnId("2"); | 682 id2_ = prefs_->AddExtensionAndReturnId("2"); |
| 675 id3_ = prefs_.AddExtensionAndReturnId("3"); | 683 id3_ = prefs_->AddExtensionAndReturnId("3"); |
| 676 id4_ = prefs_.AddExtensionAndReturnId("4"); | 684 id4_ = prefs_->AddExtensionAndReturnId("4"); |
| 677 | 685 |
| 678 // Set info for two extensions, then remove it. | 686 // Set info for two extensions, then remove it. |
| 679 SetIdleInfo(id1_, 1); | 687 SetIdleInfo(id1_, 1); |
| 680 SetIdleInfo(id2_, 2); | 688 SetIdleInfo(id2_, 2); |
| 681 VerifyIdleInfo(id1_, 1); | 689 VerifyIdleInfo(id1_, 1); |
| 682 VerifyIdleInfo(id2_, 2); | 690 VerifyIdleInfo(id2_, 2); |
| 683 std::set<std::string> ids = prefs()->GetIdleInstallInfoIds(); | 691 std::set<std::string> ids = prefs()->GetIdleInstallInfoIds(); |
| 684 EXPECT_EQ(2u, ids.size()); | 692 EXPECT_EQ(2u, ids.size()); |
| 685 EXPECT_TRUE(ContainsKey(ids, id1_)); | 693 EXPECT_TRUE(ContainsKey(ids, id1_)); |
| 686 EXPECT_TRUE(ContainsKey(ids, id2_)); | 694 EXPECT_TRUE(ContainsKey(ids, id2_)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 std::string id1_; | 738 std::string id1_; |
| 731 std::string id2_; | 739 std::string id2_; |
| 732 std::string id3_; | 740 std::string id3_; |
| 733 std::string id4_; | 741 std::string id4_; |
| 734 }; | 742 }; |
| 735 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} | 743 TEST_F(ExtensionPrefsIdleInstallInfo, IdleInstallInfo) {} |
| 736 | 744 |
| 737 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 745 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
| 738 public: | 746 public: |
| 739 virtual void Initialize() { | 747 virtual void Initialize() { |
| 740 extension_ = prefs_.AddExtension("on_extension_installed"); | 748 extension_ = prefs_->AddExtension("on_extension_installed"); |
| 741 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 749 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 742 prefs()->OnExtensionInstalled( | 750 prefs()->OnExtensionInstalled( |
| 743 extension_.get(), Extension::DISABLED, | 751 extension_.get(), Extension::DISABLED, |
| 744 syncer::StringOrdinal()); | 752 syncer::StringOrdinal()); |
| 745 } | 753 } |
| 746 | 754 |
| 747 virtual void Verify() { | 755 virtual void Verify() { |
| 748 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 756 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
| 749 } | 757 } |
| 750 | 758 |
| 751 private: | 759 private: |
| 752 scoped_refptr<Extension> extension_; | 760 scoped_refptr<Extension> extension_; |
| 753 }; | 761 }; |
| 754 TEST_F(ExtensionPrefsOnExtensionInstalled, | 762 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 755 ExtensionPrefsOnExtensionInstalled) {} | 763 ExtensionPrefsOnExtensionInstalled) {} |
| 756 | 764 |
| 757 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 765 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
| 758 public: | 766 public: |
| 759 virtual void Initialize() { | 767 virtual void Initialize() { |
| 760 extension_ = prefs_.AddExtension("on_extension_installed"); | 768 extension_ = prefs_->AddExtension("on_extension_installed"); |
| 761 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 769 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 762 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, | 770 prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, |
| 763 syncer::StringOrdinal()); | 771 syncer::StringOrdinal()); |
| 764 } | 772 } |
| 765 | 773 |
| 766 virtual void Verify() { | 774 virtual void Verify() { |
| 767 // Set the flag and see if it persisted. | 775 // Set the flag and see if it persisted. |
| 768 prefs()->SetAppDraggedByUser(extension_->id()); | 776 prefs()->SetAppDraggedByUser(extension_->id()); |
| 769 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 777 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 770 | 778 |
| 771 // Make sure it doesn't change on consecutive calls. | 779 // Make sure it doesn't change on consecutive calls. |
| 772 prefs()->SetAppDraggedByUser(extension_->id()); | 780 prefs()->SetAppDraggedByUser(extension_->id()); |
| 773 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 781 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 774 } | 782 } |
| 775 | 783 |
| 776 private: | 784 private: |
| 777 scoped_refptr<Extension> extension_; | 785 scoped_refptr<Extension> extension_; |
| 778 }; | 786 }; |
| 779 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {} | 787 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {} |
| 780 | 788 |
| 781 class ExtensionPrefsFlags : public ExtensionPrefsTest { | 789 class ExtensionPrefsFlags : public ExtensionPrefsTest { |
| 782 public: | 790 public: |
| 783 virtual void Initialize() { | 791 virtual void Initialize() { |
| 784 { | 792 { |
| 785 base::DictionaryValue dictionary; | 793 base::DictionaryValue dictionary; |
| 786 dictionary.SetString(extension_manifest_keys::kName, "from_webstore"); | 794 dictionary.SetString(extension_manifest_keys::kName, "from_webstore"); |
| 787 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 795 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 788 webstore_extension_ = prefs_.AddExtensionWithManifestAndFlags( | 796 webstore_extension_ = prefs_->AddExtensionWithManifestAndFlags( |
| 789 dictionary, Extension::INTERNAL, Extension::FROM_WEBSTORE); | 797 dictionary, Extension::INTERNAL, Extension::FROM_WEBSTORE); |
| 790 } | 798 } |
| 791 | 799 |
| 792 { | 800 { |
| 793 base::DictionaryValue dictionary; | 801 base::DictionaryValue dictionary; |
| 794 dictionary.SetString(extension_manifest_keys::kName, "from_bookmark"); | 802 dictionary.SetString(extension_manifest_keys::kName, "from_bookmark"); |
| 795 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 803 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 796 bookmark_extension_ = prefs_.AddExtensionWithManifestAndFlags( | 804 bookmark_extension_ = prefs_->AddExtensionWithManifestAndFlags( |
| 797 dictionary, Extension::INTERNAL, Extension::FROM_BOOKMARK); | 805 dictionary, Extension::INTERNAL, Extension::FROM_BOOKMARK); |
| 798 } | 806 } |
| 799 | 807 |
| 800 { | 808 { |
| 801 base::DictionaryValue dictionary; | 809 base::DictionaryValue dictionary; |
| 802 dictionary.SetString(extension_manifest_keys::kName, | 810 dictionary.SetString(extension_manifest_keys::kName, |
| 803 "was_installed_by_default"); | 811 "was_installed_by_default"); |
| 804 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); | 812 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); |
| 805 default_extension_ = prefs_.AddExtensionWithManifestAndFlags( | 813 default_extension_ = prefs_->AddExtensionWithManifestAndFlags( |
| 806 dictionary, | 814 dictionary, |
| 807 Extension::INTERNAL, | 815 Extension::INTERNAL, |
| 808 Extension::WAS_INSTALLED_BY_DEFAULT); | 816 Extension::WAS_INSTALLED_BY_DEFAULT); |
| 809 } | 817 } |
| 810 } | 818 } |
| 811 | 819 |
| 812 virtual void Verify() { | 820 virtual void Verify() { |
| 813 EXPECT_TRUE(prefs()->IsFromWebStore(webstore_extension_->id())); | 821 EXPECT_TRUE(prefs()->IsFromWebStore(webstore_extension_->id())); |
| 814 EXPECT_FALSE(prefs()->IsFromBookmark(webstore_extension_->id())); | 822 EXPECT_FALSE(prefs()->IsFromBookmark(webstore_extension_->id())); |
| 815 | 823 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 835 ext3_(NULL), | 843 ext3_(NULL), |
| 836 ext4_(NULL), | 844 ext4_(NULL), |
| 837 installed() { | 845 installed() { |
| 838 DictionaryValue simple_dict; | 846 DictionaryValue simple_dict; |
| 839 std::string error; | 847 std::string error; |
| 840 | 848 |
| 841 simple_dict.SetString(keys::kVersion, "1.0.0.0"); | 849 simple_dict.SetString(keys::kVersion, "1.0.0.0"); |
| 842 simple_dict.SetString(keys::kName, "unused"); | 850 simple_dict.SetString(keys::kName, "unused"); |
| 843 | 851 |
| 844 ext1_scoped_ = Extension::Create( | 852 ext1_scoped_ = Extension::Create( |
| 845 prefs_.temp_dir().AppendASCII("ext1_"), Extension::EXTERNAL_PREF, | 853 prefs_->temp_dir().AppendASCII("ext1_"), Extension::EXTERNAL_PREF, |
| 846 simple_dict, Extension::NO_FLAGS, &error); | 854 simple_dict, Extension::NO_FLAGS, &error); |
| 847 ext2_scoped_ = Extension::Create( | 855 ext2_scoped_ = Extension::Create( |
| 848 prefs_.temp_dir().AppendASCII("ext2_"), Extension::EXTERNAL_PREF, | 856 prefs_->temp_dir().AppendASCII("ext2_"), Extension::EXTERNAL_PREF, |
| 849 simple_dict, Extension::NO_FLAGS, &error); | 857 simple_dict, Extension::NO_FLAGS, &error); |
| 850 ext3_scoped_ = Extension::Create( | 858 ext3_scoped_ = Extension::Create( |
| 851 prefs_.temp_dir().AppendASCII("ext3_"), Extension::EXTERNAL_PREF, | 859 prefs_->temp_dir().AppendASCII("ext3_"), Extension::EXTERNAL_PREF, |
| 852 simple_dict, Extension::NO_FLAGS, &error); | 860 simple_dict, Extension::NO_FLAGS, &error); |
| 853 ext4_scoped_ = Extension::Create( | 861 ext4_scoped_ = Extension::Create( |
| 854 prefs_.temp_dir().AppendASCII("ext4_"), Extension::EXTERNAL_PREF, | 862 prefs_->temp_dir().AppendASCII("ext4_"), Extension::EXTERNAL_PREF, |
| 855 simple_dict, Extension::NO_FLAGS, &error); | 863 simple_dict, Extension::NO_FLAGS, &error); |
| 856 | 864 |
| 857 ext1_ = ext1_scoped_.get(); | 865 ext1_ = ext1_scoped_.get(); |
| 858 ext2_ = ext2_scoped_.get(); | 866 ext2_ = ext2_scoped_.get(); |
| 859 ext3_ = ext3_scoped_.get(); | 867 ext3_ = ext3_scoped_.get(); |
| 860 ext4_ = ext4_scoped_.get(); | 868 ext4_ = ext4_scoped_.get(); |
| 861 | 869 |
| 862 for (size_t i = 0; i < arraysize(installed); ++i) | 870 for (size_t i = 0; i < arraysize(installed); ++i) |
| 863 installed[i] = false; | 871 installed[i] = false; |
| 864 } | 872 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} | 962 TEST_F(ExtensionPrefsInstallOneExtension, ExtensionPrefsInstallOneExtension) {} |
| 955 | 963 |
| 956 // Check that we do not forget persistent incognito values after a reload. | 964 // Check that we do not forget persistent incognito values after a reload. |
| 957 class ExtensionPrefsInstallIncognitoPersistent | 965 class ExtensionPrefsInstallIncognitoPersistent |
| 958 : public ExtensionPrefsPrepopulatedTest { | 966 : public ExtensionPrefsPrepopulatedTest { |
| 959 public: | 967 public: |
| 960 virtual void Initialize() { | 968 virtual void Initialize() { |
| 961 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 969 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 962 InstallExtControlledPrefIncognito(ext1_, kPref1, | 970 InstallExtControlledPrefIncognito(ext1_, kPref1, |
| 963 Value::CreateStringValue("val2")); | 971 Value::CreateStringValue("val2")); |
| 964 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 972 scoped_ptr<PrefService> incog_prefs(prefs_->CreateIncognitoPrefService()); |
| 965 std::string actual = incog_prefs->GetString(kPref1); | 973 std::string actual = incog_prefs->GetString(kPref1); |
| 966 EXPECT_EQ("val2", actual); | 974 EXPECT_EQ("val2", actual); |
| 967 } | 975 } |
| 968 virtual void Verify() { | 976 virtual void Verify() { |
| 969 // Main pref service shall see only non-incognito settings. | 977 // Main pref service shall see only non-incognito settings. |
| 970 std::string actual = prefs()->pref_service()->GetString(kPref1); | 978 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 971 EXPECT_EQ("val1", actual); | 979 EXPECT_EQ("val1", actual); |
| 972 // Incognito pref service shall see incognito values. | 980 // Incognito pref service shall see incognito values. |
| 973 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 981 scoped_ptr<PrefService> incog_prefs(prefs_->CreateIncognitoPrefService()); |
| 974 actual = incog_prefs->GetString(kPref1); | 982 actual = incog_prefs->GetString(kPref1); |
| 975 EXPECT_EQ("val2", actual); | 983 EXPECT_EQ("val2", actual); |
| 976 } | 984 } |
| 977 }; | 985 }; |
| 978 TEST_F(ExtensionPrefsInstallIncognitoPersistent, | 986 TEST_F(ExtensionPrefsInstallIncognitoPersistent, |
| 979 ExtensionPrefsInstallOneExtension) {} | 987 ExtensionPrefsInstallOneExtension) {} |
| 980 | 988 |
| 981 // Check that we forget 'session only' incognito values after a reload. | 989 // Check that we forget 'session only' incognito values after a reload. |
| 982 class ExtensionPrefsInstallIncognitoSessionOnly | 990 class ExtensionPrefsInstallIncognitoSessionOnly |
| 983 : public ExtensionPrefsPrepopulatedTest { | 991 : public ExtensionPrefsPrepopulatedTest { |
| 984 public: | 992 public: |
| 985 ExtensionPrefsInstallIncognitoSessionOnly() : iteration_(0) {} | 993 ExtensionPrefsInstallIncognitoSessionOnly() : iteration_(0) {} |
| 986 | 994 |
| 987 virtual void Initialize() { | 995 virtual void Initialize() { |
| 988 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 996 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 989 InstallExtControlledPrefIncognitoSessionOnly( | 997 InstallExtControlledPrefIncognitoSessionOnly( |
| 990 ext1_, kPref1, Value::CreateStringValue("val2")); | 998 ext1_, kPref1, Value::CreateStringValue("val2")); |
| 991 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 999 scoped_ptr<PrefService> incog_prefs(prefs_->CreateIncognitoPrefService()); |
| 992 std::string actual = incog_prefs->GetString(kPref1); | 1000 std::string actual = incog_prefs->GetString(kPref1); |
| 993 EXPECT_EQ("val2", actual); | 1001 EXPECT_EQ("val2", actual); |
| 994 } | 1002 } |
| 995 virtual void Verify() { | 1003 virtual void Verify() { |
| 996 // Main pref service shall see only non-incognito settings. | 1004 // Main pref service shall see only non-incognito settings. |
| 997 std::string actual = prefs()->pref_service()->GetString(kPref1); | 1005 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 998 EXPECT_EQ("val1", actual); | 1006 EXPECT_EQ("val1", actual); |
| 999 // Incognito pref service shall see session-only incognito values only | 1007 // Incognito pref service shall see session-only incognito values only |
| 1000 // during first run. Once the pref service was reloaded, all values shall be | 1008 // during first run. Once the pref service was reloaded, all values shall be |
| 1001 // discarded. | 1009 // discarded. |
| 1002 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 1010 scoped_ptr<PrefService> incog_prefs(prefs_->CreateIncognitoPrefService()); |
| 1003 actual = incog_prefs->GetString(kPref1); | 1011 actual = incog_prefs->GetString(kPref1); |
| 1004 if (iteration_ == 0) { | 1012 if (iteration_ == 0) { |
| 1005 EXPECT_EQ("val2", actual); | 1013 EXPECT_EQ("val2", actual); |
| 1006 } else { | 1014 } else { |
| 1007 EXPECT_EQ("val1", actual); | 1015 EXPECT_EQ("val1", actual); |
| 1008 } | 1016 } |
| 1009 ++iteration_; | 1017 ++iteration_; |
| 1010 } | 1018 } |
| 1011 int iteration_; | 1019 int iteration_; |
| 1012 }; | 1020 }; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 using testing::_; | 1056 using testing::_; |
| 1049 using testing::Mock; | 1057 using testing::Mock; |
| 1050 using testing::StrEq; | 1058 using testing::StrEq; |
| 1051 | 1059 |
| 1052 content::MockNotificationObserver observer; | 1060 content::MockNotificationObserver observer; |
| 1053 PrefChangeRegistrar registrar; | 1061 PrefChangeRegistrar registrar; |
| 1054 registrar.Init(prefs()->pref_service()); | 1062 registrar.Init(prefs()->pref_service()); |
| 1055 registrar.Add(kPref1, &observer); | 1063 registrar.Add(kPref1, &observer); |
| 1056 | 1064 |
| 1057 content::MockNotificationObserver incognito_observer; | 1065 content::MockNotificationObserver incognito_observer; |
| 1058 scoped_ptr<PrefService> incog_prefs(prefs_.CreateIncognitoPrefService()); | 1066 scoped_ptr<PrefService> incog_prefs(prefs_->CreateIncognitoPrefService()); |
| 1059 PrefChangeRegistrar incognito_registrar; | 1067 PrefChangeRegistrar incognito_registrar; |
| 1060 incognito_registrar.Init(incog_prefs.get()); | 1068 incognito_registrar.Init(incog_prefs.get()); |
| 1061 incognito_registrar.Add(kPref1, &incognito_observer); | 1069 incognito_registrar.Add(kPref1, &incognito_observer); |
| 1062 | 1070 |
| 1063 // Write value and check notification. | 1071 // Write value and check notification. |
| 1064 EXPECT_CALL(observer, Observe(_, _, _)); | 1072 EXPECT_CALL(observer, Observe(_, _, _)); |
| 1065 EXPECT_CALL(incognito_observer, Observe(_, _, _)); | 1073 EXPECT_CALL(incognito_observer, Observe(_, _, _)); |
| 1066 InstallExtControlledPref(ext1_, kPref1, | 1074 InstallExtControlledPref(ext1_, kPref1, |
| 1067 Value::CreateStringValue("https://www.chromium.org")); | 1075 Value::CreateStringValue("https://www.chromium.org")); |
| 1068 Mock::VerifyAndClearExpectations(&observer); | 1076 Mock::VerifyAndClearExpectations(&observer); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 InstallExtControlledPrefIncognito(ext1_, kPref1, v1i); | 1182 InstallExtControlledPrefIncognito(ext1_, kPref1, v1i); |
| 1175 testing::Mock::VerifyAndClearExpectations(v1); | 1183 testing::Mock::VerifyAndClearExpectations(v1); |
| 1176 testing::Mock::VerifyAndClearExpectations(v1i); | 1184 testing::Mock::VerifyAndClearExpectations(v1i); |
| 1177 // Make sure there is no memory leak and both values are deleted. | 1185 // Make sure there is no memory leak and both values are deleted. |
| 1178 EXPECT_CALL(*v1, Die()).Times(1); | 1186 EXPECT_CALL(*v1, Die()).Times(1); |
| 1179 EXPECT_CALL(*v1i, Die()).Times(1); | 1187 EXPECT_CALL(*v1i, Die()).Times(1); |
| 1180 EXPECT_CALL(*v2, Die()).Times(1); | 1188 EXPECT_CALL(*v2, Die()).Times(1); |
| 1181 EXPECT_CALL(*v2i, Die()).Times(1); | 1189 EXPECT_CALL(*v2i, Die()).Times(1); |
| 1182 InstallExtControlledPref(ext1_, kPref1, v2); | 1190 InstallExtControlledPref(ext1_, kPref1, v2); |
| 1183 InstallExtControlledPrefIncognito(ext1_, kPref1, v2i); | 1191 InstallExtControlledPrefIncognito(ext1_, kPref1, v2i); |
| 1184 prefs_.RecreateExtensionPrefs(); | 1192 prefs_->RecreateExtensionPrefs(); |
| 1185 testing::Mock::VerifyAndClearExpectations(v1); | 1193 testing::Mock::VerifyAndClearExpectations(v1); |
| 1186 testing::Mock::VerifyAndClearExpectations(v1i); | 1194 testing::Mock::VerifyAndClearExpectations(v1i); |
| 1187 testing::Mock::VerifyAndClearExpectations(v2); | 1195 testing::Mock::VerifyAndClearExpectations(v2); |
| 1188 testing::Mock::VerifyAndClearExpectations(v2i); | 1196 testing::Mock::VerifyAndClearExpectations(v2i); |
| 1189 } | 1197 } |
| 1190 | 1198 |
| 1191 virtual void Verify() { | 1199 virtual void Verify() { |
| 1192 } | 1200 } |
| 1193 }; | 1201 }; |
| 1194 TEST_F(ExtensionPrefsSetExtensionControlledPref, | 1202 TEST_F(ExtensionPrefsSetExtensionControlledPref, |
| 1195 ExtensionPrefsSetExtensionControlledPref) {} | 1203 ExtensionPrefsSetExtensionControlledPref) {} |
| 1196 | 1204 |
| 1197 // Tests that the switches::kDisableExtensions command-line flag prevents | 1205 // Tests that the switches::kDisableExtensions command-line flag prevents |
| 1198 // extension controlled preferences from being enacted. | 1206 // extension controlled preferences from being enacted. |
| 1199 class ExtensionPrefsDisableExtensions : public ExtensionPrefsPrepopulatedTest { | 1207 class ExtensionPrefsDisableExtensions : public ExtensionPrefsPrepopulatedTest { |
| 1200 public: | 1208 public: |
| 1201 ExtensionPrefsDisableExtensions() | 1209 ExtensionPrefsDisableExtensions() |
| 1202 : iteration_(0) {} | 1210 : iteration_(0) {} |
| 1203 virtual ~ExtensionPrefsDisableExtensions() {} | 1211 virtual ~ExtensionPrefsDisableExtensions() {} |
| 1204 virtual void Initialize() { | 1212 virtual void Initialize() { |
| 1205 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); | 1213 InstallExtControlledPref(ext1_, kPref1, Value::CreateStringValue("val1")); |
| 1206 // This becomes only active in the second verification phase. | 1214 // This becomes only active in the second verification phase. |
| 1207 prefs_.set_extensions_disabled(true); | 1215 prefs_->set_extensions_disabled(true); |
| 1208 } | 1216 } |
| 1209 virtual void Verify() { | 1217 virtual void Verify() { |
| 1210 std::string actual = prefs()->pref_service()->GetString(kPref1); | 1218 std::string actual = prefs()->pref_service()->GetString(kPref1); |
| 1211 if (iteration_ == 0) { | 1219 if (iteration_ == 0) { |
| 1212 EXPECT_EQ("val1", actual); | 1220 EXPECT_EQ("val1", actual); |
| 1213 ++iteration_; | 1221 ++iteration_; |
| 1214 } else { | 1222 } else { |
| 1215 EXPECT_EQ(kDefaultPref1, actual); | 1223 EXPECT_EQ(kDefaultPref1, actual); |
| 1216 } | 1224 } |
| 1217 } | 1225 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1282 EXPECT_EQ(string16(), error16); | 1290 EXPECT_EQ(string16(), error16); |
| 1283 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); | 1291 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); |
| 1284 EXPECT_EQ(string16(), error16); | 1292 EXPECT_EQ(string16(), error16); |
| 1285 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); | 1293 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); |
| 1286 EXPECT_EQ(string16(), error16); | 1294 EXPECT_EQ(string16(), error16); |
| 1287 } | 1295 } |
| 1288 }; | 1296 }; |
| 1289 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} | 1297 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} |
| 1290 | 1298 |
| 1291 } // namespace extensions | 1299 } // namespace extensions |
| OLD | NEW |