OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 #include "content/public/browser/plugin_service.h" | 90 #include "content/public/browser/plugin_service.h" |
91 #include "content/public/browser/render_process_host.h" | 91 #include "content/public/browser/render_process_host.h" |
92 #include "content/public/browser/storage_partition.h" | 92 #include "content/public/browser/storage_partition.h" |
93 #include "content/public/common/content_constants.h" | 93 #include "content/public/common/content_constants.h" |
94 #include "content/public/test/test_browser_thread_bundle.h" | 94 #include "content/public/test/test_browser_thread_bundle.h" |
95 #include "content/public/test/test_utils.h" | 95 #include "content/public/test/test_utils.h" |
96 #include "extensions/browser/extension_dialog_auto_confirm.h" | 96 #include "extensions/browser/extension_dialog_auto_confirm.h" |
97 #include "extensions/browser/extension_prefs.h" | 97 #include "extensions/browser/extension_prefs.h" |
98 #include "extensions/browser/extension_registry.h" | 98 #include "extensions/browser/extension_registry.h" |
99 #include "extensions/browser/extension_system.h" | 99 #include "extensions/browser/extension_system.h" |
| 100 #include "extensions/browser/external_install_info.h" |
100 #include "extensions/browser/external_provider_interface.h" | 101 #include "extensions/browser/external_provider_interface.h" |
101 #include "extensions/browser/install_flag.h" | 102 #include "extensions/browser/install_flag.h" |
102 #include "extensions/browser/management_policy.h" | 103 #include "extensions/browser/management_policy.h" |
103 #include "extensions/browser/test_extension_registry_observer.h" | 104 #include "extensions/browser/test_extension_registry_observer.h" |
104 #include "extensions/browser/test_management_policy.h" | 105 #include "extensions/browser/test_management_policy.h" |
105 #include "extensions/browser/uninstall_reason.h" | 106 #include "extensions/browser/uninstall_reason.h" |
106 #include "extensions/common/constants.h" | 107 #include "extensions/common/constants.h" |
107 #include "extensions/common/extension.h" | 108 #include "extensions/common/extension.h" |
108 #include "extensions/common/extension_builder.h" | 109 #include "extensions/common/extension_builder.h" |
109 #include "extensions/common/extension_l10n_util.h" | 110 #include "extensions/common/extension_l10n_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 using extensions::AppSorting; | 157 using extensions::AppSorting; |
157 using extensions::Blacklist; | 158 using extensions::Blacklist; |
158 using extensions::CrxInstaller; | 159 using extensions::CrxInstaller; |
159 using extensions::Extension; | 160 using extensions::Extension; |
160 using extensions::ExtensionCreator; | 161 using extensions::ExtensionCreator; |
161 using extensions::ExtensionPrefs; | 162 using extensions::ExtensionPrefs; |
162 using extensions::ExtensionRegistry; | 163 using extensions::ExtensionRegistry; |
163 using extensions::ExtensionResource; | 164 using extensions::ExtensionResource; |
164 using extensions::ExtensionSystem; | 165 using extensions::ExtensionSystem; |
165 using extensions::ExternalInstallError; | 166 using extensions::ExternalInstallError; |
| 167 using extensions::ExternalInstallInfoFile; |
| 168 using extensions::ExternalInstallInfoUpdateUrl; |
| 169 using extensions::ExternalProviderInterface; |
166 using extensions::FakeSafeBrowsingDatabaseManager; | 170 using extensions::FakeSafeBrowsingDatabaseManager; |
167 using extensions::FeatureSwitch; | 171 using extensions::FeatureSwitch; |
168 using extensions::Manifest; | 172 using extensions::Manifest; |
169 using extensions::PermissionSet; | 173 using extensions::PermissionSet; |
170 using extensions::TestExtensionSystem; | 174 using extensions::TestExtensionSystem; |
171 using extensions::UnloadedExtensionInfo; | 175 using extensions::UnloadedExtensionInfo; |
172 using extensions::URLPatternSet; | 176 using extensions::URLPatternSet; |
173 | 177 |
174 namespace keys = extensions::manifest_keys; | 178 namespace keys = extensions::manifest_keys; |
175 | 179 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 245 |
242 void RemoveExtension(const std::string& id) { | 246 void RemoveExtension(const std::string& id) { |
243 extension_map_.erase(id); | 247 extension_map_.erase(id); |
244 } | 248 } |
245 | 249 |
246 // ExternalProvider implementation: | 250 // ExternalProvider implementation: |
247 void VisitRegisteredExtension() override { | 251 void VisitRegisteredExtension() override { |
248 visit_count_++; | 252 visit_count_++; |
249 for (DataMap::const_iterator i = extension_map_.begin(); | 253 for (DataMap::const_iterator i = extension_map_.begin(); |
250 i != extension_map_.end(); ++i) { | 254 i != extension_map_.end(); ++i) { |
251 Version version(i->second.first); | 255 scoped_ptr<Version> version(new Version(i->second.first)); |
252 | 256 |
253 visitor_->OnExternalExtensionFileFound( | 257 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
254 i->first, &version, i->second.second, location_, | 258 i->first, std::move(version), i->second.second, location_, |
255 Extension::NO_FLAGS, false, false); | 259 Extension::NO_FLAGS, false, false)); |
| 260 visitor_->OnExternalExtensionFileFound(*info); |
256 } | 261 } |
257 visitor_->OnExternalProviderReady(this); | 262 visitor_->OnExternalProviderReady(this); |
258 } | 263 } |
259 | 264 |
260 bool HasExtension(const std::string& id) const override { | 265 bool HasExtension(const std::string& id) const override { |
261 return extension_map_.find(id) != extension_map_.end(); | 266 return extension_map_.find(id) != extension_map_.end(); |
262 } | 267 } |
263 | 268 |
264 bool GetExtensionDetails(const std::string& id, | 269 bool GetExtensionDetails(const std::string& id, |
265 Manifest::Location* location, | 270 Manifest::Location* location, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 322 |
318 MockProviderVisitor(base::FilePath fake_base_path, | 323 MockProviderVisitor(base::FilePath fake_base_path, |
319 int expected_creation_flags) | 324 int expected_creation_flags) |
320 : ids_found_(0), | 325 : ids_found_(0), |
321 fake_base_path_(fake_base_path), | 326 fake_base_path_(fake_base_path), |
322 expected_creation_flags_(expected_creation_flags) { | 327 expected_creation_flags_(expected_creation_flags) { |
323 profile_.reset(new TestingProfile); | 328 profile_.reset(new TestingProfile); |
324 } | 329 } |
325 | 330 |
326 int Visit(const std::string& json_data) { | 331 int Visit(const std::string& json_data) { |
| 332 return Visit(json_data, Manifest::EXTERNAL_PREF, |
| 333 Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 334 } |
| 335 |
| 336 int Visit(const std::string& json_data, |
| 337 Manifest::Location crx_location, |
| 338 Manifest::Location download_location) { |
| 339 crx_location_ = crx_location; |
327 // Give the test json file to the provider for parsing. | 340 // Give the test json file to the provider for parsing. |
328 provider_.reset(new extensions::ExternalProviderImpl( | 341 provider_.reset(new extensions::ExternalProviderImpl( |
329 this, | 342 this, new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
330 new extensions::ExternalTestingLoader(json_data, fake_base_path_), | 343 profile_.get(), crx_location, download_location, Extension::NO_FLAGS)); |
331 profile_.get(), | |
332 Manifest::EXTERNAL_PREF, | |
333 Manifest::EXTERNAL_PREF_DOWNLOAD, | |
334 Extension::NO_FLAGS)); | |
335 | 344 |
336 // We also parse the file into a dictionary to compare what we get back | 345 // We also parse the file into a dictionary to compare what we get back |
337 // from the provider. | 346 // from the provider. |
338 JSONStringValueDeserializer deserializer(json_data); | 347 prefs_ = GetDictionaryFromJSON(json_data); |
339 scoped_ptr<base::Value> json_value = deserializer.Deserialize(NULL, NULL); | |
340 | |
341 if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) { | |
342 NOTREACHED() << "Unable to deserialize json data"; | |
343 return -1; | |
344 } else { | |
345 prefs_ = base::DictionaryValue::From(std::move(json_value)); | |
346 } | |
347 | 348 |
348 // Reset our counter. | 349 // Reset our counter. |
349 ids_found_ = 0; | 350 ids_found_ = 0; |
350 // Ask the provider to look up all extensions and return them. | 351 // Ask the provider to look up all extensions and return them. |
351 provider_->VisitRegisteredExtension(); | 352 provider_->VisitRegisteredExtension(); |
352 | 353 |
353 return ids_found_; | 354 return ids_found_; |
354 } | 355 } |
355 | 356 |
356 bool OnExternalExtensionFileFound(const std::string& id, | 357 bool OnExternalExtensionFileFound( |
357 const Version* version, | 358 const ExternalInstallInfoFile& info) override { |
358 const base::FilePath& path, | 359 EXPECT_EQ(expected_creation_flags_, info.creation_flags); |
359 Manifest::Location unused, | |
360 int creation_flags, | |
361 bool mark_acknowledged, | |
362 bool install_immediately) override { | |
363 EXPECT_EQ(expected_creation_flags_, creation_flags); | |
364 | 360 |
365 ++ids_found_; | 361 ++ids_found_; |
366 base::DictionaryValue* pref; | 362 base::DictionaryValue* pref; |
367 // This tests is to make sure that the provider only notifies us of the | 363 // This tests is to make sure that the provider only notifies us of the |
368 // values we gave it. So if the id we doesn't exist in our internal | 364 // values we gave it. So if the id we doesn't exist in our internal |
369 // dictionary then something is wrong. | 365 // dictionary then something is wrong. |
370 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 366 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) |
371 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 367 << "Got back ID (" << info.extension_id.c_str() |
| 368 << ") we weren't expecting"; |
372 | 369 |
373 EXPECT_TRUE(path.IsAbsolute()); | 370 EXPECT_TRUE(info.path.IsAbsolute()); |
374 if (!fake_base_path_.empty()) | 371 if (!fake_base_path_.empty()) |
375 EXPECT_TRUE(fake_base_path_.IsParent(path)); | 372 EXPECT_TRUE(fake_base_path_.IsParent(info.path)); |
376 | 373 |
377 if (pref) { | 374 if (pref) { |
378 EXPECT_TRUE(provider_->HasExtension(id)); | 375 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); |
379 | 376 |
380 // Ask provider if the extension we got back is registered. | 377 // Ask provider if the extension we got back is registered. |
381 Manifest::Location location = Manifest::INVALID_LOCATION; | 378 Manifest::Location location = Manifest::INVALID_LOCATION; |
382 scoped_ptr<Version> v1; | 379 scoped_ptr<Version> v1; |
383 base::FilePath crx_path; | 380 base::FilePath crx_path; |
384 | 381 |
385 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); | 382 EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1)); |
386 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 383 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); |
387 | 384 |
388 scoped_ptr<Version> v2; | 385 scoped_ptr<Version> v2; |
389 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); | 386 EXPECT_TRUE( |
390 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 387 provider_->GetExtensionDetails(info.extension_id, &location, &v2)); |
391 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); | 388 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); |
392 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); | 389 EXPECT_STREQ(info.version->GetString().c_str(), v2->GetString().c_str()); |
| 390 EXPECT_EQ(crx_location_, location); |
393 | 391 |
394 // Remove it so we won't count it ever again. | 392 // Remove it so we won't count it ever again. |
395 prefs_->Remove(id, NULL); | 393 prefs_->Remove(info.extension_id, NULL); |
396 } | 394 } |
397 return true; | 395 return true; |
398 } | 396 } |
399 | 397 |
400 bool OnExternalExtensionUpdateUrlFound(const std::string& id, | 398 bool OnExternalExtensionUpdateUrlFound( |
401 const std::string& install_parameter, | 399 const ExternalInstallInfoUpdateUrl& info, |
402 const GURL& update_url, | 400 bool is_initial_load) override { |
403 Manifest::Location location, | |
404 int creation_flags, | |
405 bool mark_acknowledged) override { | |
406 ++ids_found_; | 401 ++ids_found_; |
407 base::DictionaryValue* pref; | 402 base::DictionaryValue* pref; |
408 // This tests is to make sure that the provider only notifies us of the | 403 // This tests is to make sure that the provider only notifies us of the |
409 // values we gave it. So if the id we doesn't exist in our internal | 404 // values we gave it. So if the id we doesn't exist in our internal |
410 // dictionary then something is wrong. | 405 // dictionary then something is wrong. |
411 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 406 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) |
412 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 407 << L"Got back ID (" << info.extension_id.c_str() |
413 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); | 408 << ") we weren't expecting"; |
| 409 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location); |
414 | 410 |
415 if (pref) { | 411 if (pref) { |
416 EXPECT_TRUE(provider_->HasExtension(id)); | 412 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); |
417 | 413 |
418 // External extensions with update URLs do not have versions. | 414 // External extensions with update URLs do not have versions. |
419 scoped_ptr<Version> v1; | 415 scoped_ptr<Version> v1; |
420 Manifest::Location location1 = Manifest::INVALID_LOCATION; | 416 Manifest::Location location1 = Manifest::INVALID_LOCATION; |
421 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 417 EXPECT_TRUE( |
| 418 provider_->GetExtensionDetails(info.extension_id, &location1, &v1)); |
422 EXPECT_FALSE(v1.get()); | 419 EXPECT_FALSE(v1.get()); |
423 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); | 420 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
424 | 421 |
425 std::string parsed_install_parameter; | 422 std::string parsed_install_parameter; |
426 pref->GetString("install_parameter", &parsed_install_parameter); | 423 pref->GetString("install_parameter", &parsed_install_parameter); |
427 EXPECT_EQ(parsed_install_parameter, install_parameter); | 424 EXPECT_EQ(parsed_install_parameter, info.install_parameter); |
428 | 425 |
429 // Remove it so we won't count it again. | 426 // Remove it so we won't count it again. |
430 prefs_->Remove(id, NULL); | 427 prefs_->Remove(info.extension_id, NULL); |
431 } | 428 } |
432 return true; | 429 return true; |
433 } | 430 } |
434 | 431 |
| 432 void OnExternalProviderUpdateComplete( |
| 433 const ExternalProviderInterface* provider, |
| 434 const ScopedVector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 435 const ScopedVector<ExternalInstallInfoFile>& file_extensions, |
| 436 const std::set<std::string>& removed_extensions) override { |
| 437 ADD_FAILURE() << "MockProviderVisitor does not provide incremental updates," |
| 438 " use MockUpdateProviderVisitor instead."; |
| 439 } |
| 440 |
435 void OnExternalProviderReady( | 441 void OnExternalProviderReady( |
436 const extensions::ExternalProviderInterface* provider) override { | 442 const extensions::ExternalProviderInterface* provider) override { |
437 EXPECT_EQ(provider, provider_.get()); | 443 EXPECT_EQ(provider, provider_.get()); |
438 EXPECT_TRUE(provider->IsReady()); | 444 EXPECT_TRUE(provider->IsReady()); |
439 } | 445 } |
440 | 446 |
441 Profile* profile() { return profile_.get(); } | 447 Profile* profile() { return profile_.get(); } |
442 | 448 |
| 449 protected: |
| 450 scoped_ptr<extensions::ExternalProviderImpl> provider_; |
| 451 |
| 452 scoped_ptr<base::DictionaryValue> GetDictionaryFromJSON( |
| 453 const std::string& json_data) { |
| 454 // We also parse the file into a dictionary to compare what we get back |
| 455 // from the provider. |
| 456 JSONStringValueDeserializer deserializer(json_data); |
| 457 scoped_ptr<base::Value> json_value = deserializer.Deserialize(NULL, NULL); |
| 458 |
| 459 if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 460 ADD_FAILURE() << "Unable to deserialize json data"; |
| 461 return scoped_ptr<base::DictionaryValue>(); |
| 462 } else { |
| 463 return base::DictionaryValue::From(std::move(json_value)); |
| 464 } |
| 465 } |
| 466 |
443 private: | 467 private: |
444 int ids_found_; | 468 int ids_found_; |
445 base::FilePath fake_base_path_; | 469 base::FilePath fake_base_path_; |
446 int expected_creation_flags_; | 470 int expected_creation_flags_; |
447 scoped_ptr<extensions::ExternalProviderImpl> provider_; | 471 Manifest::Location crx_location_; |
448 scoped_ptr<base::DictionaryValue> prefs_; | 472 scoped_ptr<base::DictionaryValue> prefs_; |
449 scoped_ptr<TestingProfile> profile_; | 473 scoped_ptr<TestingProfile> profile_; |
450 | 474 |
451 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 475 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
452 }; | 476 }; |
453 | 477 |
| 478 // Mock provider that can simulate incremental update like |
| 479 // ExternalRegistryLoader. |
| 480 class MockUpdateProviderVisitor : public MockProviderVisitor { |
| 481 public: |
| 482 // The provider will return |fake_base_path| from |
| 483 // GetBaseCrxFilePath(). User can test the behavior with |
| 484 // and without an empty path using this parameter. |
| 485 explicit MockUpdateProviderVisitor(base::FilePath fake_base_path) |
| 486 : MockProviderVisitor(fake_base_path) {} |
| 487 |
| 488 void VisitDueToUpdate(const std::string& json_data) { |
| 489 update_url_extension_ids_.clear(); |
| 490 file_extension_ids_.clear(); |
| 491 removed_extension_ids_.clear(); |
| 492 |
| 493 scoped_ptr<base::DictionaryValue> new_prefs = |
| 494 GetDictionaryFromJSON(json_data); |
| 495 if (!new_prefs) |
| 496 return; |
| 497 provider_->UpdatePrefs(new_prefs.release()); |
| 498 } |
| 499 |
| 500 void OnExternalProviderUpdateComplete( |
| 501 const ExternalProviderInterface* provider, |
| 502 const ScopedVector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 503 const ScopedVector<ExternalInstallInfoFile>& file_extensions, |
| 504 const std::set<std::string>& removed_extensions) override { |
| 505 for (const auto& extension_info : update_url_extensions) |
| 506 update_url_extension_ids_.insert(extension_info->extension_id); |
| 507 EXPECT_EQ(update_url_extension_ids_.size(), update_url_extensions.size()); |
| 508 |
| 509 for (const auto& extension_info : file_extensions) |
| 510 file_extension_ids_.insert(extension_info->extension_id); |
| 511 EXPECT_EQ(file_extension_ids_.size(), file_extensions.size()); |
| 512 |
| 513 for (const auto& extension_id : removed_extensions) |
| 514 removed_extension_ids_.insert(extension_id); |
| 515 } |
| 516 |
| 517 size_t GetUpdateURLExtensionCount() { |
| 518 return update_url_extension_ids_.size(); |
| 519 } |
| 520 size_t GetFileExtensionCount() { return file_extension_ids_.size(); } |
| 521 size_t GetRemovedExtensionCount() { return removed_extension_ids_.size(); } |
| 522 |
| 523 bool HasSeenUpdateWithUpdateUrl(const std::string& extension_id) { |
| 524 return update_url_extension_ids_.count(extension_id) > 0u; |
| 525 } |
| 526 bool HasSeenUpdateWithFile(const std::string& extension_id) { |
| 527 return file_extension_ids_.count(extension_id) > 0u; |
| 528 } |
| 529 bool HasSeenRemoval(const std::string& extension_id) { |
| 530 return removed_extension_ids_.count(extension_id) > 0u; |
| 531 } |
| 532 |
| 533 private: |
| 534 std::set<std::string> update_url_extension_ids_; |
| 535 std::set<std::string> file_extension_ids_; |
| 536 std::set<std::string> removed_extension_ids_; |
| 537 |
| 538 DISALLOW_COPY_AND_ASSIGN(MockUpdateProviderVisitor); |
| 539 }; |
| 540 |
454 class ExtensionServiceTest | 541 class ExtensionServiceTest |
455 : public extensions::ExtensionServiceTestWithInstall { | 542 : public extensions::ExtensionServiceTestWithInstall { |
456 public: | 543 public: |
457 ExtensionServiceTest() { | 544 ExtensionServiceTest() { |
458 // The extension subsystem posts logging tasks to be done after | 545 // The extension subsystem posts logging tasks to be done after |
459 // browser startup. There's no StartupObserver as there normally | 546 // browser startup. There's no StartupObserver as there normally |
460 // would be since we're in a unit test, so we have to explicitly | 547 // would be since we're in a unit test, so we have to explicitly |
461 // note tasks should be processed. | 548 // note tasks should be processed. |
462 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); | 549 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
463 } | 550 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 // extension object. | 1109 // extension object. |
1023 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { | 1110 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
1024 const char kPrefFromBookmark[] = "from_bookmark"; | 1111 const char kPrefFromBookmark[] = "from_bookmark"; |
1025 | 1112 |
1026 InitializeEmptyExtensionService(); | 1113 InitializeEmptyExtensionService(); |
1027 | 1114 |
1028 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1115 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1029 service()->set_extensions_enabled(true); | 1116 service()->set_extensions_enabled(true); |
1030 | 1117 |
1031 // Register and install an external extension. | 1118 // Register and install an external extension. |
1032 Version version("1.0.0.0"); | 1119 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1033 content::WindowedNotificationObserver observer( | 1120 content::WindowedNotificationObserver observer( |
1034 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1121 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1035 content::NotificationService::AllSources()); | 1122 content::NotificationService::AllSources()); |
1036 if (service()->OnExternalExtensionFileFound( | 1123 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
1037 good_crx, | 1124 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, |
1038 &version, | 1125 Extension::FROM_BOOKMARK, false /* mark_acknowledged */, |
1039 path, | 1126 false /* install_immediately */)); |
1040 Manifest::EXTERNAL_PREF, | 1127 if (service()->OnExternalExtensionFileFound(*info)) |
1041 Extension::FROM_BOOKMARK, | |
1042 false /* mark_acknowledged */, | |
1043 false /* install_immediately */)) { | |
1044 observer.Wait(); | 1128 observer.Wait(); |
1045 } | |
1046 | 1129 |
1047 const Extension* extension = service()->GetExtensionById(good_crx, false); | 1130 const Extension* extension = service()->GetExtensionById(good_crx, false); |
1048 ASSERT_TRUE(extension); | 1131 ASSERT_TRUE(extension); |
1049 ASSERT_TRUE(extension->from_bookmark()); | 1132 ASSERT_TRUE(extension->from_bookmark()); |
1050 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); | 1133 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
1051 | 1134 |
1052 // Upgrade to version 2.0, the flag should be preserved. | 1135 // Upgrade to version 2.0, the flag should be preserved. |
1053 path = data_dir().AppendASCII("good2.crx"); | 1136 path = data_dir().AppendASCII("good2.crx"); |
1054 UpdateExtension(good_crx, path, ENABLED); | 1137 UpdateExtension(good_crx, path, ENABLED); |
1055 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); | 1138 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
1056 extension = service()->GetExtensionById(good_crx, false); | 1139 extension = service()->GetExtensionById(good_crx, false); |
1057 ASSERT_TRUE(extension); | 1140 ASSERT_TRUE(extension); |
1058 ASSERT_TRUE(extension->from_bookmark()); | 1141 ASSERT_TRUE(extension->from_bookmark()); |
1059 } | 1142 } |
1060 | 1143 |
1061 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1144 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
1062 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1145 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
1063 InitializeEmptyExtensionService(); | 1146 InitializeEmptyExtensionService(); |
1064 | 1147 |
1065 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1148 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1066 service()->set_extensions_enabled(true); | 1149 service()->set_extensions_enabled(true); |
1067 | 1150 |
1068 // Install an external extension. | 1151 // Install an external extension. |
1069 Version version("1.0.0.0"); | |
1070 content::WindowedNotificationObserver observer( | 1152 content::WindowedNotificationObserver observer( |
1071 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1153 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1072 content::NotificationService::AllSources()); | 1154 content::NotificationService::AllSources()); |
1073 if (service()->OnExternalExtensionFileFound(good_crx, | 1155 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1074 &version, | 1156 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
1075 path, | 1157 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, |
1076 Manifest::EXTERNAL_PREF, | 1158 Extension::NO_FLAGS, false, false)); |
1077 Extension::NO_FLAGS, | 1159 if (service()->OnExternalExtensionFileFound(*info)) |
1078 false, | |
1079 false)) { | |
1080 observer.Wait(); | 1160 observer.Wait(); |
1081 } | |
1082 | 1161 |
1083 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1162 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1084 | 1163 |
1085 // Uninstall it and check that its killbit gets set. | 1164 // Uninstall it and check that its killbit gets set. |
1086 UninstallExtension(good_crx, false); | 1165 UninstallExtension(good_crx, false); |
1087 ValidateIntegerPref(good_crx, "state", | 1166 ValidateIntegerPref(good_crx, "state", |
1088 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1167 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1089 | 1168 |
1090 // Try to re-install it externally. This should fail because of the killbit. | 1169 // Try to re-install it externally. This should fail because of the killbit. |
1091 service()->OnExternalExtensionFileFound(good_crx, | 1170 service()->OnExternalExtensionFileFound(*info); |
1092 &version, | |
1093 path, | |
1094 Manifest::EXTERNAL_PREF, | |
1095 Extension::NO_FLAGS, | |
1096 false, | |
1097 false); | |
1098 base::RunLoop().RunUntilIdle(); | 1171 base::RunLoop().RunUntilIdle(); |
1099 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); | 1172 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
1100 ValidateIntegerPref(good_crx, "state", | 1173 ValidateIntegerPref(good_crx, "state", |
1101 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1174 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1102 | 1175 |
1103 version = Version("1.0.0.1"); | 1176 version.reset(new Version("1.0.0.1")); |
1104 // Repeat the same thing with a newer version of the extension. | 1177 // Repeat the same thing with a newer version of the extension. |
1105 path = data_dir().AppendASCII("good2.crx"); | 1178 path = data_dir().AppendASCII("good2.crx"); |
1106 service()->OnExternalExtensionFileFound(good_crx, | 1179 info.reset(new ExternalInstallInfoFile(good_crx, std::move(version), path, |
1107 &version, | 1180 Manifest::EXTERNAL_PREF, |
1108 path, | 1181 Extension::NO_FLAGS, false, false)); |
1109 Manifest::EXTERNAL_PREF, | 1182 service()->OnExternalExtensionFileFound(*info); |
1110 Extension::NO_FLAGS, | |
1111 false, | |
1112 false); | |
1113 base::RunLoop().RunUntilIdle(); | 1183 base::RunLoop().RunUntilIdle(); |
1114 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); | 1184 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
1115 ValidateIntegerPref(good_crx, "state", | 1185 ValidateIntegerPref(good_crx, "state", |
1116 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1186 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1117 | 1187 |
1118 // Try adding the same extension from an external update URL. | 1188 // Try adding the same extension from an external update URL. |
1119 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( | 1189 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
1120 good_crx, | 1190 good_crx, |
1121 std::string(), | 1191 std::string(), |
1122 GURL("http:://fake.update/url"), | 1192 GURL("http:://fake.update/url"), |
(...skipping 30 matching lines...) Expand all Loading... |
1153 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); | 1223 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
1154 service()->OnExternalProviderReady(&provider); | 1224 service()->OnExternalProviderReady(&provider); |
1155 } | 1225 } |
1156 | 1226 |
1157 // Test that external extensions with incorrect IDs are not installed. | 1227 // Test that external extensions with incorrect IDs are not installed. |
1158 TEST_F(ExtensionServiceTest, FailOnWrongId) { | 1228 TEST_F(ExtensionServiceTest, FailOnWrongId) { |
1159 InitializeEmptyExtensionService(); | 1229 InitializeEmptyExtensionService(); |
1160 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1230 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1161 service()->set_extensions_enabled(true); | 1231 service()->set_extensions_enabled(true); |
1162 | 1232 |
1163 Version version("1.0.0.0"); | 1233 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1164 | 1234 |
1165 const std::string wrong_id = all_zero; | 1235 const std::string wrong_id = all_zero; |
1166 const std::string correct_id = good_crx; | 1236 const std::string correct_id = good_crx; |
1167 ASSERT_NE(correct_id, wrong_id); | 1237 ASSERT_NE(correct_id, wrong_id); |
1168 | 1238 |
1169 // Install an external extension with an ID from the external | 1239 // Install an external extension with an ID from the external |
1170 // source that is not equal to the ID in the extension manifest. | 1240 // source that is not equal to the ID in the extension manifest. |
1171 content::WindowedNotificationObserver observer( | 1241 content::WindowedNotificationObserver observer( |
1172 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1242 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1173 content::NotificationService::AllSources()); | 1243 content::NotificationService::AllSources()); |
1174 service()->OnExternalExtensionFileFound(wrong_id, | 1244 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
1175 &version, | 1245 wrong_id, std::move(version), path, Manifest::EXTERNAL_PREF, |
1176 path, | 1246 Extension::NO_FLAGS, false, false)); |
1177 Manifest::EXTERNAL_PREF, | 1247 service()->OnExternalExtensionFileFound(*info); |
1178 Extension::NO_FLAGS, | |
1179 false, | |
1180 false); | |
1181 | 1248 |
1182 observer.Wait(); | 1249 observer.Wait(); |
1183 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); | 1250 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
1184 | 1251 |
1185 // Try again with the right ID. Expect success. | 1252 // Try again with the right ID. Expect success. |
1186 content::WindowedNotificationObserver observer2( | 1253 content::WindowedNotificationObserver observer2( |
1187 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1254 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1188 content::NotificationService::AllSources()); | 1255 content::NotificationService::AllSources()); |
1189 if (service()->OnExternalExtensionFileFound(correct_id, | 1256 info->extension_id = correct_id; |
1190 &version, | 1257 if (service()->OnExternalExtensionFileFound(*info)) |
1191 path, | |
1192 Manifest::EXTERNAL_PREF, | |
1193 Extension::NO_FLAGS, | |
1194 false, | |
1195 false)) { | |
1196 observer2.Wait(); | 1258 observer2.Wait(); |
1197 } | |
1198 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1259 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1199 } | 1260 } |
1200 | 1261 |
1201 // Test that external extensions with incorrect versions are not installed. | 1262 // Test that external extensions with incorrect versions are not installed. |
1202 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1263 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
1203 InitializeEmptyExtensionService(); | 1264 InitializeEmptyExtensionService(); |
1204 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1265 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1205 service()->set_extensions_enabled(true); | 1266 service()->set_extensions_enabled(true); |
1206 | 1267 |
1207 // Install an external extension with a version from the external | 1268 // Install an external extension with a version from the external |
1208 // source that is not equal to the version in the extension manifest. | 1269 // source that is not equal to the version in the extension manifest. |
1209 Version wrong_version("1.2.3.4"); | |
1210 content::WindowedNotificationObserver observer( | 1270 content::WindowedNotificationObserver observer( |
1211 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1271 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1212 content::NotificationService::AllSources()); | 1272 content::NotificationService::AllSources()); |
1213 service()->OnExternalExtensionFileFound(good_crx, | 1273 scoped_ptr<Version> wrong_version(new Version("1.2.3.4")); |
1214 &wrong_version, | 1274 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
1215 path, | 1275 good_crx, std::move(wrong_version), path, Manifest::EXTERNAL_PREF, |
1216 Manifest::EXTERNAL_PREF, | 1276 Extension::NO_FLAGS, false, false)); |
1217 Extension::NO_FLAGS, | 1277 service()->OnExternalExtensionFileFound(*info); |
1218 false, | |
1219 false); | |
1220 | 1278 |
1221 observer.Wait(); | 1279 observer.Wait(); |
1222 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); | 1280 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
1223 | 1281 |
1224 // Try again with the right version. Expect success. | 1282 // Try again with the right version. Expect success. |
1225 service()->pending_extension_manager()->Remove(good_crx); | 1283 service()->pending_extension_manager()->Remove(good_crx); |
1226 Version correct_version("1.0.0.0"); | 1284 scoped_ptr<Version> correct_version(new Version("1.0.0.0")); |
| 1285 info->version = std::move(correct_version); |
1227 content::WindowedNotificationObserver observer2( | 1286 content::WindowedNotificationObserver observer2( |
1228 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1287 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1229 content::NotificationService::AllSources()); | 1288 content::NotificationService::AllSources()); |
1230 if (service()->OnExternalExtensionFileFound(good_crx, | 1289 if (service()->OnExternalExtensionFileFound(*info)) |
1231 &correct_version, | |
1232 path, | |
1233 Manifest::EXTERNAL_PREF, | |
1234 Extension::NO_FLAGS, | |
1235 false, | |
1236 false)) { | |
1237 observer2.Wait(); | 1290 observer2.Wait(); |
1238 } | |
1239 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1291 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1240 } | 1292 } |
1241 | 1293 |
1242 // Install a user script (they get converted automatically to an extension) | 1294 // Install a user script (they get converted automatically to an extension) |
1243 TEST_F(ExtensionServiceTest, InstallUserScript) { | 1295 TEST_F(ExtensionServiceTest, InstallUserScript) { |
1244 // The details of script conversion are tested elsewhere, this just tests | 1296 // The details of script conversion are tested elsewhere, this just tests |
1245 // integration with ExtensionService. | 1297 // integration with ExtensionService. |
1246 InitializeEmptyExtensionService(); | 1298 InitializeEmptyExtensionService(); |
1247 | 1299 |
1248 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); | 1300 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); |
(...skipping 3795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5044 " \"do_not_install_for_enterprise\": true" | 5096 " \"do_not_install_for_enterprise\": true" |
5045 " }," | 5097 " }," |
5046 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" | 5098 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
5047 " \"external_crx\": \"RandomExtension2.crx\"," | 5099 " \"external_crx\": \"RandomExtension2.crx\"," |
5048 " \"external_version\": \"1.0\"" | 5100 " \"external_version\": \"1.0\"" |
5049 " }" | 5101 " }" |
5050 "}"; | 5102 "}"; |
5051 EXPECT_EQ(1, visitor.Visit(json_data)); | 5103 EXPECT_EQ(1, visitor.Visit(json_data)); |
5052 } | 5104 } |
5053 | 5105 |
| 5106 TEST_F(ExtensionServiceTest, IncrementalUpdateThroughRegistry) { |
| 5107 InitializeEmptyExtensionService(); |
| 5108 |
| 5109 // Test some valid extension records. |
| 5110 // Set a base path to avoid erroring out on relative paths. |
| 5111 // Paths starting with // are absolute on every platform we support. |
| 5112 base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
| 5113 ASSERT_TRUE(base_path.IsAbsolute()); |
| 5114 MockUpdateProviderVisitor visitor(base_path); |
| 5115 std::string json_data = |
| 5116 "{" |
| 5117 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5118 " \"external_crx\": \"RandomExtension.crx\"," |
| 5119 " \"external_version\": \"1.0\"" |
| 5120 " }," |
| 5121 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5122 " \"external_crx\": \"RandomExtension2.crx\"," |
| 5123 " \"external_version\": \"2.0\"" |
| 5124 " }," |
| 5125 " \"cccccccccccccccccccccccccccccccc\": {" |
| 5126 " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 5127 " \"install_parameter\": \"id\"" |
| 5128 " }" |
| 5129 "}"; |
| 5130 EXPECT_EQ(3, visitor.Visit(json_data, Manifest::EXTERNAL_REGISTRY, |
| 5131 Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 5132 |
| 5133 // c* removed and d*, e*, f* added, a*, b* existing. |
| 5134 json_data = |
| 5135 "{" |
| 5136 " \"dddddddddddddddddddddddddddddddd\": {" |
| 5137 " \"external_crx\": \"RandomExtension3.crx\"," |
| 5138 " \"external_version\": \"1.0\"" |
| 5139 " }," |
| 5140 " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 5141 " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 5142 " \"install_parameter\": \"id\"" |
| 5143 " }," |
| 5144 " \"ffffffffffffffffffffffffffffffff\": {" |
| 5145 " \"external_update_url\": \"http:\\\\bar.com/update\"," |
| 5146 " \"install_parameter\": \"id\"" |
| 5147 " }," |
| 5148 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5149 " \"external_crx\": \"RandomExtension.crx\"," |
| 5150 " \"external_version\": \"1.0\"" |
| 5151 " }," |
| 5152 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5153 " \"external_crx\": \"RandomExtension2.crx\"," |
| 5154 " \"external_version\": \"2.0\"" |
| 5155 " }" |
| 5156 "}"; |
| 5157 |
| 5158 // This will simulate registry loader observing new changes in registry and |
| 5159 // hence will discover new extensions. |
| 5160 visitor.VisitDueToUpdate(json_data); |
| 5161 |
| 5162 // UpdateUrl. |
| 5163 EXPECT_EQ(2u, visitor.GetUpdateURLExtensionCount()); |
| 5164 EXPECT_TRUE( |
| 5165 visitor.HasSeenUpdateWithUpdateUrl("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")); |
| 5166 EXPECT_TRUE( |
| 5167 visitor.HasSeenUpdateWithUpdateUrl("ffffffffffffffffffffffffffffffff")); |
| 5168 |
| 5169 // File. |
| 5170 EXPECT_EQ(3u, visitor.GetFileExtensionCount()); |
| 5171 EXPECT_TRUE( |
| 5172 visitor.HasSeenUpdateWithFile("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 5173 EXPECT_TRUE( |
| 5174 visitor.HasSeenUpdateWithFile("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 5175 EXPECT_TRUE( |
| 5176 visitor.HasSeenUpdateWithFile("dddddddddddddddddddddddddddddddd")); |
| 5177 |
| 5178 // Removed extensions. |
| 5179 EXPECT_EQ(1u, visitor.GetRemovedExtensionCount()); |
| 5180 EXPECT_TRUE(visitor.HasSeenRemoval("cccccccccccccccccccccccccccccccc")); |
| 5181 |
| 5182 // Simulate all 5 extensions being removed. |
| 5183 json_data = "{}"; |
| 5184 visitor.VisitDueToUpdate(json_data); |
| 5185 EXPECT_EQ(0u, visitor.GetUpdateURLExtensionCount()); |
| 5186 EXPECT_EQ(0u, visitor.GetFileExtensionCount()); |
| 5187 EXPECT_EQ(5u, visitor.GetRemovedExtensionCount()); |
| 5188 } |
| 5189 |
5054 // Test loading good extensions from the profile directory. | 5190 // Test loading good extensions from the profile directory. |
5055 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { | 5191 TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
5056 // Ensure we're testing in "en" and leave global state untouched. | 5192 // Ensure we're testing in "en" and leave global state untouched. |
5057 extension_l10n_util::ScopedLocaleForTest testLocale("en"); | 5193 extension_l10n_util::ScopedLocaleForTest testLocale("en"); |
5058 | 5194 |
5059 // Initialize the test dir with a good Preferences/extensions. | 5195 // Initialize the test dir with a good Preferences/extensions. |
5060 base::FilePath source_install_dir = data_dir().AppendASCII("l10n"); | 5196 base::FilePath source_install_dir = data_dir().AppendASCII("l10n"); |
5061 base::FilePath pref_path = | 5197 base::FilePath pref_path = |
5062 source_install_dir.Append(chrome::kPreferencesFilename); | 5198 source_install_dir.Append(chrome::kPreferencesFilename); |
5063 InitializeInstalledExtensionService(pref_path, source_install_dir); | 5199 InitializeInstalledExtensionService(pref_path, source_install_dir); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5288 InstallCRX(path, INSTALL_NEW); | 5424 InstallCRX(path, INSTALL_NEW); |
5289 ValidatePrefKeyCount(1u); | 5425 ValidatePrefKeyCount(1u); |
5290 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5426 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
5291 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); | 5427 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
5292 | 5428 |
5293 extensions::PendingExtensionManager* pending = | 5429 extensions::PendingExtensionManager* pending = |
5294 service()->pending_extension_manager(); | 5430 service()->pending_extension_manager(); |
5295 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5431 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5296 | 5432 |
5297 // Skip install when the location is the same. | 5433 // Skip install when the location is the same. |
5298 EXPECT_FALSE( | 5434 scoped_ptr<GURL> good_update_url(new GURL(kGoodUpdateURL)); |
5299 service()->OnExternalExtensionUpdateUrlFound(kGoodId, | 5435 scoped_ptr<ExternalInstallInfoUpdateUrl> info( |
5300 std::string(), | 5436 new ExternalInstallInfoUpdateUrl( |
5301 GURL(kGoodUpdateURL), | 5437 kGoodId, std::string(), std::move(good_update_url), |
5302 Manifest::INTERNAL, | 5438 Manifest::INTERNAL, Extension::NO_FLAGS, false)); |
5303 Extension::NO_FLAGS, | 5439 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); |
5304 false)); | |
5305 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5440 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5306 | 5441 |
5307 // Install when the location has higher priority. | 5442 // Install when the location has higher priority. |
5308 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( | 5443 info->download_location = Manifest::EXTERNAL_POLICY_DOWNLOAD; |
5309 kGoodId, | 5444 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); |
5310 std::string(), | |
5311 GURL(kGoodUpdateURL), | |
5312 Manifest::EXTERNAL_POLICY_DOWNLOAD, | |
5313 Extension::NO_FLAGS, | |
5314 false)); | |
5315 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5445 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5316 | 5446 |
5317 // Try the low priority again. Should be rejected. | 5447 // Try the low priority again. Should be rejected. |
5318 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound( | 5448 info->download_location = Manifest::EXTERNAL_PREF_DOWNLOAD; |
5319 kGoodId, | 5449 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); |
5320 std::string(), | |
5321 GURL(kGoodUpdateURL), | |
5322 Manifest::EXTERNAL_PREF_DOWNLOAD, | |
5323 Extension::NO_FLAGS, | |
5324 false)); | |
5325 // The existing record should still be present in the pending extension | 5450 // The existing record should still be present in the pending extension |
5326 // manager. | 5451 // manager. |
5327 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5452 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5328 | 5453 |
5329 pending->Remove(kGoodId); | 5454 pending->Remove(kGoodId); |
5330 | 5455 |
5331 // Skip install when the location has the same priority as the installed | 5456 // Skip install when the location has the same priority as the installed |
5332 // location. | 5457 // location. |
5333 EXPECT_FALSE( | 5458 info->download_location = Manifest::INTERNAL; |
5334 service()->OnExternalExtensionUpdateUrlFound(kGoodId, | 5459 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); |
5335 std::string(), | |
5336 GURL(kGoodUpdateURL), | |
5337 Manifest::INTERNAL, | |
5338 Extension::NO_FLAGS, | |
5339 false)); | |
5340 | 5460 |
5341 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5461 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5342 } | 5462 } |
5343 | 5463 |
5344 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { | 5464 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
5345 Version older_version("0.1.0.0"); | 5465 Version older_version("0.1.0.0"); |
5346 Version newer_version("2.0.0.0"); | 5466 Version newer_version("2.0.0.0"); |
5347 | 5467 |
5348 // We don't want the extension to be installed. A path that doesn't | 5468 // We don't want the extension to be installed. A path that doesn't |
5349 // point to a valid CRX ensures this. | 5469 // point to a valid CRX ensures this. |
(...skipping 17 matching lines...) Expand all Loading... |
5367 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, | 5487 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
5368 Manifest::INTERNAL)); | 5488 Manifest::INTERNAL)); |
5369 ASSERT_EQ(Manifest::EXTERNAL_PREF, | 5489 ASSERT_EQ(Manifest::EXTERNAL_PREF, |
5370 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, | 5490 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
5371 Manifest::INTERNAL)); | 5491 Manifest::INTERNAL)); |
5372 | 5492 |
5373 extensions::PendingExtensionManager* pending = | 5493 extensions::PendingExtensionManager* pending = |
5374 service()->pending_extension_manager(); | 5494 service()->pending_extension_manager(); |
5375 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5495 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5376 | 5496 |
| 5497 scoped_ptr<Version> older_version_ptr(new Version(older_version)); |
| 5498 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
| 5499 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx, |
| 5500 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged, |
| 5501 kDontInstallImmediately)); |
5377 { | 5502 { |
5378 // Simulate an external source adding the extension as INTERNAL. | 5503 // Simulate an external source adding the extension as INTERNAL. |
5379 content::WindowedNotificationObserver observer( | 5504 content::WindowedNotificationObserver observer( |
5380 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5505 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5381 content::NotificationService::AllSources()); | 5506 content::NotificationService::AllSources()); |
5382 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5507 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5383 kGoodId, | |
5384 &older_version, | |
5385 kInvalidPathToCrx, | |
5386 Manifest::INTERNAL, | |
5387 kCreationFlags, | |
5388 kDontMarkAcknowledged, | |
5389 kDontInstallImmediately)); | |
5390 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5508 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5391 observer.Wait(); | 5509 observer.Wait(); |
5392 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5510 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5393 } | 5511 } |
5394 | 5512 |
5395 { | 5513 { |
5396 // Simulate an external source adding the extension as EXTERNAL_PREF. | 5514 // Simulate an external source adding the extension as EXTERNAL_PREF. |
5397 content::WindowedNotificationObserver observer( | 5515 content::WindowedNotificationObserver observer( |
5398 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5516 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5399 content::NotificationService::AllSources()); | 5517 content::NotificationService::AllSources()); |
5400 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5518 info->crx_location = Manifest::EXTERNAL_PREF; |
5401 kGoodId, | 5519 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5402 &older_version, | |
5403 kInvalidPathToCrx, | |
5404 Manifest::EXTERNAL_PREF, | |
5405 kCreationFlags, | |
5406 kDontMarkAcknowledged, | |
5407 kDontInstallImmediately)); | |
5408 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5520 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5409 observer.Wait(); | 5521 observer.Wait(); |
5410 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5522 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5411 } | 5523 } |
5412 | 5524 |
5413 // Simulate an external source adding as EXTERNAL_PREF again. | 5525 // Simulate an external source adding as EXTERNAL_PREF again. |
5414 // This is rejected because the version and the location are the same as | 5526 // This is rejected because the version and the location are the same as |
5415 // the previous installation, which is still pending. | 5527 // the previous installation, which is still pending. |
5416 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5528 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5417 kGoodId, | |
5418 &older_version, | |
5419 kInvalidPathToCrx, | |
5420 Manifest::EXTERNAL_PREF, | |
5421 kCreationFlags, | |
5422 kDontMarkAcknowledged, | |
5423 kDontInstallImmediately)); | |
5424 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5529 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5425 | 5530 |
5426 // Try INTERNAL again. Should fail. | 5531 // Try INTERNAL again. Should fail. |
5427 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5532 info->crx_location = Manifest::INTERNAL; |
5428 kGoodId, | 5533 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5429 &older_version, | |
5430 kInvalidPathToCrx, | |
5431 Manifest::INTERNAL, | |
5432 kCreationFlags, | |
5433 kDontMarkAcknowledged, | |
5434 kDontInstallImmediately)); | |
5435 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5534 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5436 | 5535 |
5437 { | 5536 { |
5438 // Now the registry adds the extension. | 5537 // Now the registry adds the extension. |
5439 content::WindowedNotificationObserver observer( | 5538 content::WindowedNotificationObserver observer( |
5440 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5539 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5441 content::NotificationService::AllSources()); | 5540 content::NotificationService::AllSources()); |
5442 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5541 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5443 kGoodId, | 5542 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5444 &older_version, | |
5445 kInvalidPathToCrx, | |
5446 Manifest::EXTERNAL_REGISTRY, | |
5447 kCreationFlags, | |
5448 kDontMarkAcknowledged, | |
5449 kDontInstallImmediately)); | |
5450 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5543 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5451 observer.Wait(); | 5544 observer.Wait(); |
5452 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5545 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5453 } | 5546 } |
5454 | 5547 |
5455 // Registry outranks both external pref and internal, so both fail. | 5548 // Registry outranks both external pref and internal, so both fail. |
5456 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5549 info->crx_location = Manifest::EXTERNAL_PREF; |
5457 kGoodId, | 5550 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5458 &older_version, | |
5459 kInvalidPathToCrx, | |
5460 Manifest::EXTERNAL_PREF, | |
5461 kCreationFlags, | |
5462 kDontMarkAcknowledged, | |
5463 kDontInstallImmediately)); | |
5464 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5551 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5465 | 5552 |
5466 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5553 info->crx_location = Manifest::INTERNAL; |
5467 kGoodId, | 5554 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5468 &older_version, | |
5469 kInvalidPathToCrx, | |
5470 Manifest::INTERNAL, | |
5471 kCreationFlags, | |
5472 kDontMarkAcknowledged, | |
5473 kDontInstallImmediately)); | |
5474 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5555 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5475 | 5556 |
5476 pending->Remove(kGoodId); | 5557 pending->Remove(kGoodId); |
5477 | 5558 |
5478 // Install the extension. | 5559 // Install the extension. |
5479 base::FilePath path = data_dir().AppendASCII("good.crx"); | 5560 base::FilePath path = data_dir().AppendASCII("good.crx"); |
5480 const Extension* ext = InstallCRX(path, INSTALL_NEW); | 5561 const Extension* ext = InstallCRX(path, INSTALL_NEW); |
5481 ValidatePrefKeyCount(1u); | 5562 ValidatePrefKeyCount(1u); |
5482 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5563 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
5483 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); | 5564 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
5484 | 5565 |
5485 // Now test the logic of OnExternalExtensionFileFound() when the extension | 5566 // Now test the logic of OnExternalExtensionFileFound() when the extension |
5486 // being added is already installed. | 5567 // being added is already installed. |
5487 | 5568 |
5488 // Tests assume |older_version| is less than the installed version, and | 5569 // Tests assume |older_version| is less than the installed version, and |
5489 // |newer_version| is greater. Verify this: | 5570 // |newer_version| is greater. Verify this: |
5490 ASSERT_LT(older_version, *ext->version()); | 5571 ASSERT_LT(older_version, *ext->version()); |
5491 ASSERT_GT(newer_version, *ext->version()); | 5572 ASSERT_GT(newer_version, *ext->version()); |
5492 | 5573 |
5493 // An external install for the same location should fail if the version is | 5574 // An external install for the same location should fail if the version is |
5494 // older, or the same, and succeed if the version is newer. | 5575 // older, or the same, and succeed if the version is newer. |
5495 | 5576 |
5496 // Older than the installed version... | 5577 // Older than the installed version... |
5497 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5578 info->version.reset(new Version(older_version)); |
5498 kGoodId, | 5579 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5499 &older_version, | |
5500 kInvalidPathToCrx, | |
5501 Manifest::INTERNAL, | |
5502 kCreationFlags, | |
5503 kDontMarkAcknowledged, | |
5504 kDontInstallImmediately)); | |
5505 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5580 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5506 | 5581 |
5507 // Same version as the installed version... | 5582 // Same version as the installed version... |
5508 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5583 info->version.reset(new Version(ext->VersionString())); |
5509 kGoodId, | 5584 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5510 ext->version(), | |
5511 kInvalidPathToCrx, | |
5512 Manifest::INTERNAL, | |
5513 kCreationFlags, | |
5514 kDontMarkAcknowledged, | |
5515 kDontInstallImmediately)); | |
5516 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5585 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5517 | 5586 |
5518 // Newer than the installed version... | 5587 // Newer than the installed version... |
5519 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5588 info->version.reset(new Version(newer_version)); |
5520 kGoodId, | 5589 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5521 &newer_version, | |
5522 kInvalidPathToCrx, | |
5523 Manifest::INTERNAL, | |
5524 kCreationFlags, | |
5525 kDontMarkAcknowledged, | |
5526 kDontInstallImmediately)); | |
5527 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5590 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5528 | 5591 |
5529 // An external install for a higher priority install source should succeed | 5592 // An external install for a higher priority install source should succeed |
5530 // if the version is greater. |older_version| is not... | 5593 // if the version is greater. |older_version| is not... |
5531 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5594 info->version.reset(new Version(older_version)); |
5532 kGoodId, | 5595 info->crx_location = Manifest::EXTERNAL_PREF; |
5533 &older_version, | 5596 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5534 kInvalidPathToCrx, | |
5535 Manifest::EXTERNAL_PREF, | |
5536 kCreationFlags, | |
5537 kDontMarkAcknowledged, | |
5538 kDontInstallImmediately)); | |
5539 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5597 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5540 | 5598 |
5541 // |newer_version| is newer. | 5599 // |newer_version| is newer. |
5542 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5600 info->version.reset(new Version(newer_version)); |
5543 kGoodId, | 5601 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5544 &newer_version, | |
5545 kInvalidPathToCrx, | |
5546 Manifest::EXTERNAL_PREF, | |
5547 kCreationFlags, | |
5548 kDontMarkAcknowledged, | |
5549 kDontInstallImmediately)); | |
5550 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5602 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5551 | 5603 |
5552 // An external install for an even higher priority install source should | 5604 // An external install for an even higher priority install source should |
5553 // succeed if the version is greater. | 5605 // succeed if the version is greater. |
5554 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5606 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5555 kGoodId, | 5607 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5556 &newer_version, | |
5557 kInvalidPathToCrx, | |
5558 Manifest::EXTERNAL_REGISTRY, | |
5559 kCreationFlags, | |
5560 kDontMarkAcknowledged, | |
5561 kDontInstallImmediately)); | |
5562 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5608 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5563 | 5609 |
5564 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, | 5610 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
5565 // adding from external pref will now fail. | 5611 // adding from external pref will now fail. |
5566 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5612 info->crx_location = Manifest::EXTERNAL_PREF; |
5567 kGoodId, | 5613 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5568 &newer_version, | |
5569 kInvalidPathToCrx, | |
5570 Manifest::EXTERNAL_PREF, | |
5571 kCreationFlags, | |
5572 kDontMarkAcknowledged, | |
5573 kDontInstallImmediately)); | |
5574 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5614 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5575 } | 5615 } |
5576 | 5616 |
5577 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { | 5617 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
5578 Version kVersion123("1.2.3"); | 5618 Version kVersion123("1.2.3"); |
5579 Version kVersion124("1.2.4"); | 5619 Version kVersion124("1.2.4"); |
5580 Version kVersion125("1.2.5"); | 5620 Version kVersion125("1.2.5"); |
5581 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); | 5621 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); |
5582 const int kCreationFlags = 0; | 5622 const int kCreationFlags = 0; |
5583 const bool kDontMarkAcknowledged = false; | 5623 const bool kDontMarkAcknowledged = false; |
5584 const bool kDontInstallImmediately = false; | 5624 const bool kDontInstallImmediately = false; |
5585 | 5625 |
5586 InitializeEmptyExtensionService(); | 5626 InitializeEmptyExtensionService(); |
5587 | 5627 |
5588 extensions::PendingExtensionManager* pending = | 5628 extensions::PendingExtensionManager* pending = |
5589 service()->pending_extension_manager(); | 5629 service()->pending_extension_manager(); |
5590 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5630 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5591 | 5631 |
5592 // An external provider starts installing from a local crx. | 5632 // An external provider starts installing from a local crx. |
5593 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5633 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
5594 kGoodId, | 5634 kGoodId, make_scoped_ptr(new Version(kVersion123)), kInvalidPathToCrx, |
5595 &kVersion123, | 5635 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged, |
5596 kInvalidPathToCrx, | |
5597 Manifest::EXTERNAL_PREF, | |
5598 kCreationFlags, | |
5599 kDontMarkAcknowledged, | |
5600 kDontInstallImmediately)); | 5636 kDontInstallImmediately)); |
5601 const extensions::PendingExtensionInfo* info; | 5637 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5602 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5638 |
5603 EXPECT_TRUE(info->version().IsValid()); | 5639 const extensions::PendingExtensionInfo* pending_info; |
5604 EXPECT_EQ(info->version(), kVersion123); | 5640 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 5641 EXPECT_TRUE(pending_info->version().IsValid()); |
| 5642 EXPECT_EQ(pending_info->version(), kVersion123); |
5605 | 5643 |
5606 // Adding a newer version overrides the currently pending version. | 5644 // Adding a newer version overrides the currently pending version. |
5607 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5645 info->version.reset(new Version(kVersion124)); |
5608 kGoodId, | 5646 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); |
5609 &kVersion124, | 5647 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5610 kInvalidPathToCrx, | 5648 EXPECT_TRUE(pending_info->version().IsValid()); |
5611 Manifest::EXTERNAL_PREF, | 5649 EXPECT_EQ(pending_info->version(), kVersion124); |
5612 kCreationFlags, | |
5613 kDontMarkAcknowledged, | |
5614 kDontInstallImmediately)); | |
5615 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5616 EXPECT_TRUE(info->version().IsValid()); | |
5617 EXPECT_EQ(info->version(), kVersion124); | |
5618 | 5650 |
5619 // Adding an older version fails. | 5651 // Adding an older version fails. |
5620 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5652 info->version.reset(new Version(kVersion123)); |
5621 kGoodId, | 5653 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5622 &kVersion123, | 5654 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5623 kInvalidPathToCrx, | 5655 EXPECT_TRUE(pending_info->version().IsValid()); |
5624 Manifest::EXTERNAL_PREF, | 5656 EXPECT_EQ(pending_info->version(), kVersion124); |
5625 kCreationFlags, | |
5626 kDontMarkAcknowledged, | |
5627 kDontInstallImmediately)); | |
5628 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5629 EXPECT_TRUE(info->version().IsValid()); | |
5630 EXPECT_EQ(info->version(), kVersion124); | |
5631 | 5657 |
5632 // Adding an older version fails even when coming from a higher-priority | 5658 // Adding an older version fails even when coming from a higher-priority |
5633 // location. | 5659 // location. |
5634 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5660 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5635 kGoodId, | 5661 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); |
5636 &kVersion123, | 5662 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5637 kInvalidPathToCrx, | 5663 EXPECT_TRUE(pending_info->version().IsValid()); |
5638 Manifest::EXTERNAL_REGISTRY, | 5664 EXPECT_EQ(pending_info->version(), kVersion124); |
5639 kCreationFlags, | |
5640 kDontMarkAcknowledged, | |
5641 kDontInstallImmediately)); | |
5642 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5643 EXPECT_TRUE(info->version().IsValid()); | |
5644 EXPECT_EQ(info->version(), kVersion124); | |
5645 | 5665 |
5646 // Adding the latest version from the webstore overrides a specific version. | 5666 // Adding the latest version from the webstore overrides a specific version. |
5647 GURL kUpdateUrl("http://example.com/update"); | 5667 GURL kUpdateUrl("http://example.com/update"); |
5648 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( | 5668 scoped_ptr<ExternalInstallInfoUpdateUrl> update_info( |
5649 kGoodId, | 5669 new ExternalInstallInfoUpdateUrl( |
5650 std::string(), | 5670 kGoodId, std::string(), make_scoped_ptr(new GURL(kUpdateUrl)), |
5651 kUpdateUrl, | 5671 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); |
5652 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 5672 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*update_info, true)); |
5653 Extension::NO_FLAGS, | 5673 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5654 false)); | 5674 EXPECT_FALSE(pending_info->version().IsValid()); |
5655 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5656 EXPECT_FALSE(info->version().IsValid()); | |
5657 } | 5675 } |
5658 | 5676 |
5659 // This makes sure we can package and install CRX files that use whitelisted | 5677 // This makes sure we can package and install CRX files that use whitelisted |
5660 // permissions. | 5678 // permissions. |
5661 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { | 5679 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
5662 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; | 5680 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
5663 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 5681 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
5664 extensions::switches::kWhitelistedExtensionID, test_id); | 5682 extensions::switches::kWhitelistedExtensionID, test_id); |
5665 | 5683 |
5666 InitializeEmptyExtensionService(); | 5684 InitializeEmptyExtensionService(); |
(...skipping 30 matching lines...) Expand all Loading... |
5697 crx_id_, | 5715 crx_id_, |
5698 std::string(), | 5716 std::string(), |
5699 GURL(), | 5717 GURL(), |
5700 Manifest::EXTERNAL_PREF_DOWNLOAD, | 5718 Manifest::EXTERNAL_PREF_DOWNLOAD, |
5701 Extension::NO_FLAGS, | 5719 Extension::NO_FLAGS, |
5702 false); | 5720 false); |
5703 } | 5721 } |
5704 | 5722 |
5705 // Fake an external file from external_extensions.json. | 5723 // Fake an external file from external_extensions.json. |
5706 bool AddPendingExternalPrefFileInstall() { | 5724 bool AddPendingExternalPrefFileInstall() { |
5707 Version version("1.0.0.0"); | 5725 scoped_ptr<Version> version(new Version("1.0.0.0")); |
5708 | 5726 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( |
5709 return service()->OnExternalExtensionFileFound(crx_id_, | 5727 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF, |
5710 &version, | 5728 Extension::NO_FLAGS, false, false)); |
5711 crx_path_, | 5729 return service()->OnExternalExtensionFileFound(*info); |
5712 Manifest::EXTERNAL_PREF, | |
5713 Extension::NO_FLAGS, | |
5714 false, | |
5715 false); | |
5716 } | 5730 } |
5717 | 5731 |
5718 // Fake a request from sync to install an extension. | 5732 // Fake a request from sync to install an extension. |
5719 bool AddPendingSyncInstall() { | 5733 bool AddPendingSyncInstall() { |
5720 return service()->pending_extension_manager()->AddFromSync( | 5734 return service()->pending_extension_manager()->AddFromSync( |
5721 crx_id_, | 5735 crx_id_, |
5722 GURL(kGoodUpdateURL), | 5736 GURL(kGoodUpdateURL), |
5723 base::Version(), | 5737 base::Version(), |
5724 &IsExtension, | 5738 &IsExtension, |
5725 kGoodRemoteInstall, | 5739 kGoodRemoteInstall, |
5726 kGoodInstalledByCustodian); | 5740 kGoodInstalledByCustodian); |
5727 } | 5741 } |
5728 | 5742 |
5729 // Fake a policy install. | 5743 // Fake a policy install. |
5730 bool AddPendingPolicyInstall() { | 5744 bool AddPendingPolicyInstall() { |
5731 // Get path to the CRX with id |kGoodId|. | 5745 // Get path to the CRX with id |kGoodId|. |
5732 return service()->OnExternalExtensionUpdateUrlFound( | 5746 scoped_ptr<GURL> empty_url(new GURL()); |
5733 crx_id_, | 5747 scoped_ptr<ExternalInstallInfoUpdateUrl> info( |
5734 std::string(), | 5748 new ExternalInstallInfoUpdateUrl( |
5735 GURL(), | 5749 crx_id_, std::string(), std::move(empty_url), |
5736 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 5750 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); |
5737 Extension::NO_FLAGS, | 5751 return service()->OnExternalExtensionUpdateUrlFound(*info, true); |
5738 false); | |
5739 } | 5752 } |
5740 | 5753 |
5741 // Get the install source of a pending extension. | 5754 // Get the install source of a pending extension. |
5742 Manifest::Location GetPendingLocation() { | 5755 Manifest::Location GetPendingLocation() { |
5743 const extensions::PendingExtensionInfo* info; | 5756 const extensions::PendingExtensionInfo* info; |
5744 EXPECT_TRUE( | 5757 EXPECT_TRUE( |
5745 (info = service()->pending_extension_manager()->GetById(crx_id_))); | 5758 (info = service()->pending_extension_manager()->GetById(crx_id_))); |
5746 return info->install_source(); | 5759 return info->install_source(); |
5747 } | 5760 } |
5748 | 5761 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6262 | 6275 |
6263 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6276 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
6264 content::Source<Profile>(profile()), | 6277 content::Source<Profile>(profile()), |
6265 content::NotificationService::NoDetails()); | 6278 content::NotificationService::NoDetails()); |
6266 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6279 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
6267 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6280 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
6268 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6281 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
6269 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6282 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
6270 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6283 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
6271 } | 6284 } |
OLD | NEW |