| 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_util.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/test_extension_prefs.h" | 12 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 13 #include "chrome/browser/pref_service.h" | 13 #include "chrome/browser/pref_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using base::Time; | 18 using base::Time; |
| 19 using base::TimeDelta; | 19 using base::TimeDelta; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 TEST_F(ExtensionPrefsVersionString, VersionString) {} | 165 TEST_F(ExtensionPrefsVersionString, VersionString) {} |
| 166 | 166 |
| 167 // Tests various areas of blacklist functionality. | 167 // Tests various areas of blacklist functionality. |
| 168 class ExtensionPrefsBlacklist : public ExtensionPrefsTest { | 168 class ExtensionPrefsBlacklist : public ExtensionPrefsTest { |
| 169 public: | 169 public: |
| 170 virtual void Initialize() { | 170 virtual void Initialize() { |
| 171 not_installed_id_ = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 171 not_installed_id_ = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 172 | 172 |
| 173 // Install 5 extensions. | 173 // Install 5 extensions. |
| 174 for (int i = 0; i < 5; i++) { | 174 for (int i = 0; i < 5; i++) { |
| 175 std::string name = "test" + IntToString(i); | 175 std::string name = "test" + base::IntToString(i); |
| 176 extensions_.push_back(linked_ptr<Extension>(prefs_.AddExtension(name))); | 176 extensions_.push_back(linked_ptr<Extension>(prefs_.AddExtension(name))); |
| 177 } | 177 } |
| 178 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); | 178 EXPECT_EQ(NULL, prefs()->GetInstalledExtensionInfo(not_installed_id_)); |
| 179 | 179 |
| 180 std::vector<linked_ptr<Extension> >::const_iterator iter; | 180 std::vector<linked_ptr<Extension> >::const_iterator iter; |
| 181 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { | 181 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) { |
| 182 EXPECT_FALSE(prefs()->IsExtensionBlacklisted((*iter)->id())); | 182 EXPECT_FALSE(prefs()->IsExtensionBlacklisted((*iter)->id())); |
| 183 } | 183 } |
| 184 // Blacklist one installed and one not-installed extension id. | 184 // Blacklist one installed and one not-installed extension id. |
| 185 std::set<std::string> blacklisted_ids; | 185 std::set<std::string> blacklisted_ids; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 std::string not_installed_id_; | 218 std::string not_installed_id_; |
| 219 }; | 219 }; |
| 220 TEST_F(ExtensionPrefsBlacklist, Blacklist) {} | 220 TEST_F(ExtensionPrefsBlacklist, Blacklist) {} |
| 221 | 221 |
| 222 | 222 |
| 223 // Tests the idle install information functions. | 223 // Tests the idle install information functions. |
| 224 class ExtensionPrefsIdleInstallInfo : public ExtensionPrefsTest { | 224 class ExtensionPrefsIdleInstallInfo : public ExtensionPrefsTest { |
| 225 public: | 225 public: |
| 226 // Sets idle install information for one test extension. | 226 // Sets idle install information for one test extension. |
| 227 void SetIdleInfo(std::string id, int num) { | 227 void SetIdleInfo(std::string id, int num) { |
| 228 prefs()->SetIdleInstallInfo(id, basedir_.AppendASCII(IntToString(num)), | 228 prefs()->SetIdleInstallInfo(id, |
| 229 "1." + IntToString(num), | 229 basedir_.AppendASCII(base::IntToString(num)), |
| 230 "1." + base::IntToString(num), |
| 230 now_ + TimeDelta::FromSeconds(num)); | 231 now_ + TimeDelta::FromSeconds(num)); |
| 231 } | 232 } |
| 232 | 233 |
| 233 // Verifies that we get back expected idle install information previously | 234 // Verifies that we get back expected idle install information previously |
| 234 // set by SetIdleInfo. | 235 // set by SetIdleInfo. |
| 235 void VerifyIdleInfo(std::string id, int num) { | 236 void VerifyIdleInfo(std::string id, int num) { |
| 236 FilePath crx_path; | 237 FilePath crx_path; |
| 237 std::string version; | 238 std::string version; |
| 238 base::Time fetch_time; | 239 base::Time fetch_time; |
| 239 ASSERT_TRUE(prefs()->GetIdleInstallInfo(id, &crx_path, &version, | 240 ASSERT_TRUE(prefs()->GetIdleInstallInfo(id, &crx_path, &version, |
| 240 &fetch_time)); | 241 &fetch_time)); |
| 241 ASSERT_EQ(crx_path.value(), | 242 ASSERT_EQ(crx_path.value(), |
| 242 basedir_.AppendASCII(IntToString(num)).value()); | 243 basedir_.AppendASCII(base::IntToString(num)).value()); |
| 243 ASSERT_EQ("1." + IntToString(num), version); | 244 ASSERT_EQ("1." + base::IntToString(num), version); |
| 244 ASSERT_TRUE(fetch_time == now_ + TimeDelta::FromSeconds(num)); | 245 ASSERT_TRUE(fetch_time == now_ + TimeDelta::FromSeconds(num)); |
| 245 } | 246 } |
| 246 | 247 |
| 247 virtual void Initialize() { | 248 virtual void Initialize() { |
| 248 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); | 249 PathService::Get(chrome::DIR_TEST_DATA, &basedir_); |
| 249 now_ = Time::Now(); | 250 now_ = Time::Now(); |
| 250 id1_ = prefs_.AddExtensionAndReturnId("1"); | 251 id1_ = prefs_.AddExtensionAndReturnId("1"); |
| 251 id2_ = prefs_.AddExtensionAndReturnId("2"); | 252 id2_ = prefs_.AddExtensionAndReturnId("2"); |
| 252 id3_ = prefs_.AddExtensionAndReturnId("3"); | 253 id3_ = prefs_.AddExtensionAndReturnId("3"); |
| 253 id4_ = prefs_.AddExtensionAndReturnId("4"); | 254 id4_ = prefs_.AddExtensionAndReturnId("4"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 EXPECT_EQ(Extension::DISABLED, | 327 EXPECT_EQ(Extension::DISABLED, |
| 327 prefs()->GetExtensionState(extension_->id())); | 328 prefs()->GetExtensionState(extension_->id())); |
| 328 EXPECT_TRUE(prefs()->IsIncognitoEnabled(extension_->id())); | 329 EXPECT_TRUE(prefs()->IsIncognitoEnabled(extension_->id())); |
| 329 } | 330 } |
| 330 | 331 |
| 331 private: | 332 private: |
| 332 scoped_ptr<Extension> extension_; | 333 scoped_ptr<Extension> extension_; |
| 333 }; | 334 }; |
| 334 TEST_F(ExtensionPrefsOnExtensionInstalled, | 335 TEST_F(ExtensionPrefsOnExtensionInstalled, |
| 335 ExtensionPrefsOnExtensionInstalled) {} | 336 ExtensionPrefsOnExtensionInstalled) {} |
| OLD | NEW |