| 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_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 using content::IndexedDBContext; | 112 using content::IndexedDBContext; |
| 113 using content::PluginService; | 113 using content::PluginService; |
| 114 using extensions::APIPermission; | 114 using extensions::APIPermission; |
| 115 using extensions::APIPermissionSet; | 115 using extensions::APIPermissionSet; |
| 116 using extensions::CrxInstaller; | 116 using extensions::CrxInstaller; |
| 117 using extensions::Extension; | 117 using extensions::Extension; |
| 118 using extensions::ExtensionCreator; | 118 using extensions::ExtensionCreator; |
| 119 using extensions::ExtensionPrefs; | 119 using extensions::ExtensionPrefs; |
| 120 using extensions::ExtensionSystem; | 120 using extensions::ExtensionSystem; |
| 121 using extensions::FeatureSwitch; | 121 using extensions::FeatureSwitch; |
| 122 using extensions::Manifest; |
| 122 using extensions::PermissionSet; | 123 using extensions::PermissionSet; |
| 123 using extensions::URLPatternSet; | 124 using extensions::URLPatternSet; |
| 124 | 125 |
| 125 namespace keys = extension_manifest_keys; | 126 namespace keys = extension_manifest_keys; |
| 126 | 127 |
| 127 namespace { | 128 namespace { |
| 128 | 129 |
| 129 // Extension ids used during testing. | 130 // Extension ids used during testing. |
| 130 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 131 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 131 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 132 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 CHECK(file_util::CreateTemporaryFile(&temp_file)); | 177 CHECK(file_util::CreateTemporaryFile(&temp_file)); |
| 177 return temp_file; | 178 return temp_file; |
| 178 } | 179 } |
| 179 | 180 |
| 180 } // namespace | 181 } // namespace |
| 181 | 182 |
| 182 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 183 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 183 public: | 184 public: |
| 184 MockExtensionProvider( | 185 MockExtensionProvider( |
| 185 VisitorInterface* visitor, | 186 VisitorInterface* visitor, |
| 186 Extension::Location location) | 187 Manifest::Location location) |
| 187 : location_(location), visitor_(visitor), visit_count_(0) { | 188 : location_(location), visitor_(visitor), visit_count_(0) { |
| 188 } | 189 } |
| 189 | 190 |
| 190 virtual ~MockExtensionProvider() {} | 191 virtual ~MockExtensionProvider() {} |
| 191 | 192 |
| 192 void UpdateOrAddExtension(const std::string& id, | 193 void UpdateOrAddExtension(const std::string& id, |
| 193 const std::string& version, | 194 const std::string& version, |
| 194 const FilePath& path) { | 195 const FilePath& path) { |
| 195 extension_map_[id] = std::make_pair(version, path); | 196 extension_map_[id] = std::make_pair(version, path); |
| 196 } | 197 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 212 } | 213 } |
| 213 visitor_->OnExternalProviderReady(this); | 214 visitor_->OnExternalProviderReady(this); |
| 214 } | 215 } |
| 215 | 216 |
| 216 virtual bool HasExtension(const std::string& id) const OVERRIDE { | 217 virtual bool HasExtension(const std::string& id) const OVERRIDE { |
| 217 return extension_map_.find(id) != extension_map_.end(); | 218 return extension_map_.find(id) != extension_map_.end(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 virtual bool GetExtensionDetails( | 221 virtual bool GetExtensionDetails( |
| 221 const std::string& id, | 222 const std::string& id, |
| 222 Extension::Location* location, | 223 Manifest::Location* location, |
| 223 scoped_ptr<Version>* version) const OVERRIDE { | 224 scoped_ptr<Version>* version) const OVERRIDE { |
| 224 DataMap::const_iterator it = extension_map_.find(id); | 225 DataMap::const_iterator it = extension_map_.find(id); |
| 225 if (it == extension_map_.end()) | 226 if (it == extension_map_.end()) |
| 226 return false; | 227 return false; |
| 227 | 228 |
| 228 if (version) | 229 if (version) |
| 229 version->reset(new Version(it->second.first)); | 230 version->reset(new Version(it->second.first)); |
| 230 | 231 |
| 231 if (location) | 232 if (location) |
| 232 *location = location_; | 233 *location = location_; |
| 233 | 234 |
| 234 return true; | 235 return true; |
| 235 } | 236 } |
| 236 | 237 |
| 237 virtual bool IsReady() const OVERRIDE { | 238 virtual bool IsReady() const OVERRIDE { |
| 238 return true; | 239 return true; |
| 239 } | 240 } |
| 240 | 241 |
| 241 virtual void ServiceShutdown() OVERRIDE { | 242 virtual void ServiceShutdown() OVERRIDE { |
| 242 } | 243 } |
| 243 | 244 |
| 244 int visit_count() const { return visit_count_; } | 245 int visit_count() const { return visit_count_; } |
| 245 void set_visit_count(int visit_count) { | 246 void set_visit_count(int visit_count) { |
| 246 visit_count_ = visit_count; | 247 visit_count_ = visit_count; |
| 247 } | 248 } |
| 248 | 249 |
| 249 private: | 250 private: |
| 250 typedef std::map< std::string, std::pair<std::string, FilePath> > DataMap; | 251 typedef std::map< std::string, std::pair<std::string, FilePath> > DataMap; |
| 251 DataMap extension_map_; | 252 DataMap extension_map_; |
| 252 Extension::Location location_; | 253 Manifest::Location location_; |
| 253 VisitorInterface* visitor_; | 254 VisitorInterface* visitor_; |
| 254 | 255 |
| 255 // visit_count_ tracks the number of calls to VisitRegisteredExtension(). | 256 // visit_count_ tracks the number of calls to VisitRegisteredExtension(). |
| 256 // Mutable because it must be incremented on each call to | 257 // Mutable because it must be incremented on each call to |
| 257 // VisitRegisteredExtension(), which must be a const method to inherit | 258 // VisitRegisteredExtension(), which must be a const method to inherit |
| 258 // from the class being mocked. | 259 // from the class being mocked. |
| 259 mutable int visit_count_; | 260 mutable int visit_count_; |
| 260 | 261 |
| 261 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); | 262 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); |
| 262 }; | 263 }; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 277 : ids_found_(0), | 278 : ids_found_(0), |
| 278 fake_base_path_(fake_base_path), | 279 fake_base_path_(fake_base_path), |
| 279 expected_creation_flags_(expected_creation_flags) { | 280 expected_creation_flags_(expected_creation_flags) { |
| 280 } | 281 } |
| 281 | 282 |
| 282 int Visit(const std::string& json_data) { | 283 int Visit(const std::string& json_data) { |
| 283 // Give the test json file to the provider for parsing. | 284 // Give the test json file to the provider for parsing. |
| 284 provider_.reset(new extensions::ExternalProviderImpl( | 285 provider_.reset(new extensions::ExternalProviderImpl( |
| 285 this, | 286 this, |
| 286 new extensions::ExternalTestingLoader(json_data, fake_base_path_), | 287 new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
| 287 Extension::EXTERNAL_PREF, | 288 Manifest::EXTERNAL_PREF, |
| 288 Extension::EXTERNAL_PREF_DOWNLOAD, | 289 Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 289 Extension::NO_FLAGS)); | 290 Extension::NO_FLAGS)); |
| 290 | 291 |
| 291 // We also parse the file into a dictionary to compare what we get back | 292 // We also parse the file into a dictionary to compare what we get back |
| 292 // from the provider. | 293 // from the provider. |
| 293 JSONStringValueSerializer serializer(json_data); | 294 JSONStringValueSerializer serializer(json_data); |
| 294 Value* json_value = serializer.Deserialize(NULL, NULL); | 295 Value* json_value = serializer.Deserialize(NULL, NULL); |
| 295 | 296 |
| 296 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { | 297 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { |
| 297 NOTREACHED() << "Unable to deserialize json data"; | 298 NOTREACHED() << "Unable to deserialize json data"; |
| 298 return -1; | 299 return -1; |
| 299 } else { | 300 } else { |
| 300 DictionaryValue* external_extensions = | 301 DictionaryValue* external_extensions = |
| 301 static_cast<DictionaryValue*>(json_value); | 302 static_cast<DictionaryValue*>(json_value); |
| 302 prefs_.reset(external_extensions); | 303 prefs_.reset(external_extensions); |
| 303 } | 304 } |
| 304 | 305 |
| 305 // Reset our counter. | 306 // Reset our counter. |
| 306 ids_found_ = 0; | 307 ids_found_ = 0; |
| 307 // Ask the provider to look up all extensions and return them. | 308 // Ask the provider to look up all extensions and return them. |
| 308 provider_->VisitRegisteredExtension(); | 309 provider_->VisitRegisteredExtension(); |
| 309 | 310 |
| 310 return ids_found_; | 311 return ids_found_; |
| 311 } | 312 } |
| 312 | 313 |
| 313 virtual bool OnExternalExtensionFileFound(const std::string& id, | 314 virtual bool OnExternalExtensionFileFound(const std::string& id, |
| 314 const Version* version, | 315 const Version* version, |
| 315 const FilePath& path, | 316 const FilePath& path, |
| 316 Extension::Location unused, | 317 Manifest::Location unused, |
| 317 int creation_flags, | 318 int creation_flags, |
| 318 bool mark_acknowledged) { | 319 bool mark_acknowledged) { |
| 319 EXPECT_EQ(expected_creation_flags_, creation_flags); | 320 EXPECT_EQ(expected_creation_flags_, creation_flags); |
| 320 | 321 |
| 321 ++ids_found_; | 322 ++ids_found_; |
| 322 DictionaryValue* pref; | 323 DictionaryValue* pref; |
| 323 // This tests is to make sure that the provider only notifies us of the | 324 // This tests is to make sure that the provider only notifies us of the |
| 324 // values we gave it. So if the id we doesn't exist in our internal | 325 // values we gave it. So if the id we doesn't exist in our internal |
| 325 // dictionary then something is wrong. | 326 // dictionary then something is wrong. |
| 326 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 327 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 327 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 328 << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
| 328 | 329 |
| 329 EXPECT_TRUE(path.IsAbsolute()); | 330 EXPECT_TRUE(path.IsAbsolute()); |
| 330 if (!fake_base_path_.empty()) | 331 if (!fake_base_path_.empty()) |
| 331 EXPECT_TRUE(fake_base_path_.IsParent(path)); | 332 EXPECT_TRUE(fake_base_path_.IsParent(path)); |
| 332 | 333 |
| 333 if (pref) { | 334 if (pref) { |
| 334 EXPECT_TRUE(provider_->HasExtension(id)); | 335 EXPECT_TRUE(provider_->HasExtension(id)); |
| 335 | 336 |
| 336 // Ask provider if the extension we got back is registered. | 337 // Ask provider if the extension we got back is registered. |
| 337 Extension::Location location = Extension::INVALID; | 338 Manifest::Location location = Manifest::INVALID_LOCATION; |
| 338 scoped_ptr<Version> v1; | 339 scoped_ptr<Version> v1; |
| 339 FilePath crx_path; | 340 FilePath crx_path; |
| 340 | 341 |
| 341 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); | 342 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); |
| 342 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 343 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 343 | 344 |
| 344 scoped_ptr<Version> v2; | 345 scoped_ptr<Version> v2; |
| 345 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); | 346 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); |
| 346 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 347 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 347 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); | 348 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
| 348 EXPECT_EQ(Extension::EXTERNAL_PREF, location); | 349 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
| 349 | 350 |
| 350 // Remove it so we won't count it ever again. | 351 // Remove it so we won't count it ever again. |
| 351 prefs_->Remove(id, NULL); | 352 prefs_->Remove(id, NULL); |
| 352 } | 353 } |
| 353 return true; | 354 return true; |
| 354 } | 355 } |
| 355 | 356 |
| 356 virtual bool OnExternalExtensionUpdateUrlFound( | 357 virtual bool OnExternalExtensionUpdateUrlFound( |
| 357 const std::string& id, const GURL& update_url, | 358 const std::string& id, const GURL& update_url, |
| 358 Extension::Location location) { | 359 Manifest::Location location) { |
| 359 ++ids_found_; | 360 ++ids_found_; |
| 360 DictionaryValue* pref; | 361 DictionaryValue* pref; |
| 361 // This tests is to make sure that the provider only notifies us of the | 362 // This tests is to make sure that the provider only notifies us of the |
| 362 // values we gave it. So if the id we doesn't exist in our internal | 363 // values we gave it. So if the id we doesn't exist in our internal |
| 363 // dictionary then something is wrong. | 364 // dictionary then something is wrong. |
| 364 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 365 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 365 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 366 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
| 366 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location); | 367 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
| 367 | 368 |
| 368 if (pref) { | 369 if (pref) { |
| 369 EXPECT_TRUE(provider_->HasExtension(id)); | 370 EXPECT_TRUE(provider_->HasExtension(id)); |
| 370 | 371 |
| 371 // External extensions with update URLs do not have versions. | 372 // External extensions with update URLs do not have versions. |
| 372 scoped_ptr<Version> v1; | 373 scoped_ptr<Version> v1; |
| 373 Extension::Location location1 = Extension::INVALID; | 374 Manifest::Location location1 = Manifest::INVALID_LOCATION; |
| 374 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 375 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
| 375 EXPECT_FALSE(v1.get()); | 376 EXPECT_FALSE(v1.get()); |
| 376 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1); | 377 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
| 377 | 378 |
| 378 // Remove it so we won't count it again. | 379 // Remove it so we won't count it again. |
| 379 prefs_->Remove(id, NULL); | 380 prefs_->Remove(id, NULL); |
| 380 } | 381 } |
| 381 return true; | 382 return true; |
| 382 } | 383 } |
| 383 | 384 |
| 384 virtual void OnExternalProviderReady( | 385 virtual void OnExternalProviderReady( |
| 385 const extensions::ExternalProviderInterface* provider) { | 386 const extensions::ExternalProviderInterface* provider) { |
| 386 EXPECT_EQ(provider, provider_.get()); | 387 EXPECT_EQ(provider, provider_.get()); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 590 } |
| 590 } | 591 } |
| 591 | 592 |
| 592 void AddMockExternalProvider( | 593 void AddMockExternalProvider( |
| 593 extensions::ExternalProviderInterface* provider) { | 594 extensions::ExternalProviderInterface* provider) { |
| 594 service_->AddProviderForTesting(provider); | 595 service_->AddProviderForTesting(provider); |
| 595 } | 596 } |
| 596 | 597 |
| 597 protected: | 598 protected: |
| 598 void TestExternalProvider(MockExtensionProvider* provider, | 599 void TestExternalProvider(MockExtensionProvider* provider, |
| 599 Extension::Location location); | 600 Manifest::Location location); |
| 600 | 601 |
| 601 void PackCRX(const FilePath& dir_path, | 602 void PackCRX(const FilePath& dir_path, |
| 602 const FilePath& pem_path, | 603 const FilePath& pem_path, |
| 603 const FilePath& crx_path) { | 604 const FilePath& crx_path) { |
| 604 // Use the existing pem key, if provided. | 605 // Use the existing pem key, if provided. |
| 605 FilePath pem_output_path; | 606 FilePath pem_output_path; |
| 606 if (pem_path.value().empty()) { | 607 if (pem_path.value().empty()) { |
| 607 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 608 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 608 } else { | 609 } else { |
| 609 ASSERT_TRUE(file_util::PathExists(pem_path)); | 610 ASSERT_TRUE(file_util::PathExists(pem_path)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 return InstallCRX(path, install_state, Extension::NO_FLAGS); | 688 return InstallCRX(path, install_state, Extension::NO_FLAGS); |
| 688 } | 689 } |
| 689 | 690 |
| 690 const Extension* InstallCRXFromWebStore(const FilePath& path, | 691 const Extension* InstallCRXFromWebStore(const FilePath& path, |
| 691 InstallState install_state) { | 692 InstallState install_state) { |
| 692 StartCRXInstall(path, Extension::FROM_WEBSTORE); | 693 StartCRXInstall(path, Extension::FROM_WEBSTORE); |
| 693 return WaitForCrxInstall(path, install_state); | 694 return WaitForCrxInstall(path, install_state); |
| 694 } | 695 } |
| 695 | 696 |
| 696 const Extension* InstallCRXWithLocation(const FilePath& crx_path, | 697 const Extension* InstallCRXWithLocation(const FilePath& crx_path, |
| 697 Extension::Location install_location, | 698 Manifest::Location install_location, |
| 698 InstallState install_state) { | 699 InstallState install_state) { |
| 699 EXPECT_TRUE(file_util::PathExists(crx_path)) | 700 EXPECT_TRUE(file_util::PathExists(crx_path)) |
| 700 << "Path does not exist: "<< crx_path.value().c_str(); | 701 << "Path does not exist: "<< crx_path.value().c_str(); |
| 701 // no client (silent install) | 702 // no client (silent install) |
| 702 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 703 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 703 installer->set_install_source(install_location); | 704 installer->set_install_source(install_location); |
| 704 installer->InstallCrx(crx_path); | 705 installer->InstallCrx(crx_path); |
| 705 | 706 |
| 706 return WaitForCrxInstall(crx_path, install_state); | 707 return WaitForCrxInstall(crx_path, install_state); |
| 707 } | 708 } |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 service_->Init(); | 1112 service_->Init(); |
| 1112 | 1113 |
| 1113 uint32 expected_num_extensions = 3u; | 1114 uint32 expected_num_extensions = 3u; |
| 1114 ASSERT_EQ(expected_num_extensions, loaded_.size()); | 1115 ASSERT_EQ(expected_num_extensions, loaded_.size()); |
| 1115 | 1116 |
| 1116 EXPECT_EQ(std::string(good0), loaded_[0]->id()); | 1117 EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
| 1117 EXPECT_EQ(std::string("My extension 1"), | 1118 EXPECT_EQ(std::string("My extension 1"), |
| 1118 loaded_[0]->name()); | 1119 loaded_[0]->name()); |
| 1119 EXPECT_EQ(std::string("The first extension that I made."), | 1120 EXPECT_EQ(std::string("The first extension that I made."), |
| 1120 loaded_[0]->description()); | 1121 loaded_[0]->description()); |
| 1121 EXPECT_EQ(Extension::INTERNAL, loaded_[0]->location()); | 1122 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); |
| 1122 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); | 1123 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); |
| 1123 EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); | 1124 EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); |
| 1124 | 1125 |
| 1125 ValidatePrefKeyCount(3); | 1126 ValidatePrefKeyCount(3); |
| 1126 ValidateIntegerPref(good0, "state", Extension::ENABLED); | 1127 ValidateIntegerPref(good0, "state", Extension::ENABLED); |
| 1127 ValidateIntegerPref(good0, "location", Extension::INTERNAL); | 1128 ValidateIntegerPref(good0, "location", Manifest::INTERNAL); |
| 1128 ValidateIntegerPref(good1, "state", Extension::ENABLED); | 1129 ValidateIntegerPref(good1, "state", Extension::ENABLED); |
| 1129 ValidateIntegerPref(good1, "location", Extension::INTERNAL); | 1130 ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
| 1130 ValidateIntegerPref(good2, "state", Extension::ENABLED); | 1131 ValidateIntegerPref(good2, "state", Extension::ENABLED); |
| 1131 ValidateIntegerPref(good2, "location", Extension::INTERNAL); | 1132 ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
| 1132 | 1133 |
| 1133 URLPatternSet expected_patterns; | 1134 URLPatternSet expected_patterns; |
| 1134 AddPattern(&expected_patterns, "file:///*"); | 1135 AddPattern(&expected_patterns, "file:///*"); |
| 1135 AddPattern(&expected_patterns, "http://*.google.com/*"); | 1136 AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1136 AddPattern(&expected_patterns, "https://*.google.com/*"); | 1137 AddPattern(&expected_patterns, "https://*.google.com/*"); |
| 1137 const Extension* extension = loaded_[0]; | 1138 const Extension* extension = loaded_[0]; |
| 1138 const extensions::UserScriptList& scripts = extension->content_scripts(); | 1139 const extensions::UserScriptList& scripts = extension->content_scripts(); |
| 1139 ASSERT_EQ(2u, scripts.size()); | 1140 ASSERT_EQ(2u, scripts.size()); |
| 1140 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); | 1141 EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
| 1141 EXPECT_EQ(2u, scripts[0].js_scripts().size()); | 1142 EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 #else | 1182 #else |
| 1182 ASSERT_EQ(2u, loaded_[1]->plugins().size()); | 1183 ASSERT_EQ(2u, loaded_[1]->plugins().size()); |
| 1183 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), | 1184 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
| 1184 loaded_[1]->plugins()[0].path.value()); | 1185 loaded_[1]->plugins()[0].path.value()); |
| 1185 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); | 1186 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); |
| 1186 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), | 1187 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
| 1187 loaded_[1]->plugins()[1].path.value()); | 1188 loaded_[1]->plugins()[1].path.value()); |
| 1188 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); | 1189 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); |
| 1189 #endif | 1190 #endif |
| 1190 | 1191 |
| 1191 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); | 1192 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
| 1192 | 1193 |
| 1193 int index = expected_num_extensions - 1; | 1194 int index = expected_num_extensions - 1; |
| 1194 EXPECT_EQ(std::string(good2), loaded_[index]->id()); | 1195 EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1195 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); | 1196 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
| 1196 EXPECT_EQ(std::string(""), loaded_[index]->description()); | 1197 EXPECT_EQ(std::string(""), loaded_[index]->description()); |
| 1197 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); | 1198 EXPECT_EQ(0u, loaded_[index]->content_scripts().size()); |
| 1198 EXPECT_EQ(Extension::INTERNAL, loaded_[index]->location()); | 1199 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
| 1199 }; | 1200 }; |
| 1200 | 1201 |
| 1201 // Test loading bad extensions from the profile directory. | 1202 // Test loading bad extensions from the profile directory. |
| 1202 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { | 1203 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
| 1203 // Initialize the test dir with a bad Preferences/extensions. | 1204 // Initialize the test dir with a bad Preferences/extensions. |
| 1204 FilePath source_install_dir = data_dir_ | 1205 FilePath source_install_dir = data_dir_ |
| 1205 .AppendASCII("bad") | 1206 .AppendASCII("bad") |
| 1206 .AppendASCII("Extensions"); | 1207 .AppendASCII("Extensions"); |
| 1207 FilePath pref_path = source_install_dir | 1208 FilePath pref_path = source_install_dir |
| 1208 .DirName() | 1209 .DirName() |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 ValidatePrefKeyCount(0); | 1366 ValidatePrefKeyCount(0); |
| 1366 | 1367 |
| 1367 // A simple extension that should install without error. | 1368 // A simple extension that should install without error. |
| 1368 path = data_dir_.AppendASCII("good.crx"); | 1369 path = data_dir_.AppendASCII("good.crx"); |
| 1369 InstallCRX(path, INSTALL_NEW); | 1370 InstallCRX(path, INSTALL_NEW); |
| 1370 // TODO(erikkay): verify the contents of the installed extension. | 1371 // TODO(erikkay): verify the contents of the installed extension. |
| 1371 | 1372 |
| 1372 int pref_count = 0; | 1373 int pref_count = 0; |
| 1373 ValidatePrefKeyCount(++pref_count); | 1374 ValidatePrefKeyCount(++pref_count); |
| 1374 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 1375 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 1375 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 1376 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 1376 | 1377 |
| 1377 // An extension with page actions. | 1378 // An extension with page actions. |
| 1378 path = data_dir_.AppendASCII("page_action.crx"); | 1379 path = data_dir_.AppendASCII("page_action.crx"); |
| 1379 InstallCRX(path, INSTALL_NEW); | 1380 InstallCRX(path, INSTALL_NEW); |
| 1380 ValidatePrefKeyCount(++pref_count); | 1381 ValidatePrefKeyCount(++pref_count); |
| 1381 ValidateIntegerPref(page_action, "state", Extension::ENABLED); | 1382 ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
| 1382 ValidateIntegerPref(page_action, "location", Extension::INTERNAL); | 1383 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); |
| 1383 | 1384 |
| 1384 // Bad signature. | 1385 // Bad signature. |
| 1385 path = data_dir_.AppendASCII("bad_signature.crx"); | 1386 path = data_dir_.AppendASCII("bad_signature.crx"); |
| 1386 InstallCRX(path, INSTALL_FAILED); | 1387 InstallCRX(path, INSTALL_FAILED); |
| 1387 ValidatePrefKeyCount(pref_count); | 1388 ValidatePrefKeyCount(pref_count); |
| 1388 | 1389 |
| 1389 // 0-length extension file. | 1390 // 0-length extension file. |
| 1390 path = data_dir_.AppendASCII("not_an_extension.crx"); | 1391 path = data_dir_.AppendASCII("not_an_extension.crx"); |
| 1391 InstallCRX(path, INSTALL_FAILED); | 1392 InstallCRX(path, INSTALL_FAILED); |
| 1392 ValidatePrefKeyCount(pref_count); | 1393 ValidatePrefKeyCount(pref_count); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1417 | 1418 |
| 1418 FilePath path = data_dir_.AppendASCII("good.crx"); | 1419 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1419 set_extensions_enabled(true); | 1420 set_extensions_enabled(true); |
| 1420 | 1421 |
| 1421 // Register and install an external extension. | 1422 // Register and install an external extension. |
| 1422 Version version("1.0.0.0"); | 1423 Version version("1.0.0.0"); |
| 1423 service_->OnExternalExtensionFileFound( | 1424 service_->OnExternalExtensionFileFound( |
| 1424 good_crx, | 1425 good_crx, |
| 1425 &version, | 1426 &version, |
| 1426 path, | 1427 path, |
| 1427 Extension::EXTERNAL_PREF, | 1428 Manifest::EXTERNAL_PREF, |
| 1428 Extension::FROM_BOOKMARK, | 1429 Extension::FROM_BOOKMARK, |
| 1429 false /* mark_acknowledged */); | 1430 false /* mark_acknowledged */); |
| 1430 loop_.RunUntilIdle(); | 1431 loop_.RunUntilIdle(); |
| 1431 | 1432 |
| 1432 const Extension* extension = service_->GetExtensionById(good_crx, false); | 1433 const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 1433 ASSERT_TRUE(extension); | 1434 ASSERT_TRUE(extension); |
| 1434 ASSERT_TRUE(extension->from_bookmark()); | 1435 ASSERT_TRUE(extension->from_bookmark()); |
| 1435 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1436 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1436 | 1437 |
| 1437 // Upgrade to version 2.0, the flag should be preserved. | 1438 // Upgrade to version 2.0, the flag should be preserved. |
| 1438 path = data_dir_.AppendASCII("good2.crx"); | 1439 path = data_dir_.AppendASCII("good2.crx"); |
| 1439 UpdateExtension(good_crx, path, ENABLED); | 1440 UpdateExtension(good_crx, path, ENABLED); |
| 1440 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1441 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1441 extension = service_->GetExtensionById(good_crx, false); | 1442 extension = service_->GetExtensionById(good_crx, false); |
| 1442 ASSERT_TRUE(extension); | 1443 ASSERT_TRUE(extension); |
| 1443 ASSERT_TRUE(extension->from_bookmark()); | 1444 ASSERT_TRUE(extension->from_bookmark()); |
| 1444 } | 1445 } |
| 1445 | 1446 |
| 1446 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1447 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
| 1447 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1448 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
| 1448 InitializeEmptyExtensionService(); | 1449 InitializeEmptyExtensionService(); |
| 1449 | 1450 |
| 1450 FilePath path = data_dir_.AppendASCII("good.crx"); | 1451 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1451 set_extensions_enabled(true); | 1452 set_extensions_enabled(true); |
| 1452 | 1453 |
| 1453 Version version("1.0.0.0"); | 1454 Version version("1.0.0.0"); |
| 1454 // Install an external extension. | 1455 // Install an external extension. |
| 1455 service_->OnExternalExtensionFileFound(good_crx, &version, | 1456 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1456 path, Extension::EXTERNAL_PREF, | 1457 path, Manifest::EXTERNAL_PREF, |
| 1457 Extension::NO_FLAGS, false); | 1458 Extension::NO_FLAGS, false); |
| 1458 loop_.RunUntilIdle(); | 1459 loop_.RunUntilIdle(); |
| 1459 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1460 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1460 | 1461 |
| 1461 // Uninstall it and check that its killbit gets set. | 1462 // Uninstall it and check that its killbit gets set. |
| 1462 UninstallExtension(good_crx, false); | 1463 UninstallExtension(good_crx, false); |
| 1463 ValidateIntegerPref(good_crx, "location", | 1464 ValidateIntegerPref(good_crx, "location", |
| 1464 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1465 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1465 | 1466 |
| 1466 // Try to re-install it externally. This should fail because of the killbit. | 1467 // Try to re-install it externally. This should fail because of the killbit. |
| 1467 service_->OnExternalExtensionFileFound(good_crx, &version, | 1468 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1468 path, Extension::EXTERNAL_PREF, | 1469 path, Manifest::EXTERNAL_PREF, |
| 1469 Extension::NO_FLAGS, false); | 1470 Extension::NO_FLAGS, false); |
| 1470 loop_.RunUntilIdle(); | 1471 loop_.RunUntilIdle(); |
| 1471 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1472 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
| 1472 ValidateIntegerPref(good_crx, "location", | 1473 ValidateIntegerPref(good_crx, "location", |
| 1473 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1474 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1474 | 1475 |
| 1475 version = Version("1.0.0.1"); | 1476 version = Version("1.0.0.1"); |
| 1476 // Repeat the same thing with a newer version of the extension. | 1477 // Repeat the same thing with a newer version of the extension. |
| 1477 path = data_dir_.AppendASCII("good2.crx"); | 1478 path = data_dir_.AppendASCII("good2.crx"); |
| 1478 service_->OnExternalExtensionFileFound(good_crx, &version, | 1479 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1479 path, Extension::EXTERNAL_PREF, | 1480 path, Manifest::EXTERNAL_PREF, |
| 1480 Extension::NO_FLAGS, false); | 1481 Extension::NO_FLAGS, false); |
| 1481 loop_.RunUntilIdle(); | 1482 loop_.RunUntilIdle(); |
| 1482 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1483 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
| 1483 ValidateIntegerPref(good_crx, "location", | 1484 ValidateIntegerPref(good_crx, "location", |
| 1484 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1485 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1485 | 1486 |
| 1486 // Try adding the same extension from an external update URL. | 1487 // Try adding the same extension from an external update URL. |
| 1487 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 1488 ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 1488 good_crx, | 1489 good_crx, |
| 1489 GURL("http:://fake.update/url"), | 1490 GURL("http:://fake.update/url"), |
| 1490 Extension::EXTERNAL_PREF_DOWNLOAD)); | 1491 Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 1491 | 1492 |
| 1492 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 1493 ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 1493 } | 1494 } |
| 1494 | 1495 |
| 1495 // Test that uninstalling an external extension does not crash when | 1496 // Test that uninstalling an external extension does not crash when |
| 1496 // the extension could not be loaded. | 1497 // the extension could not be loaded. |
| 1497 // This extension shown in preferences file requires an experimental permission. | 1498 // This extension shown in preferences file requires an experimental permission. |
| 1498 // It could not be loaded without such permission. | 1499 // It could not be loaded without such permission. |
| 1499 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { | 1500 TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
| 1500 FilePath source_install_dir = data_dir_ | 1501 FilePath source_install_dir = data_dir_ |
| 1501 .AppendASCII("good") | 1502 .AppendASCII("good") |
| 1502 .AppendASCII("Extensions"); | 1503 .AppendASCII("Extensions"); |
| 1503 // The preference contains an external extension | 1504 // The preference contains an external extension |
| 1504 // that requires 'experimental' permission. | 1505 // that requires 'experimental' permission. |
| 1505 FilePath pref_path = source_install_dir | 1506 FilePath pref_path = source_install_dir |
| 1506 .DirName() | 1507 .DirName() |
| 1507 .AppendASCII("PreferencesExperimental"); | 1508 .AppendASCII("PreferencesExperimental"); |
| 1508 | 1509 |
| 1509 // Aforementioned extension will not be loaded if | 1510 // Aforementioned extension will not be loaded if |
| 1510 // there is no '--enable-experimental-extension-apis' command line flag. | 1511 // there is no '--enable-experimental-extension-apis' command line flag. |
| 1511 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1512 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1512 | 1513 |
| 1513 service_->Init(); | 1514 service_->Init(); |
| 1514 | 1515 |
| 1515 // Check and try to uninstall it. | 1516 // Check and try to uninstall it. |
| 1516 // If we don't check whether the extension is loaded before we uninstall it | 1517 // If we don't check whether the extension is loaded before we uninstall it |
| 1517 // in CheckExternalUninstall, a crash will happen here because we will get or | 1518 // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1518 // dereference a NULL pointer (extension) inside UninstallExtension. | 1519 // dereference a NULL pointer (extension) inside UninstallExtension. |
| 1519 MockExtensionProvider provider(NULL, Extension::EXTERNAL_REGISTRY); | 1520 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
| 1520 service_->OnExternalProviderReady(&provider); | 1521 service_->OnExternalProviderReady(&provider); |
| 1521 } | 1522 } |
| 1522 | 1523 |
| 1523 // Test that external extensions with incorrect IDs are not installed. | 1524 // Test that external extensions with incorrect IDs are not installed. |
| 1524 TEST_F(ExtensionServiceTest, FailOnWrongId) { | 1525 TEST_F(ExtensionServiceTest, FailOnWrongId) { |
| 1525 InitializeEmptyExtensionService(); | 1526 InitializeEmptyExtensionService(); |
| 1526 FilePath path = data_dir_.AppendASCII("good.crx"); | 1527 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1527 set_extensions_enabled(true); | 1528 set_extensions_enabled(true); |
| 1528 | 1529 |
| 1529 Version version("1.0.0.0"); | 1530 Version version("1.0.0.0"); |
| 1530 | 1531 |
| 1531 const std::string wrong_id = all_zero; | 1532 const std::string wrong_id = all_zero; |
| 1532 const std::string correct_id = good_crx; | 1533 const std::string correct_id = good_crx; |
| 1533 ASSERT_NE(correct_id, wrong_id); | 1534 ASSERT_NE(correct_id, wrong_id); |
| 1534 | 1535 |
| 1535 // Install an external extension with an ID from the external | 1536 // Install an external extension with an ID from the external |
| 1536 // source that is not equal to the ID in the extension manifest. | 1537 // source that is not equal to the ID in the extension manifest. |
| 1537 service_->OnExternalExtensionFileFound( | 1538 service_->OnExternalExtensionFileFound( |
| 1538 wrong_id, &version, path, Extension::EXTERNAL_PREF, | 1539 wrong_id, &version, path, Manifest::EXTERNAL_PREF, |
| 1539 Extension::NO_FLAGS, false); | 1540 Extension::NO_FLAGS, false); |
| 1540 | 1541 |
| 1541 loop_.RunUntilIdle(); | 1542 loop_.RunUntilIdle(); |
| 1542 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1543 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1543 | 1544 |
| 1544 // Try again with the right ID. Expect success. | 1545 // Try again with the right ID. Expect success. |
| 1545 service_->OnExternalExtensionFileFound( | 1546 service_->OnExternalExtensionFileFound( |
| 1546 correct_id, &version, path, Extension::EXTERNAL_PREF, | 1547 correct_id, &version, path, Manifest::EXTERNAL_PREF, |
| 1547 Extension::NO_FLAGS, false); | 1548 Extension::NO_FLAGS, false); |
| 1548 loop_.RunUntilIdle(); | 1549 loop_.RunUntilIdle(); |
| 1549 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1550 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1550 } | 1551 } |
| 1551 | 1552 |
| 1552 // Test that external extensions with incorrect versions are not installed. | 1553 // Test that external extensions with incorrect versions are not installed. |
| 1553 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1554 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
| 1554 InitializeEmptyExtensionService(); | 1555 InitializeEmptyExtensionService(); |
| 1555 FilePath path = data_dir_.AppendASCII("good.crx"); | 1556 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1556 set_extensions_enabled(true); | 1557 set_extensions_enabled(true); |
| 1557 | 1558 |
| 1558 // Install an external extension with a version from the external | 1559 // Install an external extension with a version from the external |
| 1559 // source that is not equal to the version in the extension manifest. | 1560 // source that is not equal to the version in the extension manifest. |
| 1560 Version wrong_version("1.2.3.4"); | 1561 Version wrong_version("1.2.3.4"); |
| 1561 service_->OnExternalExtensionFileFound( | 1562 service_->OnExternalExtensionFileFound( |
| 1562 good_crx, &wrong_version, path, Extension::EXTERNAL_PREF, | 1563 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, |
| 1563 Extension::NO_FLAGS, false); | 1564 Extension::NO_FLAGS, false); |
| 1564 | 1565 |
| 1565 loop_.RunUntilIdle(); | 1566 loop_.RunUntilIdle(); |
| 1566 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1567 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1567 | 1568 |
| 1568 // Try again with the right version. Expect success. | 1569 // Try again with the right version. Expect success. |
| 1569 service_->pending_extension_manager()->Remove(good_crx); | 1570 service_->pending_extension_manager()->Remove(good_crx); |
| 1570 Version correct_version("1.0.0.0"); | 1571 Version correct_version("1.0.0.0"); |
| 1571 service_->OnExternalExtensionFileFound( | 1572 service_->OnExternalExtensionFileFound( |
| 1572 good_crx, &correct_version, path, Extension::EXTERNAL_PREF, | 1573 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, |
| 1573 Extension::NO_FLAGS, false); | 1574 Extension::NO_FLAGS, false); |
| 1574 loop_.RunUntilIdle(); | 1575 loop_.RunUntilIdle(); |
| 1575 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1576 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1576 } | 1577 } |
| 1577 | 1578 |
| 1578 // Install a user script (they get converted automatically to an extension) | 1579 // Install a user script (they get converted automatically to an extension) |
| 1579 TEST_F(ExtensionServiceTest, InstallUserScript) { | 1580 TEST_F(ExtensionServiceTest, InstallUserScript) { |
| 1580 // The details of script conversion are tested elsewhere, this just tests | 1581 // The details of script conversion are tested elsewhere, this just tests |
| 1581 // integration with ExtensionService. | 1582 // integration with ExtensionService. |
| 1582 InitializeEmptyExtensionService(); | 1583 InitializeEmptyExtensionService(); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 | 2050 |
| 2050 TEST_F(ExtensionServiceTest, InstallTheme) { | 2051 TEST_F(ExtensionServiceTest, InstallTheme) { |
| 2051 InitializeEmptyExtensionService(); | 2052 InitializeEmptyExtensionService(); |
| 2052 | 2053 |
| 2053 // A theme. | 2054 // A theme. |
| 2054 FilePath path = data_dir_.AppendASCII("theme.crx"); | 2055 FilePath path = data_dir_.AppendASCII("theme.crx"); |
| 2055 InstallCRX(path, INSTALL_NEW); | 2056 InstallCRX(path, INSTALL_NEW); |
| 2056 int pref_count = 0; | 2057 int pref_count = 0; |
| 2057 ValidatePrefKeyCount(++pref_count); | 2058 ValidatePrefKeyCount(++pref_count); |
| 2058 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); | 2059 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
| 2059 ValidateIntegerPref(theme_crx, "location", Extension::INTERNAL); | 2060 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
| 2060 | 2061 |
| 2061 // A theme when extensions are disabled. Themes can be installed, even when | 2062 // A theme when extensions are disabled. Themes can be installed, even when |
| 2062 // extensions are disabled. | 2063 // extensions are disabled. |
| 2063 set_extensions_enabled(false); | 2064 set_extensions_enabled(false); |
| 2064 path = data_dir_.AppendASCII("theme2.crx"); | 2065 path = data_dir_.AppendASCII("theme2.crx"); |
| 2065 InstallCRX(path, INSTALL_NEW); | 2066 InstallCRX(path, INSTALL_NEW); |
| 2066 ValidatePrefKeyCount(++pref_count); | 2067 ValidatePrefKeyCount(++pref_count); |
| 2067 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); | 2068 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
| 2068 ValidateIntegerPref(theme2_crx, "location", Extension::INTERNAL); | 2069 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); |
| 2069 | 2070 |
| 2070 // A theme with extension elements. Themes cannot have extension elements, | 2071 // A theme with extension elements. Themes cannot have extension elements, |
| 2071 // so any such elements (like content scripts) should be ignored. | 2072 // so any such elements (like content scripts) should be ignored. |
| 2072 set_extensions_enabled(true); | 2073 set_extensions_enabled(true); |
| 2073 { | 2074 { |
| 2074 path = data_dir_.AppendASCII("theme_with_extension.crx"); | 2075 path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 2075 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2076 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2076 ValidatePrefKeyCount(++pref_count); | 2077 ValidatePrefKeyCount(++pref_count); |
| 2077 ASSERT_TRUE(extension); | 2078 ASSERT_TRUE(extension); |
| 2078 EXPECT_TRUE(extension->is_theme()); | 2079 EXPECT_TRUE(extension->is_theme()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 TEST_F(ExtensionServiceTest, InstallApps) { | 2201 TEST_F(ExtensionServiceTest, InstallApps) { |
| 2201 InitializeEmptyExtensionService(); | 2202 InitializeEmptyExtensionService(); |
| 2202 | 2203 |
| 2203 // An empty app. | 2204 // An empty app. |
| 2204 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), | 2205 const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), |
| 2205 INSTALL_NEW); | 2206 INSTALL_NEW); |
| 2206 int pref_count = 0; | 2207 int pref_count = 0; |
| 2207 ValidatePrefKeyCount(++pref_count); | 2208 ValidatePrefKeyCount(++pref_count); |
| 2208 ASSERT_EQ(1u, service_->extensions()->size()); | 2209 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2209 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); | 2210 ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
| 2210 ValidateIntegerPref(app->id(), "location", Extension::INTERNAL); | 2211 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); |
| 2211 | 2212 |
| 2212 // Another app with non-overlapping extent. Should succeed. | 2213 // Another app with non-overlapping extent. Should succeed. |
| 2213 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); | 2214 PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 2214 ValidatePrefKeyCount(++pref_count); | 2215 ValidatePrefKeyCount(++pref_count); |
| 2215 | 2216 |
| 2216 // A third app whose extent overlaps the first. Should fail. | 2217 // A third app whose extent overlaps the first. Should fail. |
| 2217 PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); | 2218 PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); |
| 2218 ValidatePrefKeyCount(pref_count); | 2219 ValidatePrefKeyCount(pref_count); |
| 2219 } | 2220 } |
| 2220 | 2221 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 // Test that when an extension version is reinstalled, nothing happens. | 2397 // Test that when an extension version is reinstalled, nothing happens. |
| 2397 TEST_F(ExtensionServiceTest, Reinstall) { | 2398 TEST_F(ExtensionServiceTest, Reinstall) { |
| 2398 InitializeEmptyExtensionService(); | 2399 InitializeEmptyExtensionService(); |
| 2399 | 2400 |
| 2400 // A simple extension that should install without error. | 2401 // A simple extension that should install without error. |
| 2401 FilePath path = data_dir_.AppendASCII("good.crx"); | 2402 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2402 InstallCRX(path, INSTALL_NEW); | 2403 InstallCRX(path, INSTALL_NEW); |
| 2403 | 2404 |
| 2404 ValidatePrefKeyCount(1); | 2405 ValidatePrefKeyCount(1); |
| 2405 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 2406 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 2406 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 2407 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 2407 | 2408 |
| 2408 // Reinstall the same version, it should overwrite the previous one. | 2409 // Reinstall the same version, it should overwrite the previous one. |
| 2409 InstallCRX(path, INSTALL_UPDATED); | 2410 InstallCRX(path, INSTALL_UPDATED); |
| 2410 | 2411 |
| 2411 ValidatePrefKeyCount(1); | 2412 ValidatePrefKeyCount(1); |
| 2412 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 2413 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 2413 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 2414 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 2414 } | 2415 } |
| 2415 | 2416 |
| 2416 // Test that we can determine if extensions came from the | 2417 // Test that we can determine if extensions came from the |
| 2417 // Chrome web store. | 2418 // Chrome web store. |
| 2418 TEST_F(ExtensionServiceTest, FromWebStore) { | 2419 TEST_F(ExtensionServiceTest, FromWebStore) { |
| 2419 InitializeEmptyExtensionService(); | 2420 InitializeEmptyExtensionService(); |
| 2420 | 2421 |
| 2421 // A simple extension that should install without error. | 2422 // A simple extension that should install without error. |
| 2422 FilePath path = data_dir_.AppendASCII("good.crx"); | 2423 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2423 // Not from web store. | 2424 // Not from web store. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2585 good2->id())); | 2586 good2->id())); |
| 2586 } | 2587 } |
| 2587 | 2588 |
| 2588 // Tests that updating preserves extension location. | 2589 // Tests that updating preserves extension location. |
| 2589 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { | 2590 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
| 2590 InitializeEmptyExtensionService(); | 2591 InitializeEmptyExtensionService(); |
| 2591 | 2592 |
| 2592 FilePath path = data_dir_.AppendASCII("good.crx"); | 2593 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2593 | 2594 |
| 2594 const Extension* good = | 2595 const Extension* good = |
| 2595 InstallCRXWithLocation(path, Extension::EXTERNAL_PREF, INSTALL_NEW); | 2596 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); |
| 2596 | 2597 |
| 2597 ASSERT_EQ("1.0.0.0", good->VersionString()); | 2598 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2598 ASSERT_EQ(good_crx, good->id()); | 2599 ASSERT_EQ(good_crx, good->id()); |
| 2599 | 2600 |
| 2600 path = data_dir_.AppendASCII("good2.crx"); | 2601 path = data_dir_.AppendASCII("good2.crx"); |
| 2601 UpdateExtension(good_crx, path, ENABLED); | 2602 UpdateExtension(good_crx, path, ENABLED); |
| 2602 const Extension* good2 = service_->GetExtensionById(good_crx, false); | 2603 const Extension* good2 = service_->GetExtensionById(good_crx, false); |
| 2603 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2604 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
| 2604 EXPECT_EQ(good2->location(), Extension::EXTERNAL_PREF); | 2605 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); |
| 2605 } | 2606 } |
| 2606 | 2607 |
| 2607 // Makes sure that LOAD extension types can downgrade. | 2608 // Makes sure that LOAD extension types can downgrade. |
| 2608 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { | 2609 TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
| 2609 InitializeEmptyExtensionService(); | 2610 InitializeEmptyExtensionService(); |
| 2610 | 2611 |
| 2611 base::ScopedTempDir temp; | 2612 base::ScopedTempDir temp; |
| 2612 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2613 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2613 | 2614 |
| 2614 // We'll write the extension manifest dynamically to a temporary path | 2615 // We'll write the extension manifest dynamically to a temporary path |
| 2615 // to make it easier to change the version number. | 2616 // to make it easier to change the version number. |
| 2616 FilePath extension_path = temp.path(); | 2617 FilePath extension_path = temp.path(); |
| 2617 FilePath manifest_path = extension_path.Append(Extension::kManifestFilename); | 2618 FilePath manifest_path = extension_path.Append(Extension::kManifestFilename); |
| 2618 ASSERT_FALSE(file_util::PathExists(manifest_path)); | 2619 ASSERT_FALSE(file_util::PathExists(manifest_path)); |
| 2619 | 2620 |
| 2620 // Start with version 2.0. | 2621 // Start with version 2.0. |
| 2621 DictionaryValue manifest; | 2622 DictionaryValue manifest; |
| 2622 manifest.SetString("version", "2.0"); | 2623 manifest.SetString("version", "2.0"); |
| 2623 manifest.SetString("name", "LOAD Downgrade Test"); | 2624 manifest.SetString("name", "LOAD Downgrade Test"); |
| 2624 manifest.SetInteger("manifest_version", 2); | 2625 manifest.SetInteger("manifest_version", 2); |
| 2625 | 2626 |
| 2626 JSONFileValueSerializer serializer(manifest_path); | 2627 JSONFileValueSerializer serializer(manifest_path); |
| 2627 ASSERT_TRUE(serializer.Serialize(manifest)); | 2628 ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2628 | 2629 |
| 2629 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 2630 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 2630 loop_.RunUntilIdle(); | 2631 loop_.RunUntilIdle(); |
| 2631 | 2632 |
| 2632 EXPECT_EQ(0u, GetErrors().size()); | 2633 EXPECT_EQ(0u, GetErrors().size()); |
| 2633 ASSERT_EQ(1u, loaded_.size()); | 2634 ASSERT_EQ(1u, loaded_.size()); |
| 2634 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); | 2635 EXPECT_EQ(Manifest::LOAD, loaded_[0]->location()); |
| 2635 EXPECT_EQ(1u, service_->extensions()->size()); | 2636 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2636 EXPECT_EQ("2.0", loaded_[0]->VersionString()); | 2637 EXPECT_EQ("2.0", loaded_[0]->VersionString()); |
| 2637 | 2638 |
| 2638 // Now set the version number to 1.0, reload the extensions and verify that | 2639 // Now set the version number to 1.0, reload the extensions and verify that |
| 2639 // the downgrade was accepted. | 2640 // the downgrade was accepted. |
| 2640 manifest.SetString("version", "1.0"); | 2641 manifest.SetString("version", "1.0"); |
| 2641 ASSERT_TRUE(serializer.Serialize(manifest)); | 2642 ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2642 | 2643 |
| 2643 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 2644 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 2644 loop_.RunUntilIdle(); | 2645 loop_.RunUntilIdle(); |
| 2645 | 2646 |
| 2646 EXPECT_EQ(0u, GetErrors().size()); | 2647 EXPECT_EQ(0u, GetErrors().size()); |
| 2647 ASSERT_EQ(1u, loaded_.size()); | 2648 ASSERT_EQ(1u, loaded_.size()); |
| 2648 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); | 2649 EXPECT_EQ(Manifest::LOAD, loaded_[0]->location()); |
| 2649 EXPECT_EQ(1u, service_->extensions()->size()); | 2650 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2650 EXPECT_EQ("1.0", loaded_[0]->VersionString()); | 2651 EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 2651 } | 2652 } |
| 2652 | 2653 |
| 2653 #if !defined(OS_CHROMEOS) | 2654 #if !defined(OS_CHROMEOS) |
| 2654 // LOAD extensions with plugins require approval. | 2655 // LOAD extensions with plugins require approval. |
| 2655 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { | 2656 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { |
| 2656 FilePath extension_with_plugin_path = data_dir_ | 2657 FilePath extension_with_plugin_path = data_dir_ |
| 2657 .AppendASCII("good") | 2658 .AppendASCII("good") |
| 2658 .AppendASCII("Extensions") | 2659 .AppendASCII("Extensions") |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 loop_.RunUntilIdle(); | 2727 loop_.RunUntilIdle(); |
| 2727 EXPECT_EQ(1u, loaded_.size()); | 2728 EXPECT_EQ(1u, loaded_.size()); |
| 2728 EXPECT_EQ(2u, service_->extensions()->size()); | 2729 EXPECT_EQ(2u, service_->extensions()->size()); |
| 2729 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 2730 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2730 } | 2731 } |
| 2731 #endif | 2732 #endif |
| 2732 | 2733 |
| 2733 namespace { | 2734 namespace { |
| 2734 | 2735 |
| 2735 bool IsExtension(const Extension& extension) { | 2736 bool IsExtension(const Extension& extension) { |
| 2736 return extension.GetType() == Extension::TYPE_EXTENSION; | 2737 return extension.GetType() == Manifest::TYPE_EXTENSION; |
| 2737 } | 2738 } |
| 2738 | 2739 |
| 2739 } // namespace | 2740 } // namespace |
| 2740 | 2741 |
| 2741 // Test adding a pending extension. | 2742 // Test adding a pending extension. |
| 2742 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { | 2743 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
| 2743 InitializeEmptyExtensionService(); | 2744 InitializeEmptyExtensionService(); |
| 2744 | 2745 |
| 2745 const std::string kFakeId(all_zero); | 2746 const std::string kFakeId(all_zero); |
| 2746 const GURL kFakeUpdateURL("http:://fake.update/url"); | 2747 const GURL kFakeUpdateURL("http:://fake.update/url"); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2816 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx | 2817 #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx |
| 2817 #else | 2818 #else |
| 2818 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx | 2819 #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx |
| 2819 #endif | 2820 #endif |
| 2820 // Test updating a pending CRX as if the source is an external extension | 2821 // Test updating a pending CRX as if the source is an external extension |
| 2821 // with an update URL. In this case we don't know if the CRX is a theme | 2822 // with an update URL. In this case we don't know if the CRX is a theme |
| 2822 // or not. | 2823 // or not. |
| 2823 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { | 2824 TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { |
| 2824 InitializeEmptyExtensionService(); | 2825 InitializeEmptyExtensionService(); |
| 2825 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2826 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 2826 theme_crx, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD)); | 2827 theme_crx, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 2827 | 2828 |
| 2828 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); | 2829 EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
| 2829 | 2830 |
| 2830 FilePath path = data_dir_.AppendASCII("theme.crx"); | 2831 FilePath path = data_dir_.AppendASCII("theme.crx"); |
| 2831 UpdateExtension(theme_crx, path, ENABLED); | 2832 UpdateExtension(theme_crx, path, ENABLED); |
| 2832 | 2833 |
| 2833 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); | 2834 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
| 2834 | 2835 |
| 2835 const Extension* extension = service_->GetExtensionById(theme_crx, true); | 2836 const Extension* extension = service_->GetExtensionById(theme_crx, true); |
| 2836 ASSERT_TRUE(extension); | 2837 ASSERT_TRUE(extension); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2853 kGoodInstallSilently)); | 2854 kGoodInstallSilently)); |
| 2854 | 2855 |
| 2855 // Check that there is a pending crx, with is_from_sync set to true. | 2856 // Check that there is a pending crx, with is_from_sync set to true. |
| 2856 const extensions::PendingExtensionInfo* pending_extension_info; | 2857 const extensions::PendingExtensionInfo* pending_extension_info; |
| 2857 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2858 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2858 GetById(kGoodId))); | 2859 GetById(kGoodId))); |
| 2859 EXPECT_TRUE(pending_extension_info->is_from_sync()); | 2860 EXPECT_TRUE(pending_extension_info->is_from_sync()); |
| 2860 | 2861 |
| 2861 // Add a crx to be updated, with the same ID, from a non-sync source. | 2862 // Add a crx to be updated, with the same ID, from a non-sync source. |
| 2862 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 2863 EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 2863 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); | 2864 kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 2864 | 2865 |
| 2865 // Check that there is a pending crx, with is_from_sync set to false. | 2866 // Check that there is a pending crx, with is_from_sync set to false. |
| 2866 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2867 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2867 GetById(kGoodId))); | 2868 GetById(kGoodId))); |
| 2868 EXPECT_FALSE(pending_extension_info->is_from_sync()); | 2869 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 2869 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, | 2870 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 2870 pending_extension_info->install_source()); | 2871 pending_extension_info->install_source()); |
| 2871 | 2872 |
| 2872 // Add a crx to be installed from the update mechanism. | 2873 // Add a crx to be installed from the update mechanism. |
| 2873 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( | 2874 EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( |
| 2874 kGoodId, GURL(kGoodUpdateURL), &IsExtension, | 2875 kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
| 2875 kGoodInstallSilently)); | 2876 kGoodInstallSilently)); |
| 2876 | 2877 |
| 2877 // Check that the external, non-sync update was not overridden. | 2878 // Check that the external, non-sync update was not overridden. |
| 2878 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> | 2879 ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2879 GetById(kGoodId))); | 2880 GetById(kGoodId))); |
| 2880 EXPECT_FALSE(pending_extension_info->is_from_sync()); | 2881 EXPECT_FALSE(pending_extension_info->is_from_sync()); |
| 2881 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, | 2882 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 2882 pending_extension_info->install_source()); | 2883 pending_extension_info->install_source()); |
| 2883 } | 2884 } |
| 2884 | 2885 |
| 2885 // Updating a theme should fail if the updater is explicitly told that | 2886 // Updating a theme should fail if the updater is explicitly told that |
| 2886 // the CRX is not a theme. | 2887 // the CRX is not a theme. |
| 2887 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { | 2888 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
| 2888 InitializeEmptyExtensionService(); | 2889 InitializeEmptyExtensionService(); |
| 2889 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( | 2890 EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
| 2890 theme_crx, GURL(), &IsExtension, true)); | 2891 theme_crx, GURL(), &IsExtension, true)); |
| 2891 | 2892 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2942 FilePath path = data_dir_.AppendASCII("good.crx"); | 2943 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 2943 const Extension* good = InstallCRX(path, INSTALL_NEW); | 2944 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2944 ASSERT_EQ(1u, service_->extensions()->size()); | 2945 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2945 | 2946 |
| 2946 EXPECT_FALSE(good->is_theme()); | 2947 EXPECT_FALSE(good->is_theme()); |
| 2947 | 2948 |
| 2948 // Use AddExtensionImpl() as AddFrom*() would balk. | 2949 // Use AddExtensionImpl() as AddFrom*() would balk. |
| 2949 service_->pending_extension_manager()->AddExtensionImpl( | 2950 service_->pending_extension_manager()->AddExtensionImpl( |
| 2950 good->id(), extensions::ManifestURL::GetUpdateURL(good), | 2951 good->id(), extensions::ManifestURL::GetUpdateURL(good), |
| 2951 Version(), &IsExtension, kGoodIsFromSync, | 2952 Version(), &IsExtension, kGoodIsFromSync, |
| 2952 kGoodInstallSilently, Extension::INTERNAL); | 2953 kGoodInstallSilently, Manifest::INTERNAL); |
| 2953 UpdateExtension(good->id(), path, ENABLED); | 2954 UpdateExtension(good->id(), path, ENABLED); |
| 2954 | 2955 |
| 2955 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 2956 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2956 } | 2957 } |
| 2957 | 2958 |
| 2958 // Test pref settings for blacklist and unblacklist extensions. | 2959 // Test pref settings for blacklist and unblacklist extensions. |
| 2959 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { | 2960 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
| 2960 InitializeEmptyExtensionService(); | 2961 InitializeEmptyExtensionService(); |
| 2961 std::vector<std::string> blacklist; | 2962 std::vector<std::string> blacklist; |
| 2962 blacklist.push_back(good0); | 2963 blacklist.push_back(good0); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3221 // Mark good.crx for force-installation. | 3222 // Mark good.crx for force-installation. |
| 3222 DictionaryPrefUpdate forcelist_update(profile_->GetPrefs(), | 3223 DictionaryPrefUpdate forcelist_update(profile_->GetPrefs(), |
| 3223 prefs::kExtensionInstallForceList); | 3224 prefs::kExtensionInstallForceList); |
| 3224 extensions::ExternalPolicyLoader::AddExtension( | 3225 extensions::ExternalPolicyLoader::AddExtension( |
| 3225 forcelist_update.Get(), good_crx, "http://example.com/update_url"); | 3226 forcelist_update.Get(), good_crx, "http://example.com/update_url"); |
| 3226 } | 3227 } |
| 3227 | 3228 |
| 3228 // Have policy force-install an extension. | 3229 // Have policy force-install an extension. |
| 3229 MockExtensionProvider* provider = | 3230 MockExtensionProvider* provider = |
| 3230 new MockExtensionProvider(service_, | 3231 new MockExtensionProvider(service_, |
| 3231 Extension::EXTERNAL_POLICY_DOWNLOAD); | 3232 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 3232 AddMockExternalProvider(provider); | 3233 AddMockExternalProvider(provider); |
| 3233 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3234 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3234 data_dir_.AppendASCII("good.crx")); | 3235 data_dir_.AppendASCII("good.crx")); |
| 3235 | 3236 |
| 3236 // Reloading extensions should find our externally registered extension | 3237 // Reloading extensions should find our externally registered extension |
| 3237 // and install it. | 3238 // and install it. |
| 3238 service_->CheckForExternalUpdates(); | 3239 service_->CheckForExternalUpdates(); |
| 3239 loop_.RunUntilIdle(); | 3240 loop_.RunUntilIdle(); |
| 3240 | 3241 |
| 3241 // Extension should be installed despite blacklist. | 3242 // Extension should be installed despite blacklist. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3276 // Create a fake extension to be loaded as though it were read from prefs. | 3277 // Create a fake extension to be loaded as though it were read from prefs. |
| 3277 FilePath path = data_dir_.AppendASCII("management") | 3278 FilePath path = data_dir_.AppendASCII("management") |
| 3278 .AppendASCII("simple_extension"); | 3279 .AppendASCII("simple_extension"); |
| 3279 DictionaryValue manifest; | 3280 DictionaryValue manifest; |
| 3280 manifest.SetString(keys::kName, "simple_extension"); | 3281 manifest.SetString(keys::kName, "simple_extension"); |
| 3281 manifest.SetString(keys::kVersion, "1"); | 3282 manifest.SetString(keys::kVersion, "1"); |
| 3282 // LOAD is for extensions loaded from the command line. We use it here, even | 3283 // LOAD is for extensions loaded from the command line. We use it here, even |
| 3283 // though we're testing loading from prefs, so that we don't need to provide | 3284 // though we're testing loading from prefs, so that we don't need to provide |
| 3284 // an extension key. | 3285 // an extension key. |
| 3285 extensions::ExtensionInfo extension_info(&manifest, "", path, | 3286 extensions::ExtensionInfo extension_info(&manifest, "", path, |
| 3286 Extension::LOAD); | 3287 Manifest::LOAD); |
| 3287 | 3288 |
| 3288 // Ensure we can load it with no management policy in place. | 3289 // Ensure we can load it with no management policy in place. |
| 3289 management_policy_->UnregisterAllProviders(); | 3290 management_policy_->UnregisterAllProviders(); |
| 3290 EXPECT_EQ(0u, service_->extensions()->size()); | 3291 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3291 extensions::InstalledLoader(service_).Load(extension_info, false); | 3292 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3292 EXPECT_EQ(1u, service_->extensions()->size()); | 3293 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3293 | 3294 |
| 3294 const Extension* extension = *(service_->extensions()->begin()); | 3295 const Extension* extension = *(service_->extensions()->begin()); |
| 3295 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); | 3296 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); |
| 3296 EXPECT_EQ(0u, service_->extensions()->size()); | 3297 EXPECT_EQ(0u, service_->extensions()->size()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3390 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3391 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3391 } | 3392 } |
| 3392 | 3393 |
| 3393 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { | 3394 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { |
| 3394 InitializeEmptyExtensionService(); | 3395 InitializeEmptyExtensionService(); |
| 3395 set_extensions_enabled(true); | 3396 set_extensions_enabled(true); |
| 3396 | 3397 |
| 3397 { | 3398 { |
| 3398 // Register and install an external extension. | 3399 // Register and install an external extension. |
| 3399 MockExtensionProvider* provider = | 3400 MockExtensionProvider* provider = |
| 3400 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3401 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 3401 AddMockExternalProvider(provider); | 3402 AddMockExternalProvider(provider); |
| 3402 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3403 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3403 data_dir_.AppendASCII("good.crx")); | 3404 data_dir_.AppendASCII("good.crx")); |
| 3404 } | 3405 } |
| 3405 { | 3406 { |
| 3406 // Have policy force-install an extension. | 3407 // Have policy force-install an extension. |
| 3407 MockExtensionProvider* provider = | 3408 MockExtensionProvider* provider = |
| 3408 new MockExtensionProvider(service_, | 3409 new MockExtensionProvider(service_, |
| 3409 Extension::EXTERNAL_POLICY_DOWNLOAD); | 3410 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 3410 AddMockExternalProvider(provider); | 3411 AddMockExternalProvider(provider); |
| 3411 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 3412 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 3412 data_dir_.AppendASCII("page_action.crx")); | 3413 data_dir_.AppendASCII("page_action.crx")); |
| 3413 } | 3414 } |
| 3414 | 3415 |
| 3415 // Providers are set up. Let them run. | 3416 // Providers are set up. Let them run. |
| 3416 service_->CheckForExternalUpdates(); | 3417 service_->CheckForExternalUpdates(); |
| 3417 loop_.RunUntilIdle(); | 3418 loop_.RunUntilIdle(); |
| 3418 | 3419 |
| 3419 ASSERT_EQ(2u, service_->extensions()->size()); | 3420 ASSERT_EQ(2u, service_->extensions()->size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3438 " \"external_crx\": \"good.crx\"," | 3439 " \"external_crx\": \"good.crx\"," |
| 3439 " \"external_version\": \"1.0.0.0\"," | 3440 " \"external_version\": \"1.0.0.0\"," |
| 3440 " \"is_bookmark_app\": false" | 3441 " \"is_bookmark_app\": false" |
| 3441 " }" | 3442 " }" |
| 3442 "}"; | 3443 "}"; |
| 3443 default_apps::Provider* provider = | 3444 default_apps::Provider* provider = |
| 3444 new default_apps::Provider( | 3445 new default_apps::Provider( |
| 3445 profile_.get(), | 3446 profile_.get(), |
| 3446 service_, | 3447 service_, |
| 3447 new extensions::ExternalTestingLoader(json_data, data_dir_), | 3448 new extensions::ExternalTestingLoader(json_data, data_dir_), |
| 3448 Extension::INTERNAL, | 3449 Manifest::INTERNAL, |
| 3449 Extension::INVALID, | 3450 Manifest::INVALID_LOCATION, |
| 3450 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); | 3451 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
| 3451 | 3452 |
| 3452 AddMockExternalProvider(provider); | 3453 AddMockExternalProvider(provider); |
| 3453 } | 3454 } |
| 3454 | 3455 |
| 3455 ASSERT_EQ(0u, service_->extensions()->size()); | 3456 ASSERT_EQ(0u, service_->extensions()->size()); |
| 3456 service_->CheckForExternalUpdates(); | 3457 service_->CheckForExternalUpdates(); |
| 3457 loop_.RunUntilIdle(); | 3458 loop_.RunUntilIdle(); |
| 3458 | 3459 |
| 3459 ASSERT_EQ(1u, service_->extensions()->size()); | 3460 ASSERT_EQ(1u, service_->extensions()->size()); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3961 | 3962 |
| 3962 FilePath ext1 = data_dir_ | 3963 FilePath ext1 = data_dir_ |
| 3963 .AppendASCII("good") | 3964 .AppendASCII("good") |
| 3964 .AppendASCII("Extensions") | 3965 .AppendASCII("Extensions") |
| 3965 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 3966 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 3966 .AppendASCII("1.0.0.0"); | 3967 .AppendASCII("1.0.0.0"); |
| 3967 extensions::UnpackedInstaller::Create(service_)->Load(ext1); | 3968 extensions::UnpackedInstaller::Create(service_)->Load(ext1); |
| 3968 loop_.RunUntilIdle(); | 3969 loop_.RunUntilIdle(); |
| 3969 EXPECT_EQ(0u, GetErrors().size()); | 3970 EXPECT_EQ(0u, GetErrors().size()); |
| 3970 ASSERT_EQ(1u, loaded_.size()); | 3971 ASSERT_EQ(1u, loaded_.size()); |
| 3971 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); | 3972 EXPECT_EQ(Manifest::LOAD, loaded_[0]->location()); |
| 3972 EXPECT_EQ(1u, service_->extensions()->size()); | 3973 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3973 | 3974 |
| 3974 ValidatePrefKeyCount(1); | 3975 ValidatePrefKeyCount(1); |
| 3975 | 3976 |
| 3976 FilePath no_manifest = data_dir_ | 3977 FilePath no_manifest = data_dir_ |
| 3977 .AppendASCII("bad") | 3978 .AppendASCII("bad") |
| 3978 // .AppendASCII("Extensions") | 3979 // .AppendASCII("Extensions") |
| 3979 .AppendASCII("cccccccccccccccccccccccccccccccc") | 3980 .AppendASCII("cccccccccccccccccccccccccccccccc") |
| 3980 .AppendASCII("1"); | 3981 .AppendASCII("1"); |
| 3981 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); | 3982 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3998 // --load-extension. | 3999 // --load-extension. |
| 3999 TEST_F(ExtensionServiceTest, GenerateID) { | 4000 TEST_F(ExtensionServiceTest, GenerateID) { |
| 4000 InitializeEmptyExtensionService(); | 4001 InitializeEmptyExtensionService(); |
| 4001 | 4002 |
| 4002 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); | 4003 FilePath no_id_ext = data_dir_.AppendASCII("no_id"); |
| 4003 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); | 4004 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
| 4004 loop_.RunUntilIdle(); | 4005 loop_.RunUntilIdle(); |
| 4005 EXPECT_EQ(0u, GetErrors().size()); | 4006 EXPECT_EQ(0u, GetErrors().size()); |
| 4006 ASSERT_EQ(1u, loaded_.size()); | 4007 ASSERT_EQ(1u, loaded_.size()); |
| 4007 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); | 4008 ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); |
| 4008 EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); | 4009 EXPECT_EQ(loaded_[0]->location(), Manifest::LOAD); |
| 4009 | 4010 |
| 4010 ValidatePrefKeyCount(1); | 4011 ValidatePrefKeyCount(1); |
| 4011 | 4012 |
| 4012 std::string previous_id = loaded_[0]->id(); | 4013 std::string previous_id = loaded_[0]->id(); |
| 4013 | 4014 |
| 4014 // If we reload the same path, we should get the same extension ID. | 4015 // If we reload the same path, we should get the same extension ID. |
| 4015 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); | 4016 extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
| 4016 loop_.RunUntilIdle(); | 4017 loop_.RunUntilIdle(); |
| 4017 ASSERT_EQ(1u, loaded_.size()); | 4018 ASSERT_EQ(1u, loaded_.size()); |
| 4018 ASSERT_EQ(previous_id, loaded_[0]->id()); | 4019 ASSERT_EQ(previous_id, loaded_[0]->id()); |
| 4019 } | 4020 } |
| 4020 | 4021 |
| 4021 void ExtensionServiceTest::TestExternalProvider( | 4022 void ExtensionServiceTest::TestExternalProvider( |
| 4022 MockExtensionProvider* provider, Extension::Location location) { | 4023 MockExtensionProvider* provider, Manifest::Location location) { |
| 4023 // Verify that starting with no providers loads no extensions. | 4024 // Verify that starting with no providers loads no extensions. |
| 4024 service_->Init(); | 4025 service_->Init(); |
| 4025 ASSERT_EQ(0u, loaded_.size()); | 4026 ASSERT_EQ(0u, loaded_.size()); |
| 4026 | 4027 |
| 4027 provider->set_visit_count(0); | 4028 provider->set_visit_count(0); |
| 4028 | 4029 |
| 4029 // Register a test extension externally using the mock registry provider. | 4030 // Register a test extension externally using the mock registry provider. |
| 4030 FilePath source_path = data_dir_.AppendASCII("good.crx"); | 4031 FilePath source_path = data_dir_.AppendASCII("good.crx"); |
| 4031 | 4032 |
| 4032 // Add the extension. | 4033 // Add the extension. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 | 4153 |
| 4153 // Tests the external installation feature | 4154 // Tests the external installation feature |
| 4154 #if defined(OS_WIN) | 4155 #if defined(OS_WIN) |
| 4155 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { | 4156 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
| 4156 // This should all work, even when normal extension installation is disabled. | 4157 // This should all work, even when normal extension installation is disabled. |
| 4157 InitializeEmptyExtensionService(); | 4158 InitializeEmptyExtensionService(); |
| 4158 set_extensions_enabled(false); | 4159 set_extensions_enabled(false); |
| 4159 | 4160 |
| 4160 // Now add providers. Extension system takes ownership of the objects. | 4161 // Now add providers. Extension system takes ownership of the objects. |
| 4161 MockExtensionProvider* reg_provider = | 4162 MockExtensionProvider* reg_provider = |
| 4162 new MockExtensionProvider(service_, Extension::EXTERNAL_REGISTRY); | 4163 new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); |
| 4163 AddMockExternalProvider(reg_provider); | 4164 AddMockExternalProvider(reg_provider); |
| 4164 TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY); | 4165 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); |
| 4165 } | 4166 } |
| 4166 #endif | 4167 #endif |
| 4167 | 4168 |
| 4168 TEST_F(ExtensionServiceTest, ExternalInstallPref) { | 4169 TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
| 4169 InitializeEmptyExtensionService(); | 4170 InitializeEmptyExtensionService(); |
| 4170 | 4171 |
| 4171 // Now add providers. Extension system takes ownership of the objects. | 4172 // Now add providers. Extension system takes ownership of the objects. |
| 4172 MockExtensionProvider* pref_provider = | 4173 MockExtensionProvider* pref_provider = |
| 4173 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 4174 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 4174 | 4175 |
| 4175 AddMockExternalProvider(pref_provider); | 4176 AddMockExternalProvider(pref_provider); |
| 4176 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF); | 4177 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); |
| 4177 } | 4178 } |
| 4178 | 4179 |
| 4179 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { | 4180 TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
| 4180 // This should all work, even when normal extension installation is disabled. | 4181 // This should all work, even when normal extension installation is disabled. |
| 4181 InitializeEmptyExtensionService(); | 4182 InitializeEmptyExtensionService(); |
| 4182 set_extensions_enabled(false); | 4183 set_extensions_enabled(false); |
| 4183 | 4184 |
| 4184 // TODO(skerner): The mock provider is not a good model of a provider | 4185 // TODO(skerner): The mock provider is not a good model of a provider |
| 4185 // that works with update URLs, because it adds file and version info. | 4186 // that works with update URLs, because it adds file and version info. |
| 4186 // Extend the mock to work with update URLs. This test checks the | 4187 // Extend the mock to work with update URLs. This test checks the |
| 4187 // behavior that is common to all external extension visitors. The | 4188 // behavior that is common to all external extension visitors. The |
| 4188 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that | 4189 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4189 // what the visitor does results in an extension being downloaded and | 4190 // what the visitor does results in an extension being downloaded and |
| 4190 // installed. | 4191 // installed. |
| 4191 MockExtensionProvider* pref_provider = | 4192 MockExtensionProvider* pref_provider = |
| 4192 new MockExtensionProvider(service_, | 4193 new MockExtensionProvider(service_, |
| 4193 Extension::EXTERNAL_PREF_DOWNLOAD); | 4194 Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 4194 AddMockExternalProvider(pref_provider); | 4195 AddMockExternalProvider(pref_provider); |
| 4195 TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD); | 4196 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 4196 } | 4197 } |
| 4197 | 4198 |
| 4198 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { | 4199 TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { |
| 4199 // This should all work, even when normal extension installation is disabled. | 4200 // This should all work, even when normal extension installation is disabled. |
| 4200 InitializeEmptyExtensionService(); | 4201 InitializeEmptyExtensionService(); |
| 4201 set_extensions_enabled(false); | 4202 set_extensions_enabled(false); |
| 4202 | 4203 |
| 4203 // TODO(skerner): The mock provider is not a good model of a provider | 4204 // TODO(skerner): The mock provider is not a good model of a provider |
| 4204 // that works with update URLs, because it adds file and version info. | 4205 // that works with update URLs, because it adds file and version info. |
| 4205 // Extend the mock to work with update URLs. This test checks the | 4206 // Extend the mock to work with update URLs. This test checks the |
| 4206 // behavior that is common to all external extension visitors. The | 4207 // behavior that is common to all external extension visitors. The |
| 4207 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that | 4208 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4208 // what the visitor does results in an extension being downloaded and | 4209 // what the visitor does results in an extension being downloaded and |
| 4209 // installed. | 4210 // installed. |
| 4210 MockExtensionProvider* pref_provider = | 4211 MockExtensionProvider* pref_provider = |
| 4211 new MockExtensionProvider(service_, | 4212 new MockExtensionProvider(service_, |
| 4212 Extension::EXTERNAL_POLICY_DOWNLOAD); | 4213 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 4213 AddMockExternalProvider(pref_provider); | 4214 AddMockExternalProvider(pref_provider); |
| 4214 TestExternalProvider(pref_provider, Extension::EXTERNAL_POLICY_DOWNLOAD); | 4215 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 4215 } | 4216 } |
| 4216 | 4217 |
| 4217 // Tests that external extensions get uninstalled when the external extension | 4218 // Tests that external extensions get uninstalled when the external extension |
| 4218 // providers can't account for them. | 4219 // providers can't account for them. |
| 4219 TEST_F(ExtensionServiceTest, ExternalUninstall) { | 4220 TEST_F(ExtensionServiceTest, ExternalUninstall) { |
| 4220 // Start the extensions service with one external extension already installed. | 4221 // Start the extensions service with one external extension already installed. |
| 4221 FilePath source_install_dir = data_dir_ | 4222 FilePath source_install_dir = data_dir_ |
| 4222 .AppendASCII("good") | 4223 .AppendASCII("good") |
| 4223 .AppendASCII("Extensions"); | 4224 .AppendASCII("Extensions"); |
| 4224 FilePath pref_path = source_install_dir | 4225 FilePath pref_path = source_install_dir |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4242 ASSERT_EQ(0u, GetErrors().size()); | 4243 ASSERT_EQ(0u, GetErrors().size()); |
| 4243 ASSERT_EQ(0u, loaded_.size()); | 4244 ASSERT_EQ(0u, loaded_.size()); |
| 4244 } | 4245 } |
| 4245 | 4246 |
| 4246 // Test that running multiple update checks simultaneously does not | 4247 // Test that running multiple update checks simultaneously does not |
| 4247 // keep the update from succeeding. | 4248 // keep the update from succeeding. |
| 4248 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { | 4249 TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
| 4249 InitializeEmptyExtensionService(); | 4250 InitializeEmptyExtensionService(); |
| 4250 | 4251 |
| 4251 MockExtensionProvider* provider = | 4252 MockExtensionProvider* provider = |
| 4252 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 4253 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 4253 AddMockExternalProvider(provider); | 4254 AddMockExternalProvider(provider); |
| 4254 | 4255 |
| 4255 // Verify that starting with no providers loads no extensions. | 4256 // Verify that starting with no providers loads no extensions. |
| 4256 service_->Init(); | 4257 service_->Init(); |
| 4257 ASSERT_EQ(0u, loaded_.size()); | 4258 ASSERT_EQ(0u, loaded_.size()); |
| 4258 | 4259 |
| 4259 // Start two checks for updates. | 4260 // Start two checks for updates. |
| 4260 provider->set_visit_count(0); | 4261 provider->set_visit_count(0); |
| 4261 service_->CheckForExternalUpdates(); | 4262 service_->CheckForExternalUpdates(); |
| 4262 service_->CheckForExternalUpdates(); | 4263 service_->CheckForExternalUpdates(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4273 | 4274 |
| 4274 // Two checks for external updates should find the extension, and install it | 4275 // Two checks for external updates should find the extension, and install it |
| 4275 // once. | 4276 // once. |
| 4276 provider->set_visit_count(0); | 4277 provider->set_visit_count(0); |
| 4277 service_->CheckForExternalUpdates(); | 4278 service_->CheckForExternalUpdates(); |
| 4278 service_->CheckForExternalUpdates(); | 4279 service_->CheckForExternalUpdates(); |
| 4279 loop_.RunUntilIdle(); | 4280 loop_.RunUntilIdle(); |
| 4280 EXPECT_EQ(2, provider->visit_count()); | 4281 EXPECT_EQ(2, provider->visit_count()); |
| 4281 ASSERT_EQ(0u, GetErrors().size()); | 4282 ASSERT_EQ(0u, GetErrors().size()); |
| 4282 ASSERT_EQ(1u, loaded_.size()); | 4283 ASSERT_EQ(1u, loaded_.size()); |
| 4283 ASSERT_EQ(Extension::EXTERNAL_PREF, loaded_[0]->location()); | 4284 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
| 4284 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); | 4285 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 4285 ValidatePrefKeyCount(1); | 4286 ValidatePrefKeyCount(1); |
| 4286 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4287 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4287 ValidateIntegerPref(good_crx, "location", Extension::EXTERNAL_PREF); | 4288 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
| 4288 | 4289 |
| 4289 provider->RemoveExtension(good_crx); | 4290 provider->RemoveExtension(good_crx); |
| 4290 provider->set_visit_count(0); | 4291 provider->set_visit_count(0); |
| 4291 service_->CheckForExternalUpdates(); | 4292 service_->CheckForExternalUpdates(); |
| 4292 service_->CheckForExternalUpdates(); | 4293 service_->CheckForExternalUpdates(); |
| 4293 loop_.RunUntilIdle(); | 4294 loop_.RunUntilIdle(); |
| 4294 | 4295 |
| 4295 // Two calls should cause two checks for external extensions. | 4296 // Two calls should cause two checks for external extensions. |
| 4296 // Because the external source no longer includes good_crx, | 4297 // Because the external source no longer includes good_crx, |
| 4297 // good_crx will be uninstalled. So, expect that no extensions | 4298 // good_crx will be uninstalled. So, expect that no extensions |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4682 path.Append(Extension::kManifestFilename), &manifest)); | 4683 path.Append(Extension::kManifestFilename), &manifest)); |
| 4683 | 4684 |
| 4684 service_->component_loader()->Add(manifest, path); | 4685 service_->component_loader()->Add(manifest, path); |
| 4685 service_->Init(); | 4686 service_->Init(); |
| 4686 | 4687 |
| 4687 // Note that we do not pump messages -- the extension should be loaded | 4688 // Note that we do not pump messages -- the extension should be loaded |
| 4688 // immediately. | 4689 // immediately. |
| 4689 | 4690 |
| 4690 EXPECT_EQ(0u, GetErrors().size()); | 4691 EXPECT_EQ(0u, GetErrors().size()); |
| 4691 ASSERT_EQ(1u, loaded_.size()); | 4692 ASSERT_EQ(1u, loaded_.size()); |
| 4692 EXPECT_EQ(Extension::COMPONENT, loaded_[0]->location()); | 4693 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
| 4693 EXPECT_EQ(1u, service_->extensions()->size()); | 4694 EXPECT_EQ(1u, service_->extensions()->size()); |
| 4694 | 4695 |
| 4695 // Component extensions get a prefs entry on first install. | 4696 // Component extensions get a prefs entry on first install. |
| 4696 ValidatePrefKeyCount(1); | 4697 ValidatePrefKeyCount(1); |
| 4697 | 4698 |
| 4698 // Reload all extensions, and make sure it comes back. | 4699 // Reload all extensions, and make sure it comes back. |
| 4699 std::string extension_id = (*service_->extensions()->begin())->id(); | 4700 std::string extension_id = (*service_->extensions()->begin())->id(); |
| 4700 loaded_.clear(); | 4701 loaded_.clear(); |
| 4701 service_->ReloadExtensions(); | 4702 service_->ReloadExtensions(); |
| 4702 ASSERT_EQ(1u, service_->extensions()->size()); | 4703 ASSERT_EQ(1u, service_->extensions()->size()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4822 ASSERT_EQ(list.size(), 1U); | 4823 ASSERT_EQ(list.size(), 1U); |
| 4823 extensions::ExtensionSyncData data(list[0]); | 4824 extensions::ExtensionSyncData data(list[0]); |
| 4824 EXPECT_TRUE(data.enabled()); | 4825 EXPECT_TRUE(data.enabled()); |
| 4825 EXPECT_TRUE(data.incognito_enabled()); | 4826 EXPECT_TRUE(data.incognito_enabled()); |
| 4826 } | 4827 } |
| 4827 } | 4828 } |
| 4828 | 4829 |
| 4829 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { | 4830 TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { |
| 4830 InitializeEmptyExtensionService(); | 4831 InitializeEmptyExtensionService(); |
| 4831 InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), | 4832 InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), |
| 4832 Extension::EXTERNAL_PREF, INSTALL_NEW); | 4833 Manifest::EXTERNAL_PREF, INSTALL_NEW); |
| 4833 const Extension* extension = service_->GetInstalledExtension(good_crx); | 4834 const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 4834 ASSERT_TRUE(extension); | 4835 ASSERT_TRUE(extension); |
| 4835 | 4836 |
| 4836 TestSyncProcessorStub processor; | 4837 TestSyncProcessorStub processor; |
| 4837 service_->MergeDataAndStartSyncing( | 4838 service_->MergeDataAndStartSyncing( |
| 4838 syncer::EXTENSIONS, syncer::SyncDataList(), | 4839 syncer::EXTENSIONS, syncer::SyncDataList(), |
| 4839 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 4840 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4840 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 4841 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 4841 | 4842 |
| 4842 UninstallExtension(good_crx, false); | 4843 UninstallExtension(good_crx, false); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5258 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 5259 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
| 5259 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5260 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5260 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 5261 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
| 5261 | 5262 |
| 5262 const extensions::PendingExtensionInfo* info; | 5263 const extensions::PendingExtensionInfo* info; |
| 5263 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 5264 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 5264 GetById(good_crx))); | 5265 GetById(good_crx))); |
| 5265 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); | 5266 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
| 5266 EXPECT_TRUE(info->is_from_sync()); | 5267 EXPECT_TRUE(info->is_from_sync()); |
| 5267 EXPECT_TRUE(info->install_silently()); | 5268 EXPECT_TRUE(info->install_silently()); |
| 5268 EXPECT_EQ(Extension::INTERNAL, info->install_source()); | 5269 EXPECT_EQ(Manifest::INTERNAL, info->install_source()); |
| 5269 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 5270 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 5270 } | 5271 } |
| 5271 | 5272 |
| 5272 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { | 5273 TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
| 5273 InitializeEmptyExtensionService(); | 5274 InitializeEmptyExtensionService(); |
| 5274 | 5275 |
| 5275 FilePath path = data_dir_.AppendASCII("good.crx"); | 5276 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 5276 InstallCRX(path, INSTALL_NEW); | 5277 InstallCRX(path, INSTALL_NEW); |
| 5277 ValidatePrefKeyCount(1u); | 5278 ValidatePrefKeyCount(1u); |
| 5278 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5279 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5279 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 5280 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 5280 | 5281 |
| 5281 extensions::PendingExtensionManager* pending = | 5282 extensions::PendingExtensionManager* pending = |
| 5282 service_->pending_extension_manager(); | 5283 service_->pending_extension_manager(); |
| 5283 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5284 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5284 | 5285 |
| 5285 // Skip install when the location is the same. | 5286 // Skip install when the location is the same. |
| 5286 EXPECT_FALSE( | 5287 EXPECT_FALSE( |
| 5287 service_->OnExternalExtensionUpdateUrlFound( | 5288 service_->OnExternalExtensionUpdateUrlFound( |
| 5288 kGoodId, GURL(kGoodUpdateURL), Extension::INTERNAL)); | 5289 kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL)); |
| 5289 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5290 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5290 | 5291 |
| 5291 // Install when the location has higher priority. | 5292 // Install when the location has higher priority. |
| 5292 EXPECT_TRUE( | 5293 EXPECT_TRUE( |
| 5293 service_->OnExternalExtensionUpdateUrlFound( | 5294 service_->OnExternalExtensionUpdateUrlFound( |
| 5294 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_POLICY_DOWNLOAD)); | 5295 kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_POLICY_DOWNLOAD)); |
| 5295 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5296 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5296 | 5297 |
| 5297 // Try the low priority again. Should be rejected. | 5298 // Try the low priority again. Should be rejected. |
| 5298 EXPECT_FALSE( | 5299 EXPECT_FALSE( |
| 5299 service_->OnExternalExtensionUpdateUrlFound( | 5300 service_->OnExternalExtensionUpdateUrlFound( |
| 5300 kGoodId, GURL(kGoodUpdateURL), Extension::EXTERNAL_PREF_DOWNLOAD)); | 5301 kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 5301 // The existing record should still be present in the pending extension | 5302 // The existing record should still be present in the pending extension |
| 5302 // manager. | 5303 // manager. |
| 5303 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5304 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5304 | 5305 |
| 5305 pending->Remove(kGoodId); | 5306 pending->Remove(kGoodId); |
| 5306 | 5307 |
| 5307 // Skip install when the location has the same priority as the installed | 5308 // Skip install when the location has the same priority as the installed |
| 5308 // location. | 5309 // location. |
| 5309 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( | 5310 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( |
| 5310 kGoodId, GURL(kGoodUpdateURL), Extension::INTERNAL)); | 5311 kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL)); |
| 5311 | 5312 |
| 5312 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5313 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5313 } | 5314 } |
| 5314 | 5315 |
| 5315 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { | 5316 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
| 5316 Version older_version("0.1.0.0"); | 5317 Version older_version("0.1.0.0"); |
| 5317 Version newer_version("2.0.0.0"); | 5318 Version newer_version("2.0.0.0"); |
| 5318 | 5319 |
| 5319 // We don't want the extension to be installed. A path that doesn't | 5320 // We don't want the extension to be installed. A path that doesn't |
| 5320 // point to a valid CRX ensures this. | 5321 // point to a valid CRX ensures this. |
| 5321 const FilePath kInvalidPathToCrx = FilePath(); | 5322 const FilePath kInvalidPathToCrx = FilePath(); |
| 5322 | 5323 |
| 5323 const int kCreationFlags = 0; | 5324 const int kCreationFlags = 0; |
| 5324 const bool kDontMarkAcknowledged = false; | 5325 const bool kDontMarkAcknowledged = false; |
| 5325 | 5326 |
| 5326 InitializeEmptyExtensionService(); | 5327 InitializeEmptyExtensionService(); |
| 5327 | 5328 |
| 5328 // The test below uses install source constants to test that | 5329 // The test below uses install source constants to test that |
| 5329 // priority is enforced. It assumes a specific ranking of install | 5330 // priority is enforced. It assumes a specific ranking of install |
| 5330 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref | 5331 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref |
| 5331 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). | 5332 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). |
| 5332 // The following assertions verify these assumptions: | 5333 // The following assertions verify these assumptions: |
| 5333 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, | 5334 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5334 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, | 5335 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5335 Extension::EXTERNAL_PREF)); | 5336 Manifest::EXTERNAL_PREF)); |
| 5336 ASSERT_EQ(Extension::EXTERNAL_REGISTRY, | 5337 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5337 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_REGISTRY, | 5338 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5338 Extension::INTERNAL)); | 5339 Manifest::INTERNAL)); |
| 5339 ASSERT_EQ(Extension::EXTERNAL_PREF, | 5340 ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 5340 Extension::GetHigherPriorityLocation(Extension::EXTERNAL_PREF, | 5341 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
| 5341 Extension::INTERNAL)); | 5342 Manifest::INTERNAL)); |
| 5342 | 5343 |
| 5343 extensions::PendingExtensionManager* pending = | 5344 extensions::PendingExtensionManager* pending = |
| 5344 service_->pending_extension_manager(); | 5345 service_->pending_extension_manager(); |
| 5345 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5346 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5346 | 5347 |
| 5347 // Simulate an external source adding the extension as INTERNAL. | 5348 // Simulate an external source adding the extension as INTERNAL. |
| 5348 EXPECT_TRUE( | 5349 EXPECT_TRUE( |
| 5349 service_->OnExternalExtensionFileFound( | 5350 service_->OnExternalExtensionFileFound( |
| 5350 kGoodId, &older_version, kInvalidPathToCrx, | 5351 kGoodId, &older_version, kInvalidPathToCrx, |
| 5351 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5352 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5352 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5353 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5353 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5354 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5354 | 5355 |
| 5355 // Simulate an external source adding the extension as EXTERNAL_PREF. | 5356 // Simulate an external source adding the extension as EXTERNAL_PREF. |
| 5356 EXPECT_TRUE( | 5357 EXPECT_TRUE( |
| 5357 service_->OnExternalExtensionFileFound( | 5358 service_->OnExternalExtensionFileFound( |
| 5358 kGoodId, &older_version, kInvalidPathToCrx, | 5359 kGoodId, &older_version, kInvalidPathToCrx, |
| 5359 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5360 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5360 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5361 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5361 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5362 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5362 | 5363 |
| 5363 // Simulate an external source adding as EXTERNAL_PREF again. | 5364 // Simulate an external source adding as EXTERNAL_PREF again. |
| 5364 // This is rejected because the version and the location are the same as | 5365 // This is rejected because the version and the location are the same as |
| 5365 // the previous installation, which is still pending. | 5366 // the previous installation, which is still pending. |
| 5366 EXPECT_FALSE( | 5367 EXPECT_FALSE( |
| 5367 service_->OnExternalExtensionFileFound( | 5368 service_->OnExternalExtensionFileFound( |
| 5368 kGoodId, &older_version, kInvalidPathToCrx, | 5369 kGoodId, &older_version, kInvalidPathToCrx, |
| 5369 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5370 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5370 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5371 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5371 | 5372 |
| 5372 // Try INTERNAL again. Should fail. | 5373 // Try INTERNAL again. Should fail. |
| 5373 EXPECT_FALSE( | 5374 EXPECT_FALSE( |
| 5374 service_->OnExternalExtensionFileFound( | 5375 service_->OnExternalExtensionFileFound( |
| 5375 kGoodId, &older_version, kInvalidPathToCrx, | 5376 kGoodId, &older_version, kInvalidPathToCrx, |
| 5376 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5377 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5377 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5378 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5378 | 5379 |
| 5379 // Now the registry adds the extension. | 5380 // Now the registry adds the extension. |
| 5380 EXPECT_TRUE( | 5381 EXPECT_TRUE( |
| 5381 service_->OnExternalExtensionFileFound( | 5382 service_->OnExternalExtensionFileFound( |
| 5382 kGoodId, &older_version, kInvalidPathToCrx, | 5383 kGoodId, &older_version, kInvalidPathToCrx, |
| 5383 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); | 5384 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
| 5384 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5385 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5385 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5386 WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5386 | 5387 |
| 5387 // Registry outranks both external pref and internal, so both fail. | 5388 // Registry outranks both external pref and internal, so both fail. |
| 5388 EXPECT_FALSE( | 5389 EXPECT_FALSE( |
| 5389 service_->OnExternalExtensionFileFound( | 5390 service_->OnExternalExtensionFileFound( |
| 5390 kGoodId, &older_version, kInvalidPathToCrx, | 5391 kGoodId, &older_version, kInvalidPathToCrx, |
| 5391 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5392 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5392 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5393 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5393 | 5394 |
| 5394 EXPECT_FALSE( | 5395 EXPECT_FALSE( |
| 5395 service_->OnExternalExtensionFileFound( | 5396 service_->OnExternalExtensionFileFound( |
| 5396 kGoodId, &older_version, kInvalidPathToCrx, | 5397 kGoodId, &older_version, kInvalidPathToCrx, |
| 5397 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5398 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5398 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5399 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5399 | 5400 |
| 5400 pending->Remove(kGoodId); | 5401 pending->Remove(kGoodId); |
| 5401 | 5402 |
| 5402 // Install the extension. | 5403 // Install the extension. |
| 5403 FilePath path = data_dir_.AppendASCII("good.crx"); | 5404 FilePath path = data_dir_.AppendASCII("good.crx"); |
| 5404 const Extension* ext = InstallCRX(path, INSTALL_NEW); | 5405 const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 5405 ValidatePrefKeyCount(1u); | 5406 ValidatePrefKeyCount(1u); |
| 5406 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5407 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5407 ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); | 5408 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
| 5408 | 5409 |
| 5409 // Now test the logic of OnExternalExtensionFileFound() when the extension | 5410 // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 5410 // being added is already installed. | 5411 // being added is already installed. |
| 5411 | 5412 |
| 5412 // Tests assume |older_version| is less than the installed version, and | 5413 // Tests assume |older_version| is less than the installed version, and |
| 5413 // |newer_version| is greater. Verify this: | 5414 // |newer_version| is greater. Verify this: |
| 5414 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); | 5415 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); |
| 5415 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); | 5416 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); |
| 5416 | 5417 |
| 5417 // An external install for the same location should fail if the version is | 5418 // An external install for the same location should fail if the version is |
| 5418 // older, or the same, and succeed if the version is newer. | 5419 // older, or the same, and succeed if the version is newer. |
| 5419 | 5420 |
| 5420 // Older than the installed version... | 5421 // Older than the installed version... |
| 5421 EXPECT_FALSE( | 5422 EXPECT_FALSE( |
| 5422 service_->OnExternalExtensionFileFound( | 5423 service_->OnExternalExtensionFileFound( |
| 5423 kGoodId, &older_version, kInvalidPathToCrx, | 5424 kGoodId, &older_version, kInvalidPathToCrx, |
| 5424 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5425 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5425 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5426 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5426 | 5427 |
| 5427 // Same version as the installed version... | 5428 // Same version as the installed version... |
| 5428 EXPECT_FALSE( | 5429 EXPECT_FALSE( |
| 5429 service_->OnExternalExtensionFileFound( | 5430 service_->OnExternalExtensionFileFound( |
| 5430 kGoodId, ext->version(), kInvalidPathToCrx, | 5431 kGoodId, ext->version(), kInvalidPathToCrx, |
| 5431 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5432 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5432 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5433 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5433 | 5434 |
| 5434 // Newer than the installed version... | 5435 // Newer than the installed version... |
| 5435 EXPECT_TRUE( | 5436 EXPECT_TRUE( |
| 5436 service_->OnExternalExtensionFileFound( | 5437 service_->OnExternalExtensionFileFound( |
| 5437 kGoodId, &newer_version, kInvalidPathToCrx, | 5438 kGoodId, &newer_version, kInvalidPathToCrx, |
| 5438 Extension::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); | 5439 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 5439 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5440 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5440 | 5441 |
| 5441 // An external install for a higher priority install source should succeed | 5442 // An external install for a higher priority install source should succeed |
| 5442 // if the version is greater. |older_version| is not... | 5443 // if the version is greater. |older_version| is not... |
| 5443 EXPECT_FALSE( | 5444 EXPECT_FALSE( |
| 5444 service_->OnExternalExtensionFileFound( | 5445 service_->OnExternalExtensionFileFound( |
| 5445 kGoodId, &older_version, kInvalidPathToCrx, | 5446 kGoodId, &older_version, kInvalidPathToCrx, |
| 5446 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5447 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5447 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5448 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5448 | 5449 |
| 5449 // |newer_version| is newer. | 5450 // |newer_version| is newer. |
| 5450 EXPECT_TRUE( | 5451 EXPECT_TRUE( |
| 5451 service_->OnExternalExtensionFileFound( | 5452 service_->OnExternalExtensionFileFound( |
| 5452 kGoodId, &newer_version, kInvalidPathToCrx, | 5453 kGoodId, &newer_version, kInvalidPathToCrx, |
| 5453 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5454 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5454 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5455 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5455 | 5456 |
| 5456 // An external install for an even higher priority install source should | 5457 // An external install for an even higher priority install source should |
| 5457 // succeed if the version is greater. | 5458 // succeed if the version is greater. |
| 5458 EXPECT_TRUE( | 5459 EXPECT_TRUE( |
| 5459 service_->OnExternalExtensionFileFound( | 5460 service_->OnExternalExtensionFileFound( |
| 5460 kGoodId, &newer_version, kInvalidPathToCrx, | 5461 kGoodId, &newer_version, kInvalidPathToCrx, |
| 5461 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); | 5462 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
| 5462 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5463 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5463 | 5464 |
| 5464 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, | 5465 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 5465 // adding from external pref will now fail. | 5466 // adding from external pref will now fail. |
| 5466 EXPECT_FALSE( | 5467 EXPECT_FALSE( |
| 5467 service_->OnExternalExtensionFileFound( | 5468 service_->OnExternalExtensionFileFound( |
| 5468 kGoodId, &newer_version, kInvalidPathToCrx, | 5469 kGoodId, &newer_version, kInvalidPathToCrx, |
| 5469 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5470 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5470 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5471 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5471 } | 5472 } |
| 5472 | 5473 |
| 5473 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { | 5474 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
| 5474 Version kVersion123("1.2.3"); | 5475 Version kVersion123("1.2.3"); |
| 5475 Version kVersion124("1.2.4"); | 5476 Version kVersion124("1.2.4"); |
| 5476 Version kVersion125("1.2.5"); | 5477 Version kVersion125("1.2.5"); |
| 5477 const FilePath kInvalidPathToCrx = FilePath(); | 5478 const FilePath kInvalidPathToCrx = FilePath(); |
| 5478 const int kCreationFlags = 0; | 5479 const int kCreationFlags = 0; |
| 5479 const bool kDontMarkAcknowledged = false; | 5480 const bool kDontMarkAcknowledged = false; |
| 5480 | 5481 |
| 5481 InitializeEmptyExtensionService(); | 5482 InitializeEmptyExtensionService(); |
| 5482 | 5483 |
| 5483 extensions::PendingExtensionManager* pending = | 5484 extensions::PendingExtensionManager* pending = |
| 5484 service_->pending_extension_manager(); | 5485 service_->pending_extension_manager(); |
| 5485 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5486 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5486 | 5487 |
| 5487 // An external provider starts installing from a local crx. | 5488 // An external provider starts installing from a local crx. |
| 5488 EXPECT_TRUE( | 5489 EXPECT_TRUE( |
| 5489 service_->OnExternalExtensionFileFound( | 5490 service_->OnExternalExtensionFileFound( |
| 5490 kGoodId, &kVersion123, kInvalidPathToCrx, | 5491 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 5491 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5492 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5492 const extensions::PendingExtensionInfo* info; | 5493 const extensions::PendingExtensionInfo* info; |
| 5493 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5494 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5494 EXPECT_TRUE(info->version().IsValid()); | 5495 EXPECT_TRUE(info->version().IsValid()); |
| 5495 EXPECT_TRUE(info->version().Equals(kVersion123)); | 5496 EXPECT_TRUE(info->version().Equals(kVersion123)); |
| 5496 | 5497 |
| 5497 // Adding a newer version overrides the currently pending version. | 5498 // Adding a newer version overrides the currently pending version. |
| 5498 EXPECT_TRUE( | 5499 EXPECT_TRUE( |
| 5499 service_->OnExternalExtensionFileFound( | 5500 service_->OnExternalExtensionFileFound( |
| 5500 kGoodId, &kVersion124, kInvalidPathToCrx, | 5501 kGoodId, &kVersion124, kInvalidPathToCrx, |
| 5501 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5502 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5502 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5503 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5503 EXPECT_TRUE(info->version().IsValid()); | 5504 EXPECT_TRUE(info->version().IsValid()); |
| 5504 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5505 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 5505 | 5506 |
| 5506 // Adding an older version fails. | 5507 // Adding an older version fails. |
| 5507 EXPECT_FALSE( | 5508 EXPECT_FALSE( |
| 5508 service_->OnExternalExtensionFileFound( | 5509 service_->OnExternalExtensionFileFound( |
| 5509 kGoodId, &kVersion123, kInvalidPathToCrx, | 5510 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 5510 Extension::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 5511 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 5511 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5512 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5512 EXPECT_TRUE(info->version().IsValid()); | 5513 EXPECT_TRUE(info->version().IsValid()); |
| 5513 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5514 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 5514 | 5515 |
| 5515 // Adding an older version fails even when coming from a higher-priority | 5516 // Adding an older version fails even when coming from a higher-priority |
| 5516 // location. | 5517 // location. |
| 5517 EXPECT_FALSE( | 5518 EXPECT_FALSE( |
| 5518 service_->OnExternalExtensionFileFound( | 5519 service_->OnExternalExtensionFileFound( |
| 5519 kGoodId, &kVersion123, kInvalidPathToCrx, | 5520 kGoodId, &kVersion123, kInvalidPathToCrx, |
| 5520 Extension::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); | 5521 Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
| 5521 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5522 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5522 EXPECT_TRUE(info->version().IsValid()); | 5523 EXPECT_TRUE(info->version().IsValid()); |
| 5523 EXPECT_TRUE(info->version().Equals(kVersion124)); | 5524 EXPECT_TRUE(info->version().Equals(kVersion124)); |
| 5524 | 5525 |
| 5525 // Adding the latest version from the webstore overrides a specific version. | 5526 // Adding the latest version from the webstore overrides a specific version. |
| 5526 GURL kUpdateUrl("http://example.com/update"); | 5527 GURL kUpdateUrl("http://example.com/update"); |
| 5527 EXPECT_TRUE( | 5528 EXPECT_TRUE( |
| 5528 service_->OnExternalExtensionUpdateUrlFound( | 5529 service_->OnExternalExtensionUpdateUrlFound( |
| 5529 kGoodId, kUpdateUrl, Extension::EXTERNAL_POLICY_DOWNLOAD)); | 5530 kGoodId, kUpdateUrl, Manifest::EXTERNAL_POLICY_DOWNLOAD)); |
| 5530 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5531 EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5531 EXPECT_FALSE(info->version().IsValid()); | 5532 EXPECT_FALSE(info->version().IsValid()); |
| 5532 } | 5533 } |
| 5533 | 5534 |
| 5534 // This makes sure we can package and install CRX files that use whitelisted | 5535 // This makes sure we can package and install CRX files that use whitelisted |
| 5535 // permissions. | 5536 // permissions. |
| 5536 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { | 5537 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
| 5537 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; | 5538 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
| 5538 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 5539 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 5539 switches::kWhitelistedExtensionID, test_id); | 5540 switches::kWhitelistedExtensionID, test_id); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5563 | 5564 |
| 5564 // All tests use a single extension. Put the id and path in member vars | 5565 // All tests use a single extension. Put the id and path in member vars |
| 5565 // that all methods can read. | 5566 // that all methods can read. |
| 5566 crx_id_ = kGoodId; | 5567 crx_id_ = kGoodId; |
| 5567 crx_path_ = data_dir_.AppendASCII("good.crx"); | 5568 crx_path_ = data_dir_.AppendASCII("good.crx"); |
| 5568 } | 5569 } |
| 5569 | 5570 |
| 5570 // Fake an external source adding a URL to fetch an extension from. | 5571 // Fake an external source adding a URL to fetch an extension from. |
| 5571 bool AddPendingExternalPrefUrl() { | 5572 bool AddPendingExternalPrefUrl() { |
| 5572 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 5573 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 5573 crx_id_, GURL(), Extension::EXTERNAL_PREF_DOWNLOAD); | 5574 crx_id_, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 5574 } | 5575 } |
| 5575 | 5576 |
| 5576 // Fake an external file from external_extensions.json. | 5577 // Fake an external file from external_extensions.json. |
| 5577 bool AddPendingExternalPrefFileInstall() { | 5578 bool AddPendingExternalPrefFileInstall() { |
| 5578 Version version("1.0.0.0"); | 5579 Version version("1.0.0.0"); |
| 5579 | 5580 |
| 5580 return service_->OnExternalExtensionFileFound( | 5581 return service_->OnExternalExtensionFileFound( |
| 5581 crx_id_, &version, crx_path_, Extension::EXTERNAL_PREF, | 5582 crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, |
| 5582 Extension::NO_FLAGS, false); | 5583 Extension::NO_FLAGS, false); |
| 5583 } | 5584 } |
| 5584 | 5585 |
| 5585 // Fake a request from sync to install an extension. | 5586 // Fake a request from sync to install an extension. |
| 5586 bool AddPendingSyncInstall() { | 5587 bool AddPendingSyncInstall() { |
| 5587 return service_->pending_extension_manager()->AddFromSync( | 5588 return service_->pending_extension_manager()->AddFromSync( |
| 5588 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); | 5589 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); |
| 5589 } | 5590 } |
| 5590 | 5591 |
| 5591 // Fake a policy install. | 5592 // Fake a policy install. |
| 5592 bool AddPendingPolicyInstall() { | 5593 bool AddPendingPolicyInstall() { |
| 5593 // Get path to the CRX with id |kGoodId|. | 5594 // Get path to the CRX with id |kGoodId|. |
| 5594 return service_->OnExternalExtensionUpdateUrlFound( | 5595 return service_->OnExternalExtensionUpdateUrlFound( |
| 5595 crx_id_, GURL(), Extension::EXTERNAL_POLICY_DOWNLOAD); | 5596 crx_id_, GURL(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 5596 } | 5597 } |
| 5597 | 5598 |
| 5598 // Get the install source of a pending extension. | 5599 // Get the install source of a pending extension. |
| 5599 Extension::Location GetPendingLocation() { | 5600 Manifest::Location GetPendingLocation() { |
| 5600 const extensions::PendingExtensionInfo* info; | 5601 const extensions::PendingExtensionInfo* info; |
| 5601 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 5602 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 5602 GetById(crx_id_))); | 5603 GetById(crx_id_))); |
| 5603 return info->install_source(); | 5604 return info->install_source(); |
| 5604 } | 5605 } |
| 5605 | 5606 |
| 5606 // Is an extension pending from a sync request? | 5607 // Is an extension pending from a sync request? |
| 5607 bool GetPendingIsFromSync() { | 5608 bool GetPendingIsFromSync() { |
| 5608 const extensions::PendingExtensionInfo* info; | 5609 const extensions::PendingExtensionInfo* info; |
| 5609 EXPECT_TRUE((info = service_->pending_extension_manager()-> | 5610 EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5631 // Test that a pending request for installation of an external CRX from | 5632 // Test that a pending request for installation of an external CRX from |
| 5632 // an update URL overrides a pending request to install the same extension | 5633 // an update URL overrides a pending request to install the same extension |
| 5633 // from sync. | 5634 // from sync. |
| 5634 TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { | 5635 TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { |
| 5635 InitializeEmptyExtensionService(); | 5636 InitializeEmptyExtensionService(); |
| 5636 | 5637 |
| 5637 ASSERT_FALSE(IsCrxInstalled()); | 5638 ASSERT_FALSE(IsCrxInstalled()); |
| 5638 | 5639 |
| 5639 // Install pending extension from sync. | 5640 // Install pending extension from sync. |
| 5640 EXPECT_TRUE(AddPendingSyncInstall()); | 5641 EXPECT_TRUE(AddPendingSyncInstall()); |
| 5641 ASSERT_EQ(Extension::INTERNAL, GetPendingLocation()); | 5642 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
| 5642 EXPECT_TRUE(GetPendingIsFromSync()); | 5643 EXPECT_TRUE(GetPendingIsFromSync()); |
| 5643 ASSERT_FALSE(IsCrxInstalled()); | 5644 ASSERT_FALSE(IsCrxInstalled()); |
| 5644 | 5645 |
| 5645 // Install pending as external prefs json would. | 5646 // Install pending as external prefs json would. |
| 5646 AddPendingExternalPrefFileInstall(); | 5647 AddPendingExternalPrefFileInstall(); |
| 5647 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); | 5648 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
| 5648 ASSERT_FALSE(IsCrxInstalled()); | 5649 ASSERT_FALSE(IsCrxInstalled()); |
| 5649 | 5650 |
| 5650 // Another request from sync should be ignorred. | 5651 // Another request from sync should be ignorred. |
| 5651 EXPECT_FALSE(AddPendingSyncInstall()); | 5652 EXPECT_FALSE(AddPendingSyncInstall()); |
| 5652 ASSERT_EQ(Extension::EXTERNAL_PREF, GetPendingLocation()); | 5653 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
| 5653 ASSERT_FALSE(IsCrxInstalled()); | 5654 ASSERT_FALSE(IsCrxInstalled()); |
| 5654 | 5655 |
| 5655 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 5656 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
| 5656 ASSERT_TRUE(IsCrxInstalled()); | 5657 ASSERT_TRUE(IsCrxInstalled()); |
| 5657 } | 5658 } |
| 5658 | 5659 |
| 5659 // Test that an install of an external CRX from an update overrides | 5660 // Test that an install of an external CRX from an update overrides |
| 5660 // an install of the same extension from sync. | 5661 // an install of the same extension from sync. |
| 5661 TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { | 5662 TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
| 5662 InitializeEmptyExtensionService(); | 5663 InitializeEmptyExtensionService(); |
| 5663 ASSERT_FALSE(IsCrxInstalled()); | 5664 ASSERT_FALSE(IsCrxInstalled()); |
| 5664 | 5665 |
| 5665 EXPECT_TRUE(AddPendingSyncInstall()); | 5666 EXPECT_TRUE(AddPendingSyncInstall()); |
| 5666 ASSERT_EQ(Extension::INTERNAL, GetPendingLocation()); | 5667 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
| 5667 EXPECT_TRUE(GetPendingIsFromSync()); | 5668 EXPECT_TRUE(GetPendingIsFromSync()); |
| 5668 ASSERT_FALSE(IsCrxInstalled()); | 5669 ASSERT_FALSE(IsCrxInstalled()); |
| 5669 | 5670 |
| 5670 ASSERT_TRUE(AddPendingExternalPrefUrl()); | 5671 ASSERT_TRUE(AddPendingExternalPrefUrl()); |
| 5671 ASSERT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); | 5672 ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
| 5672 EXPECT_FALSE(GetPendingIsFromSync()); | 5673 EXPECT_FALSE(GetPendingIsFromSync()); |
| 5673 ASSERT_FALSE(IsCrxInstalled()); | 5674 ASSERT_FALSE(IsCrxInstalled()); |
| 5674 | 5675 |
| 5675 EXPECT_FALSE(AddPendingSyncInstall()); | 5676 EXPECT_FALSE(AddPendingSyncInstall()); |
| 5676 ASSERT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); | 5677 ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
| 5677 EXPECT_FALSE(GetPendingIsFromSync()); | 5678 EXPECT_FALSE(GetPendingIsFromSync()); |
| 5678 ASSERT_FALSE(IsCrxInstalled()); | 5679 ASSERT_FALSE(IsCrxInstalled()); |
| 5679 } | 5680 } |
| 5680 | 5681 |
| 5681 // Test that an external install request stops sync from installing | 5682 // Test that an external install request stops sync from installing |
| 5682 // the same extension. | 5683 // the same extension. |
| 5683 TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { | 5684 TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { |
| 5684 InitializeEmptyExtensionService(); | 5685 InitializeEmptyExtensionService(); |
| 5685 ASSERT_FALSE(IsCrxInstalled()); | 5686 ASSERT_FALSE(IsCrxInstalled()); |
| 5686 | 5687 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5703 ASSERT_FALSE(AddPendingSyncInstall()); | 5704 ASSERT_FALSE(AddPendingSyncInstall()); |
| 5704 } | 5705 } |
| 5705 | 5706 |
| 5706 // Test that installing an external extension displays a GlobalError. | 5707 // Test that installing an external extension displays a GlobalError. |
| 5707 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { | 5708 TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
| 5708 FeatureSwitch::ScopedOverride prompt( | 5709 FeatureSwitch::ScopedOverride prompt( |
| 5709 FeatureSwitch::prompt_for_external_extensions(), true); | 5710 FeatureSwitch::prompt_for_external_extensions(), true); |
| 5710 | 5711 |
| 5711 InitializeEmptyExtensionService(); | 5712 InitializeEmptyExtensionService(); |
| 5712 MockExtensionProvider* provider = | 5713 MockExtensionProvider* provider = |
| 5713 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 5714 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5714 AddMockExternalProvider(provider); | 5715 AddMockExternalProvider(provider); |
| 5715 | 5716 |
| 5716 service_->UpdateExternalExtensionAlert(); | 5717 service_->UpdateExternalExtensionAlert(); |
| 5717 // Should return false, meaning there aren't any extensions that the user | 5718 // Should return false, meaning there aren't any extensions that the user |
| 5718 // needs to know about. | 5719 // needs to know about. |
| 5719 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5720 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5720 | 5721 |
| 5721 // This is a normal extension, installed normally. | 5722 // This is a normal extension, installed normally. |
| 5722 // This should NOT trigger an alert. | 5723 // This should NOT trigger an alert. |
| 5723 set_extensions_enabled(true); | 5724 set_extensions_enabled(true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5748 } | 5749 } |
| 5749 | 5750 |
| 5750 // Test that external extensions are initially disabled, and that enabling | 5751 // Test that external extensions are initially disabled, and that enabling |
| 5751 // them clears the prompt. | 5752 // them clears the prompt. |
| 5752 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { | 5753 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
| 5753 FeatureSwitch::ScopedOverride prompt( | 5754 FeatureSwitch::ScopedOverride prompt( |
| 5754 FeatureSwitch::prompt_for_external_extensions(), true); | 5755 FeatureSwitch::prompt_for_external_extensions(), true); |
| 5755 | 5756 |
| 5756 InitializeEmptyExtensionService(); | 5757 InitializeEmptyExtensionService(); |
| 5757 MockExtensionProvider* provider = | 5758 MockExtensionProvider* provider = |
| 5758 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 5759 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5759 AddMockExternalProvider(provider); | 5760 AddMockExternalProvider(provider); |
| 5760 | 5761 |
| 5761 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 5762 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5762 data_dir_.AppendASCII("page_action.crx")); | 5763 data_dir_.AppendASCII("page_action.crx")); |
| 5763 | 5764 |
| 5764 service_->CheckForExternalUpdates(); | 5765 service_->CheckForExternalUpdates(); |
| 5765 loop_.RunUntilIdle(); | 5766 loop_.RunUntilIdle(); |
| 5766 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 5767 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5767 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); | 5768 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 5768 | 5769 |
| 5769 const Extension* extension = | 5770 const Extension* extension = |
| 5770 service_->disabled_extensions()->GetByID(page_action); | 5771 service_->disabled_extensions()->GetByID(page_action); |
| 5771 EXPECT_TRUE(extension); | 5772 EXPECT_TRUE(extension); |
| 5772 EXPECT_EQ(page_action, extension->id()); | 5773 EXPECT_EQ(page_action, extension->id()); |
| 5773 | 5774 |
| 5774 service_->EnableExtension(page_action); | 5775 service_->EnableExtension(page_action); |
| 5775 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5776 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5776 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5777 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5777 } | 5778 } |
| 5778 | 5779 |
| 5779 // Test that installing multiple external extensions works. | 5780 // Test that installing multiple external extensions works. |
| 5780 TEST_F(ExtensionServiceTest, ExternalInstallMultiple) { | 5781 TEST_F(ExtensionServiceTest, ExternalInstallMultiple) { |
| 5781 FeatureSwitch::ScopedOverride prompt( | 5782 FeatureSwitch::ScopedOverride prompt( |
| 5782 FeatureSwitch::prompt_for_external_extensions(), true); | 5783 FeatureSwitch::prompt_for_external_extensions(), true); |
| 5783 | 5784 |
| 5784 InitializeEmptyExtensionService(); | 5785 InitializeEmptyExtensionService(); |
| 5785 MockExtensionProvider* provider = | 5786 MockExtensionProvider* provider = |
| 5786 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 5787 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5787 AddMockExternalProvider(provider); | 5788 AddMockExternalProvider(provider); |
| 5788 | 5789 |
| 5789 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 5790 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5790 data_dir_.AppendASCII("page_action.crx")); | 5791 data_dir_.AppendASCII("page_action.crx")); |
| 5791 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 5792 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 5792 data_dir_.AppendASCII("good.crx")); | 5793 data_dir_.AppendASCII("good.crx")); |
| 5793 provider->UpdateOrAddExtension(theme_crx, "2.0", | 5794 provider->UpdateOrAddExtension(theme_crx, "2.0", |
| 5794 data_dir_.AppendASCII("theme.crx")); | 5795 data_dir_.AppendASCII("theme.crx")); |
| 5795 | 5796 |
| 5796 service_->CheckForExternalUpdates(); | 5797 service_->CheckForExternalUpdates(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5808 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5809 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5809 } | 5810 } |
| 5810 | 5811 |
| 5811 // Test that a sideloaded extension gets wiped out. | 5812 // Test that a sideloaded extension gets wiped out. |
| 5812 TEST_F(ExtensionServiceTest, WipeOutExtension) { | 5813 TEST_F(ExtensionServiceTest, WipeOutExtension) { |
| 5813 FeatureSwitch::ScopedOverride prompt( | 5814 FeatureSwitch::ScopedOverride prompt( |
| 5814 FeatureSwitch::sideload_wipeout(), true); | 5815 FeatureSwitch::sideload_wipeout(), true); |
| 5815 | 5816 |
| 5816 InitializeEmptyExtensionService(); | 5817 InitializeEmptyExtensionService(); |
| 5817 MockExtensionProvider* provider_registry = | 5818 MockExtensionProvider* provider_registry = |
| 5818 new MockExtensionProvider(service_, Extension::EXTERNAL_REGISTRY); | 5819 new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); |
| 5819 AddMockExternalProvider(provider_registry); | 5820 AddMockExternalProvider(provider_registry); |
| 5820 MockExtensionProvider* provider_pref = | 5821 MockExtensionProvider* provider_pref = |
| 5821 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 5822 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5822 AddMockExternalProvider(provider_pref); | 5823 AddMockExternalProvider(provider_pref); |
| 5823 | 5824 |
| 5824 provider_registry->UpdateOrAddExtension(good_crx, "1.0.0.0", | 5825 provider_registry->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 5825 data_dir_.AppendASCII("good.crx")); | 5826 data_dir_.AppendASCII("good.crx")); |
| 5826 provider_pref->UpdateOrAddExtension(good_crx, "1.0.0.0", | 5827 provider_pref->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 5827 data_dir_.AppendASCII("good.crx")); | 5828 data_dir_.AppendASCII("good.crx")); |
| 5828 | 5829 |
| 5829 service_->CheckForExternalUpdates(); | 5830 service_->CheckForExternalUpdates(); |
| 5830 loop_.RunUntilIdle(); | 5831 loop_.RunUntilIdle(); |
| 5831 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5832 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5832 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5833 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5833 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5834 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5834 | 5835 |
| 5835 ExtensionPrefs* prefs = service_->extension_prefs(); | 5836 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5836 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5837 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5837 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5838 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5838 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5839 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5839 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5840 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5840 } | 5841 } |
| OLD | NEW |