| 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 "chrome/browser/extensions/extension_prefs_unittest.h" | 5 #include "chrome/browser/extensions/extension_prefs_unittest.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/mock_pref_change_callback.h" | 10 #include "base/prefs/mock_pref_change_callback.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/extension_pref_value_map.h" | 17 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 18 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
| 19 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 20 #include "chrome/common/chrome_paths.h" | |
| 21 #include "components/user_prefs/pref_registry_syncable.h" | 19 #include "components/user_prefs/pref_registry_syncable.h" |
| 22 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/test/mock_notification_observer.h" | 22 #include "content/public/test/mock_notification_observer.h" |
| 25 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 26 #include "extensions/common/manifest_constants.h" | 24 #include "extensions/common/manifest_constants.h" |
| 27 #include "extensions/common/permissions/permission_set.h" | 25 #include "extensions/common/permissions/permission_set.h" |
| 28 #include "extensions/common/permissions/permissions_info.h" | 26 #include "extensions/common/permissions/permissions_info.h" |
| 29 #include "sync/api/string_ordinal.h" | 27 #include "sync/api/string_ordinal.h" |
| 30 | 28 |
| 31 using base::Time; | 29 using base::Time; |
| 32 using base::TimeDelta; | 30 using base::TimeDelta; |
| 33 using content::BrowserThread; | 31 using content::BrowserThread; |
| 34 | 32 |
| 35 namespace extensions { | 33 namespace extensions { |
| 36 | 34 |
| 37 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 35 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 38 int schemes = URLPattern::SCHEME_ALL; | 36 int schemes = URLPattern::SCHEME_ALL; |
| 39 extent->AddPattern(URLPattern(schemes, pattern)); | 37 extent->AddPattern(URLPattern(schemes, pattern)); |
| 40 } | 38 } |
| 41 | 39 |
| 42 ExtensionPrefsTest::ExtensionPrefsTest() | 40 ExtensionPrefsTest::ExtensionPrefsTest( |
| 41 base::PrefServiceFactory* custom_pref_service_factory) |
| 43 : ui_thread_(BrowserThread::UI, &message_loop_), | 42 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 44 prefs_(message_loop_.message_loop_proxy().get()) {} | 43 prefs_(message_loop_.message_loop_proxy().get(), |
| 44 custom_pref_service_factory) {} |
| 45 | 45 |
| 46 ExtensionPrefsTest::~ExtensionPrefsTest() { | 46 ExtensionPrefsTest::~ExtensionPrefsTest() { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void ExtensionPrefsTest::RegisterPreferences( | 49 void ExtensionPrefsTest::RegisterPreferences( |
| 50 user_prefs::PrefRegistrySyncable* registry) {} | 50 user_prefs::PrefRegistrySyncable* registry) {} |
| 51 | 51 |
| 52 void ExtensionPrefsTest::SetUp() { | 52 void ExtensionPrefsTest::SetUp() { |
| 53 RegisterPreferences(prefs_.pref_registry().get()); | 53 RegisterPreferences(prefs_.pref_registry().get()); |
| 54 Initialize(); | 54 Initialize(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ExtensionPrefsTest::TearDown() { | 57 void ExtensionPrefsTest::TearDown() { |
| 58 Verify(); | 58 Verify(); |
| 59 | 59 |
| 60 // Reset ExtensionPrefs, and re-verify. | 60 // Reset ExtensionPrefs, and re-verify. |
| 61 prefs_.ResetPrefRegistry(); | 61 prefs_.ResetPrefRegistry(); |
| 62 RegisterPreferences(prefs_.pref_registry().get()); | 62 RegisterPreferences(prefs_.pref_registry().get()); |
| 63 prefs_.RecreateExtensionPrefs(); | 63 prefs_.RecreateExtensionPrefs(); |
| 64 Verify(); | 64 Verify(); |
| 65 prefs_.pref_service()->CommitPendingWrite(); | 65 prefs_.pref_service()->CommitPendingWrite(); |
| 66 message_loop_.RunUntilIdle(); | 66 message_loop_.RunUntilIdle(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Tests the LastPingDay/SetLastPingDay functions. | 69 // Tests the LastPingDay/SetLastPingDay functions. |
| 70 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { | 70 class ExtensionPrefsLastPingDay : public ExtensionPrefsTest { |
| 71 public: | 71 public: |
| 72 ExtensionPrefsLastPingDay() | 72 ExtensionPrefsLastPingDay() |
| 73 : extension_time_(Time::Now() - TimeDelta::FromHours(4)), | 73 : ExtensionPrefsTest(NULL), |
| 74 extension_time_(Time::Now() - TimeDelta::FromHours(4)), |
| 74 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} | 75 blacklist_time_(Time::Now() - TimeDelta::FromHours(2)) {} |
| 75 | 76 |
| 76 virtual void Initialize() OVERRIDE { | 77 virtual void Initialize() OVERRIDE { |
| 77 extension_id_ = prefs_.AddExtensionAndReturnId("last_ping_day"); | 78 extension_id_ = prefs_.AddExtensionAndReturnId("last_ping_day"); |
| 78 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); | 79 EXPECT_TRUE(prefs()->LastPingDay(extension_id_).is_null()); |
| 79 prefs()->SetLastPingDay(extension_id_, extension_time_); | 80 prefs()->SetLastPingDay(extension_id_, extension_time_); |
| 80 prefs()->SetBlacklistLastPingDay(blacklist_time_); | 81 prefs()->SetBlacklistLastPingDay(blacklist_time_); |
| 81 } | 82 } |
| 82 | 83 |
| 83 virtual void Verify() OVERRIDE { | 84 virtual void Verify() OVERRIDE { |
| 84 Time result = prefs()->LastPingDay(extension_id_); | 85 Time result = prefs()->LastPingDay(extension_id_); |
| 85 EXPECT_FALSE(result.is_null()); | 86 EXPECT_FALSE(result.is_null()); |
| 86 EXPECT_TRUE(result == extension_time_); | 87 EXPECT_TRUE(result == extension_time_); |
| 87 result = prefs()->BlacklistLastPingDay(); | 88 result = prefs()->BlacklistLastPingDay(); |
| 88 EXPECT_FALSE(result.is_null()); | 89 EXPECT_FALSE(result.is_null()); |
| 89 EXPECT_TRUE(result == blacklist_time_); | 90 EXPECT_TRUE(result == blacklist_time_); |
| 90 } | 91 } |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 Time extension_time_; | 94 Time extension_time_; |
| 94 Time blacklist_time_; | 95 Time blacklist_time_; |
| 95 std::string extension_id_; | 96 std::string extension_id_; |
| 96 }; | 97 }; |
| 97 TEST_F(ExtensionPrefsLastPingDay, LastPingDay) {} | 98 TEST_F(ExtensionPrefsLastPingDay, LastPingDay) {} |
| 98 | 99 |
| 99 // Tests the GetToolbarOrder/SetToolbarOrder functions. | 100 // Tests the GetToolbarOrder/SetToolbarOrder functions. |
| 100 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { | 101 class ExtensionPrefsToolbarOrder : public ExtensionPrefsTest { |
| 101 public: | 102 public: |
| 103 ExtensionPrefsToolbarOrder() : ExtensionPrefsTest(NULL) {} |
| 104 |
| 102 virtual void Initialize() OVERRIDE { | 105 virtual void Initialize() OVERRIDE { |
| 103 list_.push_back(prefs_.AddExtensionAndReturnId("1")); | 106 list_.push_back(prefs_.AddExtensionAndReturnId("1")); |
| 104 list_.push_back(prefs_.AddExtensionAndReturnId("2")); | 107 list_.push_back(prefs_.AddExtensionAndReturnId("2")); |
| 105 list_.push_back(prefs_.AddExtensionAndReturnId("3")); | 108 list_.push_back(prefs_.AddExtensionAndReturnId("3")); |
| 106 ExtensionIdList before_list = prefs()->GetToolbarOrder(); | 109 ExtensionIdList before_list = prefs()->GetToolbarOrder(); |
| 107 EXPECT_TRUE(before_list.empty()); | 110 EXPECT_TRUE(before_list.empty()); |
| 108 prefs()->SetToolbarOrder(list_); | 111 prefs()->SetToolbarOrder(list_); |
| 109 } | 112 } |
| 110 | 113 |
| 111 virtual void Verify() OVERRIDE { | 114 virtual void Verify() OVERRIDE { |
| 112 ExtensionIdList result = prefs()->GetToolbarOrder(); | 115 ExtensionIdList result = prefs()->GetToolbarOrder(); |
| 113 ASSERT_EQ(list_, result); | 116 ASSERT_EQ(list_, result); |
| 114 } | 117 } |
| 115 | 118 |
| 116 private: | 119 private: |
| 117 ExtensionIdList list_; | 120 ExtensionIdList list_; |
| 118 }; | 121 }; |
| 119 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} | 122 TEST_F(ExtensionPrefsToolbarOrder, ToolbarOrder) {} |
| 120 | 123 |
| 121 // Tests the GetKnownDisabled/SetKnownDisabled functions. | 124 // Tests the GetKnownDisabled/SetKnownDisabled functions. |
| 122 class ExtensionPrefsKnownDisabled : public ExtensionPrefsTest { | 125 class ExtensionPrefsKnownDisabled : public ExtensionPrefsTest { |
| 123 public: | 126 public: |
| 127 ExtensionPrefsKnownDisabled() : ExtensionPrefsTest(NULL) {} |
| 128 |
| 124 virtual void Initialize() OVERRIDE { | 129 virtual void Initialize() OVERRIDE { |
| 125 ExtensionIdSet before_set; | 130 ExtensionIdSet before_set; |
| 126 EXPECT_FALSE(prefs()->GetKnownDisabled(&before_set)); | 131 EXPECT_FALSE(prefs()->GetKnownDisabled(&before_set)); |
| 127 EXPECT_TRUE(before_set.empty()); | 132 EXPECT_TRUE(before_set.empty()); |
| 128 | 133 |
| 129 // Initialize to an empty list and confirm that GetKnownDisabled() returns | 134 // Initialize to an empty list and confirm that GetKnownDisabled() returns |
| 130 // true and an empty list. | 135 // true and an empty list. |
| 131 prefs()->SetKnownDisabled(before_set); | 136 prefs()->SetKnownDisabled(before_set); |
| 132 EXPECT_TRUE(prefs()->GetKnownDisabled(&before_set)); | 137 EXPECT_TRUE(prefs()->GetKnownDisabled(&before_set)); |
| 133 EXPECT_TRUE(before_set.empty()); | 138 EXPECT_TRUE(before_set.empty()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 145 } | 150 } |
| 146 | 151 |
| 147 private: | 152 private: |
| 148 ExtensionIdSet set_; | 153 ExtensionIdSet set_; |
| 149 }; | 154 }; |
| 150 TEST_F(ExtensionPrefsKnownDisabled, KnownDisabled) {} | 155 TEST_F(ExtensionPrefsKnownDisabled, KnownDisabled) {} |
| 151 | 156 |
| 152 // Tests the IsExtensionDisabled/SetExtensionState functions. | 157 // Tests the IsExtensionDisabled/SetExtensionState functions. |
| 153 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { | 158 class ExtensionPrefsExtensionState : public ExtensionPrefsTest { |
| 154 public: | 159 public: |
| 160 ExtensionPrefsExtensionState() : ExtensionPrefsTest(NULL) {} |
| 161 |
| 155 virtual void Initialize() OVERRIDE { | 162 virtual void Initialize() OVERRIDE { |
| 156 extension = prefs_.AddExtension("test"); | 163 extension = prefs_.AddExtension("test"); |
| 157 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); | 164 prefs()->SetExtensionState(extension->id(), Extension::DISABLED); |
| 158 } | 165 } |
| 159 | 166 |
| 160 virtual void Verify() OVERRIDE { | 167 virtual void Verify() OVERRIDE { |
| 161 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); | 168 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension->id())); |
| 162 } | 169 } |
| 163 | 170 |
| 164 private: | 171 private: |
| 165 scoped_refptr<Extension> extension; | 172 scoped_refptr<Extension> extension; |
| 166 }; | 173 }; |
| 167 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} | 174 TEST_F(ExtensionPrefsExtensionState, ExtensionState) {} |
| 168 | 175 |
| 169 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { | 176 class ExtensionPrefsEscalatePermissions : public ExtensionPrefsTest { |
| 170 public: | 177 public: |
| 178 ExtensionPrefsEscalatePermissions() : ExtensionPrefsTest(NULL) {} |
| 179 |
| 171 virtual void Initialize() OVERRIDE { | 180 virtual void Initialize() OVERRIDE { |
| 172 extension = prefs_.AddExtension("test"); | 181 extension = prefs_.AddExtension("test"); |
| 173 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); | 182 prefs()->SetDidExtensionEscalatePermissions(extension.get(), true); |
| 174 } | 183 } |
| 175 | 184 |
| 176 virtual void Verify() OVERRIDE { | 185 virtual void Verify() OVERRIDE { |
| 177 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); | 186 EXPECT_TRUE(prefs()->DidExtensionEscalatePermissions(extension->id())); |
| 178 } | 187 } |
| 179 | 188 |
| 180 private: | 189 private: |
| 181 scoped_refptr<Extension> extension; | 190 scoped_refptr<Extension> extension; |
| 182 }; | 191 }; |
| 183 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} | 192 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} |
| 184 | 193 |
| 185 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. | 194 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. |
| 186 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { | 195 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
| 187 public: | 196 public: |
| 197 ExtensionPrefsGrantedPermissions() : ExtensionPrefsTest(NULL) {} |
| 198 |
| 188 virtual void Initialize() OVERRIDE { | 199 virtual void Initialize() OVERRIDE { |
| 189 const APIPermissionInfo* permission_info = | 200 const APIPermissionInfo* permission_info = |
| 190 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 201 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 191 | 202 |
| 192 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 203 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
| 193 | 204 |
| 194 api_perm_set1_.insert(APIPermission::kTab); | 205 api_perm_set1_.insert(APIPermission::kTab); |
| 195 api_perm_set1_.insert(APIPermission::kBookmark); | 206 api_perm_set1_.insert(APIPermission::kBookmark); |
| 196 scoped_ptr<APIPermission> permission( | 207 scoped_ptr<APIPermission> permission( |
| 197 permission_info->CreateAPIPermission()); | 208 permission_info->CreateAPIPermission()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 APIPermissionSet api_permissions_; | 342 APIPermissionSet api_permissions_; |
| 332 URLPatternSet ehost_permissions_; | 343 URLPatternSet ehost_permissions_; |
| 333 URLPatternSet shost_permissions_; | 344 URLPatternSet shost_permissions_; |
| 334 URLPatternSet effective_permissions_; | 345 URLPatternSet effective_permissions_; |
| 335 }; | 346 }; |
| 336 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} | 347 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} |
| 337 | 348 |
| 338 // Tests the SetActivePermissions / GetActivePermissions functions. | 349 // Tests the SetActivePermissions / GetActivePermissions functions. |
| 339 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { | 350 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { |
| 340 public: | 351 public: |
| 352 ExtensionPrefsActivePermissions() : ExtensionPrefsTest(NULL) {} |
| 353 |
| 341 virtual void Initialize() OVERRIDE { | 354 virtual void Initialize() OVERRIDE { |
| 342 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 355 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
| 343 | 356 |
| 344 APIPermissionSet api_perms; | 357 APIPermissionSet api_perms; |
| 345 api_perms.insert(APIPermission::kTab); | 358 api_perms.insert(APIPermission::kTab); |
| 346 api_perms.insert(APIPermission::kBookmark); | 359 api_perms.insert(APIPermission::kBookmark); |
| 347 api_perms.insert(APIPermission::kHistory); | 360 api_perms.insert(APIPermission::kHistory); |
| 348 | 361 |
| 349 ManifestPermissionSet empty_manifest_permissions; | 362 ManifestPermissionSet empty_manifest_permissions; |
| 350 | 363 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 395 |
| 383 private: | 396 private: |
| 384 std::string extension_id_; | 397 std::string extension_id_; |
| 385 scoped_refptr<PermissionSet> active_perms_; | 398 scoped_refptr<PermissionSet> active_perms_; |
| 386 }; | 399 }; |
| 387 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} | 400 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} |
| 388 | 401 |
| 389 // Tests the GetVersionString function. | 402 // Tests the GetVersionString function. |
| 390 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 403 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
| 391 public: | 404 public: |
| 405 ExtensionPrefsVersionString() : ExtensionPrefsTest(NULL) {} |
| 406 |
| 392 virtual void Initialize() OVERRIDE { | 407 virtual void Initialize() OVERRIDE { |
| 393 extension = prefs_.AddExtension("test"); | 408 extension = prefs_.AddExtension("test"); |
| 394 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); | 409 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); |
| 395 prefs()->OnExtensionUninstalled(extension->id(), | 410 prefs()->OnExtensionUninstalled(extension->id(), |
| 396 Manifest::INTERNAL, false); | 411 Manifest::INTERNAL, false); |
| 397 } | 412 } |
| 398 | 413 |
| 399 virtual void Verify() OVERRIDE { | 414 virtual void Verify() OVERRIDE { |
| 400 EXPECT_EQ("", prefs()->GetVersionString(extension->id())); | 415 EXPECT_EQ("", prefs()->GetVersionString(extension->id())); |
| 401 } | 416 } |
| 402 | 417 |
| 403 private: | 418 private: |
| 404 scoped_refptr<Extension> extension; | 419 scoped_refptr<Extension> extension; |
| 405 }; | 420 }; |
| 406 TEST_F(ExtensionPrefsVersionString, VersionString) {} | 421 TEST_F(ExtensionPrefsVersionString, VersionString) {} |
| 407 | 422 |
| 408 class ExtensionPrefsAcknowledgment : public ExtensionPrefsTest { | 423 class ExtensionPrefsAcknowledgment : public ExtensionPrefsTest { |
| 409 public: | 424 public: |
| 425 ExtensionPrefsAcknowledgment() : ExtensionPrefsTest(NULL) {} |
| 426 |
| 410 virtual void Initialize() OVERRIDE { | 427 virtual void Initialize() OVERRIDE { |
| 411 not_installed_id_ = "pghjnghklobnfoidcldiidjjjhkeeaoi"; | 428 not_installed_id_ = "pghjnghklobnfoidcldiidjjjhkeeaoi"; |
| 412 | 429 |
| 413 // Install some extensions. | 430 // Install some extensions. |
| 414 for (int i = 0; i < 5; i++) { | 431 for (int i = 0; i < 5; i++) { |
| 415 std::string name = "test" + base::IntToString(i); | 432 std::string name = "test" + base::IntToString(i); |
| 416 extensions_.push_back(prefs_.AddExtension(name)); | 433 extensions_.push_back(prefs_.AddExtension(name)); |
| 417 } | 434 } |
| 418 EXPECT_EQ(NULL, | 435 EXPECT_EQ(NULL, |
| 419 prefs()->GetInstalledExtensionInfo(not_installed_id_).get()); | 436 prefs()->GetInstalledExtensionInfo(not_installed_id_).get()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 481 |
| 465 std::string not_installed_id_; | 482 std::string not_installed_id_; |
| 466 std::string external_id_; | 483 std::string external_id_; |
| 467 std::string blacklisted_id_; | 484 std::string blacklisted_id_; |
| 468 }; | 485 }; |
| 469 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {} | 486 TEST_F(ExtensionPrefsAcknowledgment, Acknowledgment) {} |
| 470 | 487 |
| 471 // Tests the idle install information functions. | 488 // Tests the idle install information functions. |
| 472 class ExtensionPrefsDelayedInstallInfo : public ExtensionPrefsTest { | 489 class ExtensionPrefsDelayedInstallInfo : public ExtensionPrefsTest { |
| 473 public: | 490 public: |
| 491 ExtensionPrefsDelayedInstallInfo() : ExtensionPrefsTest(NULL) {} |
| 492 |
| 474 // Sets idle install information for one test extension. | 493 // Sets idle install information for one test extension. |
| 475 void SetIdleInfo(std::string id, int num) { | 494 void SetIdleInfo(std::string id, int num) { |
| 476 DictionaryValue manifest; | 495 DictionaryValue manifest; |
| 477 manifest.SetString(manifest_keys::kName, "test"); | 496 manifest.SetString(manifest_keys::kName, "test"); |
| 478 manifest.SetString(manifest_keys::kVersion, "1." + base::IntToString(num)); | 497 manifest.SetString(manifest_keys::kVersion, "1." + base::IntToString(num)); |
| 479 base::FilePath path = | 498 base::FilePath path = |
| 480 prefs_.extensions_dir().AppendASCII(base::IntToString(num)); | 499 prefs_.extensions_dir().AppendASCII(base::IntToString(num)); |
| 481 std::string errors; | 500 std::string errors; |
| 482 scoped_refptr<Extension> extension = Extension::Create( | 501 scoped_refptr<Extension> extension = Extension::Create( |
| 483 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors); | 502 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id, &errors); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 505 bool HasInfoForId(ExtensionPrefs::ExtensionsInfo* info, | 524 bool HasInfoForId(ExtensionPrefs::ExtensionsInfo* info, |
| 506 const std::string& id) { | 525 const std::string& id) { |
| 507 for (size_t i = 0; i < info->size(); ++i) { | 526 for (size_t i = 0; i < info->size(); ++i) { |
| 508 if (info->at(i)->extension_id == id) | 527 if (info->at(i)->extension_id == id) |
| 509 return true; | 528 return true; |
| 510 } | 529 } |
| 511 return false; | 530 return false; |
| 512 } | 531 } |
| 513 | 532 |
| 514 virtual void Initialize() OVERRIDE { | 533 virtual void Initialize() OVERRIDE { |
| 515 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); | |
| 516 now_ = Time::Now(); | 534 now_ = Time::Now(); |
| 517 id1_ = prefs_.AddExtensionAndReturnId("1"); | 535 id1_ = prefs_.AddExtensionAndReturnId("1"); |
| 518 id2_ = prefs_.AddExtensionAndReturnId("2"); | 536 id2_ = prefs_.AddExtensionAndReturnId("2"); |
| 519 id3_ = prefs_.AddExtensionAndReturnId("3"); | 537 id3_ = prefs_.AddExtensionAndReturnId("3"); |
| 520 id4_ = prefs_.AddExtensionAndReturnId("4"); | 538 id4_ = prefs_.AddExtensionAndReturnId("4"); |
| 521 | 539 |
| 522 // Set info for two extensions, then remove it. | 540 // Set info for two extensions, then remove it. |
| 523 SetIdleInfo(id1_, 1); | 541 SetIdleInfo(id1_, 1); |
| 524 SetIdleInfo(id2_, 2); | 542 SetIdleInfo(id2_, 2); |
| 525 VerifyIdleInfo(id1_, 1); | 543 VerifyIdleInfo(id1_, 1); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 VerifyIdleInfo(id1_, 1); | 583 VerifyIdleInfo(id1_, 1); |
| 566 VerifyIdleInfo(id2_, 2); | 584 VerifyIdleInfo(id2_, 2); |
| 567 VerifyIdleInfo(id4_, 4); | 585 VerifyIdleInfo(id4_, 4); |
| 568 | 586 |
| 569 // Make sure there isn't info the for the one extension id we removed. | 587 // Make sure there isn't info the for the one extension id we removed. |
| 570 EXPECT_FALSE(prefs()->GetDelayedInstallInfo(id3_)); | 588 EXPECT_FALSE(prefs()->GetDelayedInstallInfo(id3_)); |
| 571 } | 589 } |
| 572 | 590 |
| 573 protected: | 591 protected: |
| 574 Time now_; | 592 Time now_; |
| 575 base::FilePath basedir_; | |
| 576 std::string id1_; | 593 std::string id1_; |
| 577 std::string id2_; | 594 std::string id2_; |
| 578 std::string id3_; | 595 std::string id3_; |
| 579 std::string id4_; | 596 std::string id4_; |
| 580 }; | 597 }; |
| 581 TEST_F(ExtensionPrefsDelayedInstallInfo, DelayedInstallInfo) {} | 598 TEST_F(ExtensionPrefsDelayedInstallInfo, DelayedInstallInfo) {} |
| 582 | 599 |
| 583 // Tests the FinishDelayedInstallInfo function. | 600 // Tests the FinishDelayedInstallInfo function. |
| 584 class ExtensionPrefsFinishDelayedInstallInfo : public ExtensionPrefsTest { | 601 class ExtensionPrefsFinishDelayedInstallInfo : public ExtensionPrefsTest { |
| 585 public: | 602 public: |
| 603 ExtensionPrefsFinishDelayedInstallInfo() : ExtensionPrefsTest(NULL) {} |
| 604 |
| 586 virtual void Initialize() OVERRIDE { | 605 virtual void Initialize() OVERRIDE { |
| 587 DictionaryValue dictionary; | 606 DictionaryValue dictionary; |
| 588 dictionary.SetString(manifest_keys::kName, "test"); | 607 dictionary.SetString(manifest_keys::kName, "test"); |
| 589 dictionary.SetString(manifest_keys::kVersion, "0.1"); | 608 dictionary.SetString(manifest_keys::kVersion, "0.1"); |
| 590 dictionary.SetString(manifest_keys::kBackgroundPage, "background.html"); | 609 dictionary.SetString(manifest_keys::kBackgroundPage, "background.html"); |
| 591 scoped_refptr<Extension> extension = | 610 scoped_refptr<Extension> extension = |
| 592 prefs_.AddExtensionWithManifest(dictionary, Manifest::INTERNAL); | 611 prefs_.AddExtensionWithManifest(dictionary, Manifest::INTERNAL); |
| 593 id_ = extension->id(); | 612 id_ = extension->id(); |
| 594 | 613 |
| 595 | 614 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 EXPECT_EQ(1u, scripts->GetSize()); | 653 EXPECT_EQ(1u, scripts->GetSize()); |
| 635 } | 654 } |
| 636 | 655 |
| 637 protected: | 656 protected: |
| 638 std::string id_; | 657 std::string id_; |
| 639 }; | 658 }; |
| 640 TEST_F(ExtensionPrefsFinishDelayedInstallInfo, FinishDelayedInstallInfo) {} | 659 TEST_F(ExtensionPrefsFinishDelayedInstallInfo, FinishDelayedInstallInfo) {} |
| 641 | 660 |
| 642 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { | 661 class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { |
| 643 public: | 662 public: |
| 663 ExtensionPrefsOnExtensionInstalled() : ExtensionPrefsTest(NULL) {} |
| 664 |
| 644 virtual void Initialize() OVERRIDE { | 665 virtual void Initialize() OVERRIDE { |
| 645 extension_ = prefs_.AddExtension("on_extension_installed"); | 666 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 646 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); | 667 EXPECT_FALSE(prefs()->IsExtensionDisabled(extension_->id())); |
| 647 prefs()->OnExtensionInstalled(extension_.get(), | 668 prefs()->OnExtensionInstalled(extension_.get(), |
| 648 Extension::DISABLED, | 669 Extension::DISABLED, |
| 649 false, | 670 false, |
| 650 syncer::StringOrdinal()); | 671 syncer::StringOrdinal()); |
| 651 } | 672 } |
| 652 | 673 |
| 653 virtual void Verify() OVERRIDE { | 674 virtual void Verify() OVERRIDE { |
| 654 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); | 675 EXPECT_TRUE(prefs()->IsExtensionDisabled(extension_->id())); |
| 655 } | 676 } |
| 656 | 677 |
| 657 private: | 678 private: |
| 658 scoped_refptr<Extension> extension_; | 679 scoped_refptr<Extension> extension_; |
| 659 }; | 680 }; |
| 660 TEST_F(ExtensionPrefsOnExtensionInstalled, | 681 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 661 ExtensionPrefsOnExtensionInstalled) {} | 682 ExtensionPrefsOnExtensionInstalled) {} |
| 662 | 683 |
| 663 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { | 684 class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { |
| 664 public: | 685 public: |
| 686 ExtensionPrefsAppDraggedByUser() : ExtensionPrefsTest(NULL) {} |
| 687 |
| 665 virtual void Initialize() OVERRIDE { | 688 virtual void Initialize() OVERRIDE { |
| 666 extension_ = prefs_.AddExtension("on_extension_installed"); | 689 extension_ = prefs_.AddExtension("on_extension_installed"); |
| 667 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); | 690 EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 668 prefs()->OnExtensionInstalled(extension_.get(), | 691 prefs()->OnExtensionInstalled(extension_.get(), |
| 669 Extension::ENABLED, | 692 Extension::ENABLED, |
| 670 false, | 693 false, |
| 671 syncer::StringOrdinal()); | 694 syncer::StringOrdinal()); |
| 672 } | 695 } |
| 673 | 696 |
| 674 virtual void Verify() OVERRIDE { | 697 virtual void Verify() OVERRIDE { |
| 675 // Set the flag and see if it persisted. | 698 // Set the flag and see if it persisted. |
| 676 prefs()->SetAppDraggedByUser(extension_->id()); | 699 prefs()->SetAppDraggedByUser(extension_->id()); |
| 677 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 700 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 678 | 701 |
| 679 // Make sure it doesn't change on consecutive calls. | 702 // Make sure it doesn't change on consecutive calls. |
| 680 prefs()->SetAppDraggedByUser(extension_->id()); | 703 prefs()->SetAppDraggedByUser(extension_->id()); |
| 681 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); | 704 EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id())); |
| 682 } | 705 } |
| 683 | 706 |
| 684 private: | 707 private: |
| 685 scoped_refptr<Extension> extension_; | 708 scoped_refptr<Extension> extension_; |
| 686 }; | 709 }; |
| 687 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {} | 710 TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {} |
| 688 | 711 |
| 689 class ExtensionPrefsFlags : public ExtensionPrefsTest { | 712 class ExtensionPrefsFlags : public ExtensionPrefsTest { |
| 690 public: | 713 public: |
| 714 ExtensionPrefsFlags() : ExtensionPrefsTest(NULL) {} |
| 715 |
| 691 virtual void Initialize() OVERRIDE { | 716 virtual void Initialize() OVERRIDE { |
| 692 { | 717 { |
| 693 base::DictionaryValue dictionary; | 718 base::DictionaryValue dictionary; |
| 694 dictionary.SetString(manifest_keys::kName, "from_webstore"); | 719 dictionary.SetString(manifest_keys::kName, "from_webstore"); |
| 695 dictionary.SetString(manifest_keys::kVersion, "0.1"); | 720 dictionary.SetString(manifest_keys::kVersion, "0.1"); |
| 696 webstore_extension_ = prefs_.AddExtensionWithManifestAndFlags( | 721 webstore_extension_ = prefs_.AddExtensionWithManifestAndFlags( |
| 697 dictionary, Manifest::INTERNAL, Extension::FROM_WEBSTORE); | 722 dictionary, Manifest::INTERNAL, Extension::FROM_WEBSTORE); |
| 698 } | 723 } |
| 699 | 724 |
| 700 { | 725 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 726 EXPECT_TRUE(prefs()->WasInstalledByDefault(default_extension_->id())); | 751 EXPECT_TRUE(prefs()->WasInstalledByDefault(default_extension_->id())); |
| 727 } | 752 } |
| 728 | 753 |
| 729 private: | 754 private: |
| 730 scoped_refptr<Extension> webstore_extension_; | 755 scoped_refptr<Extension> webstore_extension_; |
| 731 scoped_refptr<Extension> bookmark_extension_; | 756 scoped_refptr<Extension> bookmark_extension_; |
| 732 scoped_refptr<Extension> default_extension_; | 757 scoped_refptr<Extension> default_extension_; |
| 733 }; | 758 }; |
| 734 TEST_F(ExtensionPrefsFlags, ExtensionPrefsFlags) {} | 759 TEST_F(ExtensionPrefsFlags, ExtensionPrefsFlags) {} |
| 735 | 760 |
| 736 PrefsPrepopulatedTestBase::PrefsPrepopulatedTestBase() | 761 PrefsPrepopulatedTestBase::PrefsPrepopulatedTestBase( |
| 737 : ExtensionPrefsTest() { | 762 base::PrefServiceFactory* custom_pref_service_factory) |
| 763 : ExtensionPrefsTest(custom_pref_service_factory) { |
| 738 DictionaryValue simple_dict; | 764 DictionaryValue simple_dict; |
| 739 std::string error; | 765 std::string error; |
| 740 | 766 |
| 741 simple_dict.SetString(manifest_keys::kVersion, "1.0.0.0"); | 767 simple_dict.SetString(manifest_keys::kVersion, "1.0.0.0"); |
| 742 simple_dict.SetString(manifest_keys::kName, "unused"); | 768 simple_dict.SetString(manifest_keys::kName, "unused"); |
| 743 | 769 |
| 744 extension1_ = Extension::Create( | 770 extension1_ = Extension::Create( |
| 745 prefs_.temp_dir().AppendASCII("ext1_"), | 771 prefs_.temp_dir().AppendASCII("ext1_"), |
| 746 Manifest::EXTERNAL_PREF, | 772 Manifest::EXTERNAL_PREF, |
| 747 simple_dict, | 773 simple_dict, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 769 for (size_t i = 0; i < kNumInstalledExtensions; ++i) | 795 for (size_t i = 0; i < kNumInstalledExtensions; ++i) |
| 770 installed_[i] = false; | 796 installed_[i] = false; |
| 771 } | 797 } |
| 772 | 798 |
| 773 PrefsPrepopulatedTestBase::~PrefsPrepopulatedTestBase() { | 799 PrefsPrepopulatedTestBase::~PrefsPrepopulatedTestBase() { |
| 774 } | 800 } |
| 775 | 801 |
| 776 // Tests that blacklist state can be queried. | 802 // Tests that blacklist state can be queried. |
| 777 class ExtensionPrefsBlacklistedExtensions : public ExtensionPrefsTest { | 803 class ExtensionPrefsBlacklistedExtensions : public ExtensionPrefsTest { |
| 778 public: | 804 public: |
| 805 ExtensionPrefsBlacklistedExtensions() : ExtensionPrefsTest(NULL) {} |
| 779 virtual ~ExtensionPrefsBlacklistedExtensions() {} | 806 virtual ~ExtensionPrefsBlacklistedExtensions() {} |
| 780 | 807 |
| 781 virtual void Initialize() OVERRIDE { | 808 virtual void Initialize() OVERRIDE { |
| 782 extension_a_ = prefs_.AddExtension("a"); | 809 extension_a_ = prefs_.AddExtension("a"); |
| 783 extension_b_ = prefs_.AddExtension("b"); | 810 extension_b_ = prefs_.AddExtension("b"); |
| 784 extension_c_ = prefs_.AddExtension("c"); | 811 extension_c_ = prefs_.AddExtension("c"); |
| 785 } | 812 } |
| 786 | 813 |
| 787 virtual void Verify() OVERRIDE { | 814 virtual void Verify() OVERRIDE { |
| 788 { | 815 { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 873 |
| 847 private: | 874 private: |
| 848 scoped_refptr<const Extension> extension_a_; | 875 scoped_refptr<const Extension> extension_a_; |
| 849 scoped_refptr<const Extension> extension_b_; | 876 scoped_refptr<const Extension> extension_b_; |
| 850 scoped_refptr<const Extension> extension_c_; | 877 scoped_refptr<const Extension> extension_c_; |
| 851 }; | 878 }; |
| 852 TEST_F(ExtensionPrefsBlacklistedExtensions, | 879 TEST_F(ExtensionPrefsBlacklistedExtensions, |
| 853 ExtensionPrefsBlacklistedExtensions) {} | 880 ExtensionPrefsBlacklistedExtensions) {} |
| 854 | 881 |
| 855 } // namespace extensions | 882 } // namespace extensions |
| OLD | NEW |