| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 public: | 195 public: |
| 196 ExtensionsServiceTest() : installed_(NULL) { | 196 ExtensionsServiceTest() : installed_(NULL) { |
| 197 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, | 197 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, |
| 198 NotificationService::AllSources()); | 198 NotificationService::AllSources()); |
| 199 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 199 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 200 NotificationService::AllSources()); | 200 NotificationService::AllSources()); |
| 201 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, | 201 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, |
| 202 NotificationService::AllSources()); | 202 NotificationService::AllSources()); |
| 203 registrar_.Add(this, NotificationType::THEME_INSTALLED, | 203 registrar_.Add(this, NotificationType::THEME_INSTALLED, |
| 204 NotificationService::AllSources()); | 204 NotificationService::AllSources()); |
| 205 } |
| 205 | 206 |
| 207 virtual void InitializeExtensionsService(const FilePath& pref_file, |
| 208 const FilePath& extensions_install_dir) { |
| 209 prefs_.reset(new PrefService(pref_file, NULL)); |
| 206 profile_.reset(new TestingProfile()); | 210 profile_.reset(new TestingProfile()); |
| 207 service_ = new ExtensionsService( | 211 service_ = new ExtensionsService(profile_.get(), |
| 208 profile_.get(), CommandLine::ForCurrentProcess(), &loop_, &loop_); | 212 CommandLine::ForCurrentProcess(), |
| 213 prefs_.get(), |
| 214 extensions_install_dir, |
| 215 &loop_, |
| 216 &loop_); |
| 209 service_->SetExtensionsEnabled(true); | 217 service_->SetExtensionsEnabled(true); |
| 210 service_->set_show_extensions_prompts(false); | 218 service_->set_show_extensions_prompts(false); |
| 211 | 219 |
| 212 // When we start up, we want to make sure there is no external provider, | 220 // When we start up, we want to make sure there is no external provider, |
| 213 // since the ExtensionService on Windows will use the Registry as a default | 221 // since the ExtensionService on Windows will use the Registry as a default |
| 214 // provider and if there is something already registered there then it will | 222 // provider and if there is something already registered there then it will |
| 215 // interfere with the tests. Those tests that need an external provider | 223 // interfere with the tests. Those tests that need an external provider |
| 216 // will register one specifically. | 224 // will register one specifically. |
| 217 service_->ClearProvidersForTesting(); | 225 service_->ClearProvidersForTesting(); |
| 218 | 226 |
| 219 total_successes_ = 0; | 227 total_successes_ = 0; |
| 220 } | 228 } |
| 221 | 229 |
| 230 virtual void InitializeInstalledExtensionsService(const FilePath& prefs_file, |
| 231 const FilePath& source_install_dir) { |
| 232 FilePath path_; |
| 233 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_)); |
| 234 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 235 file_util::Delete(path_, true); |
| 236 file_util::CreateDirectory(path_); |
| 237 FilePath temp_prefs = path_.Append(FILE_PATH_LITERAL("Preferences")); |
| 238 file_util::CopyFile(prefs_file, temp_prefs); |
| 239 |
| 240 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); |
| 241 file_util::Delete(extensions_install_dir_, true); |
| 242 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
| 243 |
| 244 InitializeExtensionsService(temp_prefs, extensions_install_dir_); |
| 245 } |
| 246 |
| 247 virtual void InitializeEmptyExtensionsService() { |
| 248 FilePath path_; |
| 249 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_)); |
| 250 path_ = path_.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 251 file_util::Delete(path_, true); |
| 252 file_util::CreateDirectory(path_); |
| 253 FilePath prefs_filename = path_ |
| 254 .Append(FILE_PATH_LITERAL("TestPreferences")); |
| 255 extensions_install_dir_ = path_.Append(FILE_PATH_LITERAL("Extensions")); |
| 256 file_util::Delete(extensions_install_dir_, true); |
| 257 file_util::CreateDirectory(extensions_install_dir_); |
| 258 |
| 259 InitializeExtensionsService(prefs_filename, extensions_install_dir_); |
| 260 } |
| 261 |
| 222 static void SetUpTestCase() { | 262 static void SetUpTestCase() { |
| 223 ExtensionErrorReporter::Init(false); // no noisy errors | 263 ExtensionErrorReporter::Init(false); // no noisy errors |
| 224 } | 264 } |
| 225 | 265 |
| 226 virtual void SetUp() { | 266 virtual void SetUp() { |
| 227 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 267 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 228 } | 268 } |
| 229 | 269 |
| 230 virtual void Observe(NotificationType type, | 270 virtual void Observe(NotificationType type, |
| 231 const NotificationSource& source, | 271 const NotificationSource& source, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 EXPECT_EQ(1u, errors.size()) << path.value(); | 401 EXPECT_EQ(1u, errors.size()) << path.value(); |
| 362 } | 402 } |
| 363 if (use_callback) { | 403 if (use_callback) { |
| 364 EXPECT_EQ(NULL, callback_recorder.extension()); | 404 EXPECT_EQ(NULL, callback_recorder.extension()); |
| 365 } | 405 } |
| 366 } | 406 } |
| 367 } | 407 } |
| 368 | 408 |
| 369 void ValidatePrefKeyCount(size_t count) { | 409 void ValidatePrefKeyCount(size_t count) { |
| 370 DictionaryValue* dict = | 410 DictionaryValue* dict = |
| 371 profile_->GetPrefs()->GetMutableDictionary(L"extensions.settings"); | 411 prefs_->GetMutableDictionary(L"extensions.settings"); |
| 372 ASSERT_TRUE(dict != NULL); | 412 ASSERT_TRUE(dict != NULL); |
| 373 EXPECT_EQ(count, dict->GetSize()); | 413 EXPECT_EQ(count, dict->GetSize()); |
| 374 } | 414 } |
| 375 | 415 |
| 376 void ValidatePref(std::string extension_id, | 416 void ValidatePref(std::string extension_id, |
| 377 std::wstring pref_path, | 417 std::wstring pref_path, |
| 378 int must_equal) { | 418 int must_equal) { |
| 379 std::wstring msg = L" while checking: "; | 419 std::wstring msg = L" while checking: "; |
| 380 msg += ASCIIToWide(extension_id); | 420 msg += ASCIIToWide(extension_id); |
| 381 msg += L" "; | 421 msg += L" "; |
| 382 msg += pref_path; | 422 msg += pref_path; |
| 383 msg += L" == "; | 423 msg += L" == "; |
| 384 msg += IntToWString(must_equal); | 424 msg += IntToWString(must_equal); |
| 385 | 425 |
| 386 const DictionaryValue* dict = | 426 const DictionaryValue* dict = |
| 387 profile_->GetPrefs()->GetDictionary(L"extensions.settings"); | 427 prefs_->GetDictionary(L"extensions.settings"); |
| 388 ASSERT_TRUE(dict != NULL) << msg; | 428 ASSERT_TRUE(dict != NULL) << msg; |
| 389 DictionaryValue* pref = NULL; | 429 DictionaryValue* pref = NULL; |
| 390 ASSERT_TRUE(dict->GetDictionary(ASCIIToWide(extension_id), &pref)) << msg; | 430 ASSERT_TRUE(dict->GetDictionary(ASCIIToWide(extension_id), &pref)) << msg; |
| 391 EXPECT_TRUE(pref != NULL) << msg; | 431 EXPECT_TRUE(pref != NULL) << msg; |
| 392 int val; | 432 int val; |
| 393 pref->GetInteger(pref_path, &val); | 433 pref->GetInteger(pref_path, &val); |
| 394 EXPECT_EQ(must_equal, val) << msg; | 434 EXPECT_EQ(must_equal, val) << msg; |
| 395 } | 435 } |
| 396 | 436 |
| 397 void SetPref(std::string extension_id, std::wstring pref_path, int value) { | 437 void SetPref(std::string extension_id, std::wstring pref_path, int value) { |
| 398 std::wstring msg = L" while setting: "; | 438 std::wstring msg = L" while setting: "; |
| 399 msg += ASCIIToWide(extension_id); | 439 msg += ASCIIToWide(extension_id); |
| 400 msg += L" "; | 440 msg += L" "; |
| 401 msg += pref_path; | 441 msg += pref_path; |
| 402 msg += L" = "; | 442 msg += L" = "; |
| 403 msg += IntToWString(value); | 443 msg += IntToWString(value); |
| 404 | 444 |
| 405 const DictionaryValue* dict = | 445 const DictionaryValue* dict = |
| 406 profile_->GetPrefs()->GetMutableDictionary(L"extensions.settings"); | 446 prefs_->GetMutableDictionary(L"extensions.settings"); |
| 407 ASSERT_TRUE(dict != NULL) << msg; | 447 ASSERT_TRUE(dict != NULL) << msg; |
| 408 DictionaryValue* pref = NULL; | 448 DictionaryValue* pref = NULL; |
| 409 ASSERT_TRUE(dict->GetDictionary(ASCIIToWide(extension_id), &pref)) << msg; | 449 ASSERT_TRUE(dict->GetDictionary(ASCIIToWide(extension_id), &pref)) << msg; |
| 410 EXPECT_TRUE(pref != NULL) << msg; | 450 EXPECT_TRUE(pref != NULL) << msg; |
| 411 pref->SetInteger(pref_path, value); | 451 pref->SetInteger(pref_path, value); |
| 412 } | 452 } |
| 413 | 453 |
| 414 protected: | 454 protected: |
| 415 scoped_ptr<TestingProfile> profile_; | 455 scoped_ptr<PrefService> prefs_; |
| 456 scoped_ptr<Profile> profile_; |
| 457 FilePath extensions_install_dir_; |
| 416 scoped_refptr<ExtensionsService> service_; | 458 scoped_refptr<ExtensionsService> service_; |
| 417 size_t total_successes_; | 459 size_t total_successes_; |
| 418 MessageLoop loop_; | 460 MessageLoop loop_; |
| 419 ExtensionList loaded_; | 461 ExtensionList loaded_; |
| 420 std::string unloaded_id_; | 462 std::string unloaded_id_; |
| 421 Extension* installed_; | 463 Extension* installed_; |
| 422 | 464 |
| 423 private: | 465 private: |
| 424 NotificationRegistrar registrar_; | 466 NotificationRegistrar registrar_; |
| 425 }; | 467 }; |
| 426 | 468 |
| 427 // TODO(erikkay) this test and the next need to be replaced with equivalent | 469 FilePath::StringType NormalizeSeperators(FilePath::StringType path) { |
| 428 // versions that load from prefs. | 470 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 471 FilePath::StringType ret_val; |
| 472 for (size_t i = 0; i < path.length(); i++) { |
| 473 if (FilePath::IsSeparator(path[i])) |
| 474 path[i] = FilePath::kSeparators[0]; |
| 475 } |
| 476 #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 477 return path; |
| 478 } |
| 429 // Test loading good extensions from the profile directory. | 479 // Test loading good extensions from the profile directory. |
| 430 TEST_F(ExtensionsServiceTest, DISABLED_LoadAllExtensionsFromDirectorySuccess) { | 480 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
| 431 // Copy the test extensions into the test profile. | 481 // Initialize the test dir with a good Preferences/extensions. |
| 432 FilePath source_path; | 482 FilePath source_install_dir; |
| 433 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path)); | 483 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); |
| 434 source_path = source_path.AppendASCII("extensions"); | 484 source_install_dir = source_install_dir |
| 435 source_path = source_path.AppendASCII("good"); | 485 .AppendASCII("extensions") |
| 436 | 486 .AppendASCII("good") |
| 437 FilePath dest_path = profile_->GetPath().AppendASCII("Extensions"); | 487 .AppendASCII("Extensions"); |
| 438 file_util::CopyDirectory(source_path, dest_path, true); // Recursive. | 488 FilePath pref_path = source_install_dir |
| 489 .DirName() |
| 490 .AppendASCII("Preferences"); |
| 491 InitializeInstalledExtensionsService(pref_path, source_install_dir); |
| 439 | 492 |
| 440 service_->Init(); | 493 service_->Init(); |
| 441 loop_.RunAllPending(); | 494 loop_.RunAllPending(); |
| 442 | 495 |
| 443 std::vector<std::string> errors = GetErrors(); | 496 std::vector<std::string> errors = GetErrors(); |
| 444 for (std::vector<std::string>::iterator err = errors.begin(); | 497 for (std::vector<std::string>::iterator err = errors.begin(); |
| 445 err != errors.end(); ++err) { | 498 err != errors.end(); ++err) { |
| 446 LOG(ERROR) << *err; | 499 LOG(ERROR) << *err; |
| 447 } | 500 } |
| 448 ASSERT_EQ(3u, loaded_.size()); | 501 ASSERT_EQ(3u, loaded_.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 467 Extension* extension = loaded_[0]; | 520 Extension* extension = loaded_[0]; |
| 468 const UserScriptList& scripts = extension->content_scripts(); | 521 const UserScriptList& scripts = extension->content_scripts(); |
| 469 const std::vector<std::string>& toolstrips = extension->toolstrips(); | 522 const std::vector<std::string>& toolstrips = extension->toolstrips(); |
| 470 ASSERT_EQ(2u, scripts.size()); | 523 ASSERT_EQ(2u, scripts.size()); |
| 471 EXPECT_EQ(2u, scripts[0].url_patterns().size()); | 524 EXPECT_EQ(2u, scripts[0].url_patterns().size()); |
| 472 EXPECT_EQ("http://*.google.com/*", | 525 EXPECT_EQ("http://*.google.com/*", |
| 473 scripts[0].url_patterns()[0].GetAsString()); | 526 scripts[0].url_patterns()[0].GetAsString()); |
| 474 EXPECT_EQ("https://*.google.com/*", | 527 EXPECT_EQ("https://*.google.com/*", |
| 475 scripts[0].url_patterns()[1].GetAsString()); | 528 scripts[0].url_patterns()[1].GetAsString()); |
| 476 EXPECT_EQ(2u, scripts[0].js_scripts().size()); | 529 EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
| 477 EXPECT_EQ(extension->path().AppendASCII("script1.js").value(), | 530 EXPECT_EQ( |
| 478 scripts[0].js_scripts()[0].path().value()); | 531 NormalizeSeperators(extension->path().AppendASCII("script1.js").value()), |
| 479 EXPECT_EQ(extension->path().AppendASCII("script2.js").value(), | 532 NormalizeSeperators(scripts[0].js_scripts()[0].path().value())); |
| 480 scripts[0].js_scripts()[1].path().value()); | 533 EXPECT_EQ( |
| 534 NormalizeSeperators(extension->path().AppendASCII("script2.js").value()), |
| 535 NormalizeSeperators(scripts[0].js_scripts()[1].path().value())); |
| 481 EXPECT_TRUE(extension->plugins().empty()); | 536 EXPECT_TRUE(extension->plugins().empty()); |
| 482 EXPECT_EQ(1u, scripts[1].url_patterns().size()); | 537 EXPECT_EQ(1u, scripts[1].url_patterns().size()); |
| 483 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); | 538 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); |
| 484 EXPECT_EQ(extension->path().AppendASCII("js_files").AppendASCII("script3.js") | 539 EXPECT_EQ( |
| 485 .value(), scripts[1].js_scripts()[0].path().value()); | 540 NormalizeSeperators(extension->path() |
| 541 .AppendASCII("js_files") |
| 542 .AppendASCII("script3.js") |
| 543 .value()), |
| 544 NormalizeSeperators(scripts[1].js_scripts()[0].path().value())); |
| 486 const std::vector<URLPattern> permissions = extension->permissions(); | 545 const std::vector<URLPattern> permissions = extension->permissions(); |
| 487 ASSERT_EQ(2u, permissions.size()); | 546 ASSERT_EQ(2u, permissions.size()); |
| 488 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); | 547 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); |
| 489 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); | 548 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); |
| 490 ASSERT_EQ(2u, toolstrips.size()); | 549 ASSERT_EQ(2u, toolstrips.size()); |
| 491 EXPECT_EQ("toolstrip1.html", toolstrips[0]); | 550 EXPECT_EQ("toolstrip1.html", toolstrips[0]); |
| 492 EXPECT_EQ("toolstrip2.html", toolstrips[1]); | 551 EXPECT_EQ("toolstrip2.html", toolstrips[1]); |
| 493 | 552 |
| 494 EXPECT_EQ(std::string(good1), loaded_[1]->id()); | 553 EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
| 495 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); | 554 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
| 496 EXPECT_EQ(std::string(""), loaded_[1]->description()); | 555 EXPECT_EQ(std::string(""), loaded_[1]->description()); |
| 497 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), | 556 // TODO(erikkay): re-enable: |
| 498 loaded_[1]->background_url()); | 557 // http://code.google.com/p/chromium/issues/detail?id=15363. |
| 558 // EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
| 559 // loaded_[1]->background_url()); |
| 499 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); | 560 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); |
| 500 EXPECT_EQ(2u, loaded_[1]->plugins().size()); | 561 EXPECT_EQ(2u, loaded_[1]->plugins().size()); |
| 501 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), | 562 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
| 502 loaded_[1]->plugins()[0].path.value()); | 563 loaded_[1]->plugins()[0].path.value()); |
| 503 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); | 564 EXPECT_TRUE(loaded_[1]->plugins()[0].is_public); |
| 504 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), | 565 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
| 505 loaded_[1]->plugins()[1].path.value()); | 566 loaded_[1]->plugins()[1].path.value()); |
| 506 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); | 567 EXPECT_FALSE(loaded_[1]->plugins()[1].is_public); |
| 507 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); | 568 EXPECT_EQ(Extension::INTERNAL, loaded_[1]->location()); |
| 508 | 569 |
| 509 EXPECT_EQ(std::string(good2), loaded_[2]->id()); | 570 EXPECT_EQ(std::string(good2), loaded_[2]->id()); |
| 510 EXPECT_EQ(std::string("My extension 3"), loaded_[2]->name()); | 571 EXPECT_EQ(std::string("My extension 3"), loaded_[2]->name()); |
| 511 EXPECT_EQ(std::string(""), loaded_[2]->description()); | 572 EXPECT_EQ(std::string(""), loaded_[2]->description()); |
| 512 EXPECT_EQ(0u, loaded_[2]->content_scripts().size()); | 573 EXPECT_EQ(0u, loaded_[2]->content_scripts().size()); |
| 513 EXPECT_EQ(Extension::INTERNAL, loaded_[2]->location()); | 574 EXPECT_EQ(Extension::INTERNAL, loaded_[2]->location()); |
| 514 }; | 575 }; |
| 515 | 576 |
| 516 // Test loading bad extensions from the profile directory. | 577 // Test loading bad extensions from the profile directory. |
| 517 TEST_F(ExtensionsServiceTest, DISABLED_LoadAllExtensionsFromDirectoryFail) { | 578 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectoryFail) { |
| 518 FilePath source_path; | 579 // Initialize the test dir with a good Preferences/extensions. |
| 519 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path)); | 580 FilePath source_install_dir; |
| 520 source_path = source_path.AppendASCII("extensions"); | 581 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_install_dir)); |
| 521 source_path = source_path.AppendASCII("bad"); | 582 source_install_dir = source_install_dir |
| 583 .AppendASCII("extensions") |
| 584 .AppendASCII("bad") |
| 585 .AppendASCII("Extensions"); |
| 586 FilePath pref_path = source_install_dir |
| 587 .DirName() |
| 588 .AppendASCII("Preferences"); |
| 522 | 589 |
| 523 FilePath dest_path = profile_->GetPath().AppendASCII("Extensions"); | 590 InitializeInstalledExtensionsService(pref_path, source_install_dir); |
| 524 file_util::CopyDirectory(source_path, dest_path, true); // Recursive. | |
| 525 | 591 |
| 526 service_->Init(); | 592 service_->Init(); |
| 527 loop_.RunAllPending(); | 593 loop_.RunAllPending(); |
| 528 | 594 |
| 529 EXPECT_EQ(3u, GetErrors().size()); | 595 ASSERT_EQ(4u, GetErrors().size()); |
| 530 EXPECT_EQ(0u, loaded_.size()); | 596 ASSERT_EQ(0u, loaded_.size()); |
| 531 | |
| 532 // Make sure the dictionary is empty. | |
| 533 ValidatePrefKeyCount(0); | |
| 534 | 597 |
| 535 EXPECT_TRUE(MatchPattern(GetErrors()[0], | 598 EXPECT_TRUE(MatchPattern(GetErrors()[0], |
| 536 std::string("Could not load extension from '*'. * ") + | 599 std::string("Could not load extension from '*'. * ") + |
| 537 JSONReader::kBadRootElementType)) << GetErrors()[0]; | 600 JSONReader::kBadRootElementType)) << GetErrors()[0]; |
| 538 | 601 |
| 539 EXPECT_TRUE(MatchPattern(GetErrors()[1], | 602 EXPECT_TRUE(MatchPattern(GetErrors()[1], |
| 540 std::string("Could not load extension from '*'. ") + | 603 std::string("Could not load extension from '*'. ") + |
| 541 Extension::kInvalidManifestError)) << GetErrors()[1]; | 604 Extension::kInvalidManifestError)) << GetErrors()[1]; |
| 542 | 605 |
| 543 EXPECT_TRUE(MatchPattern(GetErrors()[2], | 606 EXPECT_TRUE(MatchPattern(GetErrors()[2], |
| 544 std::string("Could not load extension from '*'. ") + | 607 std::string("Could not load extension from '*'. ") + |
| 545 Extension::kMissingFileError)) << GetErrors()[2]; | 608 Extension::kMissingFileError)) << GetErrors()[2]; |
| 609 |
| 610 EXPECT_TRUE(MatchPattern(GetErrors()[3], |
| 611 std::string("Could not load extension from '*'. ") + |
| 612 Extension::kInvalidManifestError)) << GetErrors()[3]; |
| 546 }; | 613 }; |
| 547 | 614 |
| 548 // Test that partially deleted extensions are cleaned up during startup | 615 // Test that partially deleted extensions are cleaned up during startup |
| 549 // Test loading bad extensions from the profile directory. | 616 // Test loading bad extensions from the profile directory. |
| 550 TEST_F(ExtensionsServiceTest, CleanupOnStartup) { | 617 TEST_F(ExtensionsServiceTest, CleanupOnStartup) { |
| 618 InitializeEmptyExtensionsService(); |
| 619 |
| 551 FilePath source_path; | 620 FilePath source_path; |
| 552 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path)); | 621 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path)); |
| 553 source_path = source_path.AppendASCII("extensions"); | 622 source_path = source_path.AppendASCII("extensions") |
| 554 source_path = source_path.AppendASCII("good"); | 623 .AppendASCII("good") |
| 624 .AppendASCII("Extensions"); |
| 555 | 625 |
| 556 FilePath dest_path = profile_->GetPath().AppendASCII("Extensions"); | 626 file_util::Delete(extensions_install_dir_, true); |
| 557 file_util::CopyDirectory(source_path, dest_path, true); // Recursive. | 627 |
| 628 // Recursive. |
| 629 file_util::CopyDirectory(source_path, extensions_install_dir_, true); |
| 558 | 630 |
| 559 // Simulate that one of them got partially deleted by deling the | 631 // Simulate that one of them got partially deleted by deling the |
| 560 // Current Version file. | 632 // Current Version file. |
| 561 FilePath vers = dest_path.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 633 FilePath vers = extensions_install_dir_ |
| 634 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 562 .AppendASCII(ExtensionsService::kCurrentVersionFileName); | 635 .AppendASCII(ExtensionsService::kCurrentVersionFileName); |
| 563 ASSERT_TRUE(file_util::Delete(vers, false)); // not recursive | 636 ASSERT_TRUE(file_util::Delete(vers, false)); // not recursive |
| 564 | 637 |
| 565 service_->Init(); | 638 service_->Init(); |
| 566 loop_.RunAllPending(); | 639 loop_.RunAllPending(); |
| 567 | 640 |
| 568 file_util::FileEnumerator dirs(dest_path, false, | 641 file_util::FileEnumerator dirs(extensions_install_dir_, false, |
| 569 file_util::FileEnumerator::DIRECTORIES); | 642 file_util::FileEnumerator::DIRECTORIES); |
| 570 size_t count = 0; | 643 size_t count = 0; |
| 571 while (!dirs.Next().empty()) | 644 while (!dirs.Next().empty()) |
| 572 count++; | 645 count++; |
| 573 | 646 |
| 574 // We should have only gotten two extensions now. | 647 // We should have only gotten two extensions now. |
| 575 EXPECT_EQ(2u, count); | 648 EXPECT_EQ(2u, count); |
| 576 | 649 |
| 577 // And extension1 dir should now be toast. | 650 // And extension1 dir should now be toast. |
| 578 vers = vers.DirName(); | 651 vers = vers.DirName(); |
| 579 ASSERT_FALSE(file_util::PathExists(vers)); | 652 ASSERT_FALSE(file_util::PathExists(vers)); |
| 580 } | 653 } |
| 581 | 654 |
| 582 // Test installing extensions. | 655 // Test installing extensions. |
| 583 TEST_F(ExtensionsServiceTest, InstallExtension) { | 656 TEST_F(ExtensionsServiceTest, InstallExtension) { |
| 657 InitializeEmptyExtensionsService(); |
| 658 |
| 584 FilePath extensions_path; | 659 FilePath extensions_path; |
| 585 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 660 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 586 extensions_path = extensions_path.AppendASCII("extensions"); | 661 extensions_path = extensions_path.AppendASCII("extensions"); |
| 587 | 662 |
| 588 // Extensions not enabled. | 663 // Extensions not enabled. |
| 589 SetExtensionsEnabled(false); | 664 SetExtensionsEnabled(false); |
| 590 FilePath path = extensions_path.AppendASCII("good.crx"); | 665 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 591 InstallExtension(path, false); | 666 InstallExtension(path, false); |
| 592 SetExtensionsEnabled(true); | 667 SetExtensionsEnabled(true); |
| 593 | 668 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 ValidatePrefKeyCount(pref_count); | 700 ValidatePrefKeyCount(pref_count); |
| 626 | 701 |
| 627 // TODO(erikkay): add more tests for many of the failure cases. | 702 // TODO(erikkay): add more tests for many of the failure cases. |
| 628 // TODO(erikkay): add tests for upgrade cases. | 703 // TODO(erikkay): add tests for upgrade cases. |
| 629 } | 704 } |
| 630 | 705 |
| 631 #if defined(OS_WIN) // TODO(port) | 706 #if defined(OS_WIN) // TODO(port) |
| 632 // Test Packaging and installing an extension. | 707 // Test Packaging and installing an extension. |
| 633 // TODO(rafaelw): add more tests for failure cases. | 708 // TODO(rafaelw): add more tests for failure cases. |
| 634 TEST_F(ExtensionsServiceTest, PackExtension) { | 709 TEST_F(ExtensionsServiceTest, PackExtension) { |
| 710 InitializeEmptyExtensionsService(); |
| 635 FilePath extensions_path; | 711 FilePath extensions_path; |
| 636 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 712 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 637 extensions_path = extensions_path.AppendASCII("extensions"); | 713 extensions_path = extensions_path.AppendASCII("extensions"); |
| 638 FilePath input_directory = extensions_path.AppendASCII("good") | 714 FilePath input_directory = extensions_path |
| 639 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0"); | 715 .AppendASCII("good") |
| 716 .AppendASCII("Extensions") |
| 717 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 718 .AppendASCII("1.0.0.0"); |
| 640 | 719 |
| 641 FilePath output_directory; | 720 FilePath output_directory; |
| 642 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), | 721 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), |
| 643 &output_directory); | 722 &output_directory); |
| 644 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 723 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 645 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 724 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 646 | 725 |
| 647 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 726 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 648 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), | 727 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), |
| 649 privkey_path)); | 728 privkey_path)); |
| 650 | 729 |
| 651 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 730 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 652 InstallExtension(crx_path, true); | 731 InstallExtension(crx_path, true); |
| 653 | 732 |
| 654 file_util::Delete(crx_path, false); | 733 file_util::Delete(crx_path, false); |
| 655 file_util::Delete(privkey_path, false); | 734 file_util::Delete(privkey_path, false); |
| 656 } | 735 } |
| 657 | 736 |
| 658 // Test Packaging and installing an extension using an openssl generated key. | 737 // Test Packaging and installing an extension using an openssl generated key. |
| 659 // The openssl is generated with the following: | 738 // The openssl is generated with the following: |
| 660 // > openssl genrsa -out privkey.pem 1024 | 739 // > openssl genrsa -out privkey.pem 1024 |
| 661 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem | 740 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
| 662 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a | 741 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
| 663 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. | 742 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
| 664 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { | 743 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { |
| 744 InitializeEmptyExtensionsService(); |
| 665 FilePath extensions_path; | 745 FilePath extensions_path; |
| 666 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 746 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 667 extensions_path = extensions_path.AppendASCII("extensions"); | 747 extensions_path = extensions_path.AppendASCII("extensions"); |
| 668 FilePath input_directory = extensions_path.AppendASCII("good") | 748 FilePath input_directory = extensions_path |
| 669 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj").AppendASCII("1.0.0.0"); | 749 .AppendASCII("good") |
| 750 .AppendASCII("Extensions") |
| 751 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 752 .AppendASCII("1.0.0.0"); |
| 670 FilePath privkey_path(extensions_path.AppendASCII( | 753 FilePath privkey_path(extensions_path.AppendASCII( |
| 671 "openssl_privkey_asn1.pem")); | 754 "openssl_privkey_asn1.pem")); |
| 672 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 755 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 673 | 756 |
| 674 FilePath output_directory; | 757 FilePath output_directory; |
| 675 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), | 758 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), |
| 676 &output_directory); | 759 &output_directory); |
| 677 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 760 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 678 | 761 |
| 679 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 762 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 680 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, | 763 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
| 681 FilePath())); | 764 FilePath())); |
| 682 | 765 |
| 683 InstallExtension(crx_path, true); | 766 InstallExtension(crx_path, true); |
| 684 | 767 |
| 685 file_util::Delete(crx_path, false); | 768 file_util::Delete(crx_path, false); |
| 686 } | 769 } |
| 687 #endif // defined(OS_WIN) | 770 #endif // defined(OS_WIN) |
| 688 | 771 |
| 689 TEST_F(ExtensionsServiceTest, InstallTheme) { | 772 TEST_F(ExtensionsServiceTest, InstallTheme) { |
| 773 InitializeEmptyExtensionsService(); |
| 690 FilePath extensions_path; | 774 FilePath extensions_path; |
| 691 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 775 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 692 extensions_path = extensions_path.AppendASCII("extensions"); | 776 extensions_path = extensions_path.AppendASCII("extensions"); |
| 693 | 777 |
| 694 // A theme. | 778 // A theme. |
| 695 FilePath path = extensions_path.AppendASCII("theme.crx"); | 779 FilePath path = extensions_path.AppendASCII("theme.crx"); |
| 696 InstallExtension(path, true); | 780 InstallExtension(path, true); |
| 697 int pref_count = 0; | 781 int pref_count = 0; |
| 698 ValidatePrefKeyCount(++pref_count); | 782 ValidatePrefKeyCount(++pref_count); |
| 699 ValidatePref(theme_crx, L"state", Extension::ENABLED); | 783 ValidatePref(theme_crx, L"state", Extension::ENABLED); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 716 ValidatePrefKeyCount(pref_count); | 800 ValidatePrefKeyCount(pref_count); |
| 717 | 801 |
| 718 // A theme with image resources missing (misspelt path). | 802 // A theme with image resources missing (misspelt path). |
| 719 path = extensions_path.AppendASCII("theme_missing_image.crx"); | 803 path = extensions_path.AppendASCII("theme_missing_image.crx"); |
| 720 InstallExtension(path, false); | 804 InstallExtension(path, false); |
| 721 ValidatePrefKeyCount(pref_count); | 805 ValidatePrefKeyCount(pref_count); |
| 722 } | 806 } |
| 723 | 807 |
| 724 // Test that when an extension version is reinstalled, nothing happens. | 808 // Test that when an extension version is reinstalled, nothing happens. |
| 725 TEST_F(ExtensionsServiceTest, Reinstall) { | 809 TEST_F(ExtensionsServiceTest, Reinstall) { |
| 810 InitializeEmptyExtensionsService(); |
| 726 FilePath extensions_path; | 811 FilePath extensions_path; |
| 727 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 812 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 728 extensions_path = extensions_path.AppendASCII("extensions"); | 813 extensions_path = extensions_path.AppendASCII("extensions"); |
| 729 | 814 |
| 730 // A simple extension that should install without error. | 815 // A simple extension that should install without error. |
| 731 FilePath path = extensions_path.AppendASCII("good.crx"); | 816 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 732 service_->InstallExtension(path); | 817 service_->InstallExtension(path); |
| 733 loop_.RunAllPending(); | 818 loop_.RunAllPending(); |
| 734 | 819 |
| 735 ASSERT_TRUE(installed_); | 820 ASSERT_TRUE(installed_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 750 ASSERT_FALSE(installed_); | 835 ASSERT_FALSE(installed_); |
| 751 ASSERT_EQ(0u, loaded_.size()); | 836 ASSERT_EQ(0u, loaded_.size()); |
| 752 ASSERT_EQ(0u, GetErrors().size()); | 837 ASSERT_EQ(0u, GetErrors().size()); |
| 753 ValidatePrefKeyCount(1); | 838 ValidatePrefKeyCount(1); |
| 754 ValidatePref(good_crx, L"state", Extension::ENABLED); | 839 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 755 ValidatePref(good_crx, L"location", Extension::INTERNAL); | 840 ValidatePref(good_crx, L"location", Extension::INTERNAL); |
| 756 } | 841 } |
| 757 | 842 |
| 758 // Test upgrading a signed extension. | 843 // Test upgrading a signed extension. |
| 759 TEST_F(ExtensionsServiceTest, UpgradeSignedGood) { | 844 TEST_F(ExtensionsServiceTest, UpgradeSignedGood) { |
| 845 InitializeEmptyExtensionsService(); |
| 760 FilePath extensions_path; | 846 FilePath extensions_path; |
| 761 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 847 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 762 extensions_path = extensions_path.AppendASCII("extensions"); | 848 extensions_path = extensions_path.AppendASCII("extensions"); |
| 763 | 849 |
| 764 FilePath path = extensions_path.AppendASCII("good.crx"); | 850 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 765 service_->InstallExtension(path); | 851 service_->InstallExtension(path); |
| 766 loop_.RunAllPending(); | 852 loop_.RunAllPending(); |
| 767 | 853 |
| 768 ASSERT_TRUE(installed_); | 854 ASSERT_TRUE(installed_); |
| 769 ASSERT_EQ(1u, loaded_.size()); | 855 ASSERT_EQ(1u, loaded_.size()); |
| 770 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); | 856 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 771 ASSERT_EQ(0u, GetErrors().size()); | 857 ASSERT_EQ(0u, GetErrors().size()); |
| 772 | 858 |
| 773 // Upgrade to version 2.0 | 859 // Upgrade to version 2.0 |
| 774 path = extensions_path.AppendASCII("good2.crx"); | 860 path = extensions_path.AppendASCII("good2.crx"); |
| 775 service_->InstallExtension(path); | 861 service_->InstallExtension(path); |
| 776 loop_.RunAllPending(); | 862 loop_.RunAllPending(); |
| 777 | 863 |
| 778 ASSERT_TRUE(installed_); | 864 ASSERT_TRUE(installed_); |
| 779 ASSERT_EQ(1u, loaded_.size()); | 865 ASSERT_EQ(1u, loaded_.size()); |
| 780 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 866 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
| 781 ASSERT_EQ(0u, GetErrors().size()); | 867 ASSERT_EQ(0u, GetErrors().size()); |
| 782 } | 868 } |
| 783 | 869 |
| 784 // Test upgrading a signed extension with a bad signature. | 870 // Test upgrading a signed extension with a bad signature. |
| 785 TEST_F(ExtensionsServiceTest, UpgradeSignedBad) { | 871 TEST_F(ExtensionsServiceTest, UpgradeSignedBad) { |
| 872 InitializeEmptyExtensionsService(); |
| 786 FilePath extensions_path; | 873 FilePath extensions_path; |
| 787 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 874 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 788 extensions_path = extensions_path.AppendASCII("extensions"); | 875 extensions_path = extensions_path.AppendASCII("extensions"); |
| 789 | 876 |
| 790 FilePath path = extensions_path.AppendASCII("good.crx"); | 877 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 791 service_->InstallExtension(path); | 878 service_->InstallExtension(path); |
| 792 loop_.RunAllPending(); | 879 loop_.RunAllPending(); |
| 793 | 880 |
| 794 ASSERT_TRUE(installed_); | 881 ASSERT_TRUE(installed_); |
| 795 ASSERT_EQ(1u, loaded_.size()); | 882 ASSERT_EQ(1u, loaded_.size()); |
| 796 ASSERT_EQ(0u, GetErrors().size()); | 883 ASSERT_EQ(0u, GetErrors().size()); |
| 797 installed_ = NULL; | 884 installed_ = NULL; |
| 798 | 885 |
| 799 // Try upgrading with a bad signature. This should fail during the unpack, | 886 // Try upgrading with a bad signature. This should fail during the unpack, |
| 800 // because the key will not match the signature. | 887 // because the key will not match the signature. |
| 801 path = extensions_path.AppendASCII("good2_bad_signature.crx"); | 888 path = extensions_path.AppendASCII("good2_bad_signature.crx"); |
| 802 service_->InstallExtension(path); | 889 service_->InstallExtension(path); |
| 803 loop_.RunAllPending(); | 890 loop_.RunAllPending(); |
| 804 | 891 |
| 805 ASSERT_FALSE(installed_); | 892 ASSERT_FALSE(installed_); |
| 806 ASSERT_EQ(1u, loaded_.size()); | 893 ASSERT_EQ(1u, loaded_.size()); |
| 807 ASSERT_EQ(1u, GetErrors().size()); | 894 ASSERT_EQ(1u, GetErrors().size()); |
| 808 } | 895 } |
| 809 | 896 |
| 810 // Test a normal update via the UpdateExtension API | 897 // Test a normal update via the UpdateExtension API |
| 811 TEST_F(ExtensionsServiceTest, UpdateExtension) { | 898 TEST_F(ExtensionsServiceTest, UpdateExtension) { |
| 899 InitializeEmptyExtensionsService(); |
| 812 FilePath extensions_path; | 900 FilePath extensions_path; |
| 813 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 901 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 814 extensions_path = extensions_path.AppendASCII("extensions"); | 902 extensions_path = extensions_path.AppendASCII("extensions"); |
| 815 | 903 |
| 816 FilePath path = extensions_path.AppendASCII("good.crx"); | 904 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 817 | 905 |
| 818 InstallExtension(path, true); | 906 InstallExtension(path, true); |
| 819 Extension* good = service_->extensions()->at(0); | 907 Extension* good = service_->extensions()->at(0); |
| 820 ASSERT_EQ("1.0.0.0", good->VersionString()); | 908 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 821 ASSERT_EQ(good_crx, good->id()); | 909 ASSERT_EQ(good_crx, good->id()); |
| 822 | 910 |
| 823 path = extensions_path.AppendASCII("good2.crx"); | 911 path = extensions_path.AppendASCII("good2.crx"); |
| 824 UpdateExtension(good_crx, path, true, true, true); | 912 UpdateExtension(good_crx, path, true, true, true); |
| 825 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 913 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
| 826 } | 914 } |
| 827 | 915 |
| 828 // Test doing an update without passing a completion callback | 916 // Test doing an update without passing a completion callback |
| 829 TEST_F(ExtensionsServiceTest, UpdateWithoutCallback) { | 917 TEST_F(ExtensionsServiceTest, UpdateWithoutCallback) { |
| 918 InitializeEmptyExtensionsService(); |
| 830 FilePath extensions_path; | 919 FilePath extensions_path; |
| 831 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 920 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 832 extensions_path = extensions_path.AppendASCII("extensions"); | 921 extensions_path = extensions_path.AppendASCII("extensions"); |
| 833 | 922 |
| 834 FilePath path = extensions_path.AppendASCII("good.crx"); | 923 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 835 | 924 |
| 836 InstallExtension(path, true); | 925 InstallExtension(path, true); |
| 837 Extension* good = service_->extensions()->at(0); | 926 Extension* good = service_->extensions()->at(0); |
| 838 ASSERT_EQ("1.0.0.0", good->VersionString()); | 927 ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 839 ASSERT_EQ(good_crx, good->id()); | 928 ASSERT_EQ(good_crx, good->id()); |
| 840 | 929 |
| 841 path = extensions_path.AppendASCII("good2.crx"); | 930 path = extensions_path.AppendASCII("good2.crx"); |
| 842 UpdateExtension(good_crx, path, true, false, true); | 931 UpdateExtension(good_crx, path, true, false, true); |
| 843 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 932 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
| 844 } | 933 } |
| 845 | 934 |
| 846 // Test updating a not-already-installed extension - this should fail | 935 // Test updating a not-already-installed extension - this should fail |
| 847 TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) { | 936 TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) { |
| 937 InitializeEmptyExtensionsService(); |
| 848 FilePath extensions_path; | 938 FilePath extensions_path; |
| 849 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 939 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 850 extensions_path = extensions_path.AppendASCII("extensions"); | 940 extensions_path = extensions_path.AppendASCII("extensions"); |
| 851 | 941 |
| 852 FilePath path = extensions_path.AppendASCII("good.crx"); | 942 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 853 service_->UpdateExtension(good_crx, path, false, NULL); | 943 service_->UpdateExtension(good_crx, path, false, NULL); |
| 854 loop_.RunAllPending(); | 944 loop_.RunAllPending(); |
| 855 | 945 |
| 856 ASSERT_EQ(0u, service_->extensions()->size()); | 946 ASSERT_EQ(0u, service_->extensions()->size()); |
| 857 ASSERT_FALSE(installed_); | 947 ASSERT_FALSE(installed_); |
| 858 ASSERT_EQ(0u, loaded_.size()); | 948 ASSERT_EQ(0u, loaded_.size()); |
| 859 } | 949 } |
| 860 | 950 |
| 861 // Makes sure you can't downgrade an extension via UpdateExtension | 951 // Makes sure you can't downgrade an extension via UpdateExtension |
| 862 TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) { | 952 TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) { |
| 953 InitializeEmptyExtensionsService(); |
| 863 FilePath extensions_path; | 954 FilePath extensions_path; |
| 864 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 955 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 865 extensions_path = extensions_path.AppendASCII("extensions"); | 956 extensions_path = extensions_path.AppendASCII("extensions"); |
| 866 | 957 |
| 867 FilePath path = extensions_path.AppendASCII("good2.crx"); | 958 FilePath path = extensions_path.AppendASCII("good2.crx"); |
| 868 | 959 |
| 869 InstallExtension(path, true); | 960 InstallExtension(path, true); |
| 870 Extension* good = service_->extensions()->at(0); | 961 Extension* good = service_->extensions()->at(0); |
| 871 ASSERT_EQ("1.0.0.1", good->VersionString()); | 962 ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 872 ASSERT_EQ(good_crx, good->id()); | 963 ASSERT_EQ(good_crx, good->id()); |
| 873 | 964 |
| 874 // Change path from good2.crx -> good.crx | 965 // Change path from good2.crx -> good.crx |
| 875 path = extensions_path.AppendASCII("good.crx"); | 966 path = extensions_path.AppendASCII("good.crx"); |
| 876 UpdateExtension(good_crx, path, false, true, true); | 967 UpdateExtension(good_crx, path, false, true, true); |
| 877 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); | 968 ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString()); |
| 878 } | 969 } |
| 879 | 970 |
| 880 // Make sure calling update with an identical version does nothing | 971 // Make sure calling update with an identical version does nothing |
| 881 TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) { | 972 TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) { |
| 973 InitializeEmptyExtensionsService(); |
| 882 FilePath extensions_path; | 974 FilePath extensions_path; |
| 883 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 975 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 884 extensions_path = extensions_path.AppendASCII("extensions"); | 976 extensions_path = extensions_path.AppendASCII("extensions"); |
| 885 | 977 |
| 886 FilePath path = extensions_path.AppendASCII("good.crx"); | 978 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 887 | 979 |
| 888 InstallExtension(path, true); | 980 InstallExtension(path, true); |
| 889 Extension* good = service_->extensions()->at(0); | 981 Extension* good = service_->extensions()->at(0); |
| 890 ASSERT_EQ(good_crx, good->id()); | 982 ASSERT_EQ(good_crx, good->id()); |
| 891 UpdateExtension(good_crx, path, false, true, false); | 983 UpdateExtension(good_crx, path, false, true, false); |
| 892 } | 984 } |
| 893 | 985 |
| 894 // Tests uninstalling normal extensions | 986 // Tests uninstalling normal extensions |
| 895 TEST_F(ExtensionsServiceTest, UninstallExtension) { | 987 TEST_F(ExtensionsServiceTest, UninstallExtension) { |
| 988 InitializeEmptyExtensionsService(); |
| 896 FilePath extensions_path; | 989 FilePath extensions_path; |
| 897 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 990 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 898 extensions_path = extensions_path.AppendASCII("extensions"); | 991 extensions_path = extensions_path.AppendASCII("extensions"); |
| 899 | 992 |
| 900 // A simple extension that should install without error. | 993 // A simple extension that should install without error. |
| 901 FilePath path = extensions_path.AppendASCII("good.crx"); | 994 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 902 InstallExtension(path, true); | 995 InstallExtension(path, true); |
| 903 | 996 |
| 904 // The directory should be there now. | 997 // The directory should be there now. |
| 905 FilePath install_path = profile_->GetPath().AppendASCII("Extensions"); | |
| 906 const char* extension_id = good_crx; | 998 const char* extension_id = good_crx; |
| 907 FilePath extension_path = install_path.AppendASCII(extension_id); | 999 FilePath extension_path = extensions_install_dir_.AppendASCII(extension_id); |
| 908 EXPECT_TRUE(file_util::PathExists(extension_path)); | 1000 EXPECT_TRUE(file_util::PathExists(extension_path)); |
| 909 | 1001 |
| 910 ValidatePrefKeyCount(1); | 1002 ValidatePrefKeyCount(1); |
| 911 ValidatePref(good_crx, L"state", Extension::ENABLED); | 1003 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 912 ValidatePref(good_crx, L"location", Extension::INTERNAL); | 1004 ValidatePref(good_crx, L"location", Extension::INTERNAL); |
| 913 | 1005 |
| 914 // Uninstall it. | 1006 // Uninstall it. |
| 915 service_->UninstallExtension(extension_id, false); | 1007 service_->UninstallExtension(extension_id, false); |
| 916 total_successes_ = 0; | 1008 total_successes_ = 0; |
| 917 | 1009 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 937 EXPECT_TRUE(file_util::Delete(current_version_file, true)); | 1029 EXPECT_TRUE(file_util::Delete(current_version_file, true)); |
| 938 service_->UninstallExtension(extension_id, false); | 1030 service_->UninstallExtension(extension_id, false); |
| 939 loop_.RunAllPending(); | 1031 loop_.RunAllPending(); |
| 940 EXPECT_FALSE(file_util::PathExists(extension_path)); | 1032 EXPECT_FALSE(file_util::PathExists(extension_path)); |
| 941 | 1033 |
| 942 ValidatePrefKeyCount(0); | 1034 ValidatePrefKeyCount(0); |
| 943 } | 1035 } |
| 944 | 1036 |
| 945 // Tests loading single extensions (like --load-extension) | 1037 // Tests loading single extensions (like --load-extension) |
| 946 TEST_F(ExtensionsServiceTest, LoadExtension) { | 1038 TEST_F(ExtensionsServiceTest, LoadExtension) { |
| 1039 InitializeEmptyExtensionsService(); |
| 947 FilePath extensions_path; | 1040 FilePath extensions_path; |
| 948 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1041 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 949 extensions_path = extensions_path.AppendASCII("extensions"); | 1042 extensions_path = extensions_path.AppendASCII("extensions"); |
| 950 | 1043 |
| 951 FilePath ext1 = extensions_path.AppendASCII("good") | 1044 FilePath ext1 = extensions_path |
| 1045 .AppendASCII("good") |
| 1046 .AppendASCII("Extensions") |
| 952 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 1047 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 953 .AppendASCII("1.0.0.0"); | 1048 .AppendASCII("1.0.0.0"); |
| 954 service_->LoadExtension(ext1); | 1049 service_->LoadExtension(ext1); |
| 955 loop_.RunAllPending(); | 1050 loop_.RunAllPending(); |
| 956 EXPECT_EQ(0u, GetErrors().size()); | 1051 EXPECT_EQ(0u, GetErrors().size()); |
| 957 ASSERT_EQ(1u, loaded_.size()); | 1052 ASSERT_EQ(1u, loaded_.size()); |
| 958 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); | 1053 EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); |
| 959 EXPECT_EQ(1u, service_->extensions()->size()); | 1054 EXPECT_EQ(1u, service_->extensions()->size()); |
| 960 | 1055 |
| 961 // --load-extension doesn't add entries to prefs | 1056 // --load-extension doesn't add entries to prefs |
| 962 ValidatePrefKeyCount(0); | 1057 ValidatePrefKeyCount(0); |
| 963 | 1058 |
| 964 FilePath no_manifest = extensions_path.AppendASCII("bad") | 1059 FilePath no_manifest = extensions_path |
| 965 .AppendASCII("cccccccccccccccccccccccccccccccc").AppendASCII("1"); | 1060 .AppendASCII("bad") |
| 1061 //.AppendASCII("Extensions") |
| 1062 .AppendASCII("cccccccccccccccccccccccccccccccc") |
| 1063 .AppendASCII("1"); |
| 966 service_->LoadExtension(no_manifest); | 1064 service_->LoadExtension(no_manifest); |
| 967 loop_.RunAllPending(); | 1065 loop_.RunAllPending(); |
| 968 EXPECT_EQ(1u, GetErrors().size()); | 1066 EXPECT_EQ(1u, GetErrors().size()); |
| 969 ASSERT_EQ(1u, loaded_.size()); | 1067 ASSERT_EQ(1u, loaded_.size()); |
| 970 EXPECT_EQ(1u, service_->extensions()->size()); | 1068 EXPECT_EQ(1u, service_->extensions()->size()); |
| 971 | 1069 |
| 972 // Test uninstall. | 1070 // Test uninstall. |
| 973 std::string id = loaded_[0]->id(); | 1071 std::string id = loaded_[0]->id(); |
| 974 EXPECT_FALSE(unloaded_id_.length()); | 1072 EXPECT_FALSE(unloaded_id_.length()); |
| 975 service_->UninstallExtension(id, false); | 1073 service_->UninstallExtension(id, false); |
| 976 loop_.RunAllPending(); | 1074 loop_.RunAllPending(); |
| 977 EXPECT_EQ(id, unloaded_id_); | 1075 EXPECT_EQ(id, unloaded_id_); |
| 978 ASSERT_EQ(0u, loaded_.size()); | 1076 ASSERT_EQ(0u, loaded_.size()); |
| 979 EXPECT_EQ(0u, service_->extensions()->size()); | 1077 EXPECT_EQ(0u, service_->extensions()->size()); |
| 980 } | 1078 } |
| 981 | 1079 |
| 982 // Tests that we generate IDs when they are not specified in the manifest for | 1080 // Tests that we generate IDs when they are not specified in the manifest for |
| 983 // --load-extension. | 1081 // --load-extension. |
| 984 TEST_F(ExtensionsServiceTest, GenerateID) { | 1082 TEST_F(ExtensionsServiceTest, GenerateID) { |
| 1083 InitializeEmptyExtensionsService(); |
| 985 Extension::ResetGeneratedIdCounter(); | 1084 Extension::ResetGeneratedIdCounter(); |
| 986 | 1085 |
| 987 FilePath extensions_path; | 1086 FilePath extensions_path; |
| 988 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1087 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 989 extensions_path = extensions_path.AppendASCII("extensions"); | 1088 extensions_path = extensions_path.AppendASCII("extensions"); |
| 990 | 1089 |
| 991 FilePath no_id_ext = extensions_path.AppendASCII("no_id"); | 1090 FilePath no_id_ext = extensions_path.AppendASCII("no_id"); |
| 992 service_->LoadExtension(no_id_ext); | 1091 service_->LoadExtension(no_id_ext); |
| 993 loop_.RunAllPending(); | 1092 loop_.RunAllPending(); |
| 994 EXPECT_EQ(0u, GetErrors().size()); | 1093 EXPECT_EQ(0u, GetErrors().size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1012 | 1111 |
| 1013 // --load-extension doesn't add entries to prefs | 1112 // --load-extension doesn't add entries to prefs |
| 1014 ValidatePrefKeyCount(0); | 1113 ValidatePrefKeyCount(0); |
| 1015 } | 1114 } |
| 1016 | 1115 |
| 1017 // Tests the external installation feature | 1116 // Tests the external installation feature |
| 1018 #if defined(OS_WIN) | 1117 #if defined(OS_WIN) |
| 1019 | 1118 |
| 1020 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) { | 1119 TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) { |
| 1021 // This should all work, even when normal extension installation is disabled. | 1120 // This should all work, even when normal extension installation is disabled. |
| 1121 InitializeEmptyExtensionsService(); |
| 1022 SetExtensionsEnabled(false); | 1122 SetExtensionsEnabled(false); |
| 1023 | |
| 1024 // Verify that starting with no providers loads no extensions. | 1123 // Verify that starting with no providers loads no extensions. |
| 1025 service_->Init(); | 1124 service_->Init(); |
| 1026 loop_.RunAllPending(); | 1125 loop_.RunAllPending(); |
| 1027 ASSERT_EQ(0u, loaded_.size()); | 1126 ASSERT_EQ(0u, loaded_.size()); |
| 1028 | 1127 |
| 1029 // Now add providers. Extension system takes ownership of the objects. | 1128 // Now add providers. Extension system takes ownership of the objects. |
| 1030 MockExtensionProvider* reg_provider = | 1129 MockExtensionProvider* reg_provider = |
| 1031 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); | 1130 new MockExtensionProvider(Extension::EXTERNAL_REGISTRY); |
| 1032 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider); | 1131 SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider); |
| 1033 | 1132 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 ValidatePref(good_crx, L"state", Extension::ENABLED); | 1176 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 1078 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); | 1177 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); |
| 1079 | 1178 |
| 1080 // Uninstall the extension and reload. Nothing should happen because the | 1179 // Uninstall the extension and reload. Nothing should happen because the |
| 1081 // preference should prevent us from reinstalling. | 1180 // preference should prevent us from reinstalling. |
| 1082 std::string id = loaded_[0]->id(); | 1181 std::string id = loaded_[0]->id(); |
| 1083 service_->UninstallExtension(id, false); | 1182 service_->UninstallExtension(id, false); |
| 1084 loop_.RunAllPending(); | 1183 loop_.RunAllPending(); |
| 1085 | 1184 |
| 1086 // The extension should also be gone from the install directory. | 1185 // The extension should also be gone from the install directory. |
| 1087 FilePath install_path = profile_->GetPath().AppendASCII("Extensions") | 1186 FilePath install_path = extensions_install_dir_.AppendASCII(id); |
| 1088 .AppendASCII(id); | |
| 1089 ASSERT_FALSE(file_util::PathExists(install_path)); | 1187 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 1090 | 1188 |
| 1091 loaded_.clear(); | 1189 loaded_.clear(); |
| 1092 service_->CheckForUpdates(); | 1190 service_->CheckForUpdates(); |
| 1093 loop_.RunAllPending(); | 1191 loop_.RunAllPending(); |
| 1094 ASSERT_EQ(0u, loaded_.size()); | 1192 ASSERT_EQ(0u, loaded_.size()); |
| 1095 ValidatePrefKeyCount(1); | 1193 ValidatePrefKeyCount(1); |
| 1096 ValidatePref(good_crx, L"state", Extension::KILLBIT); // It is an ex-parrot. | 1194 ValidatePref(good_crx, L"state", Extension::KILLBIT); // It is an ex-parrot. |
| 1097 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); | 1195 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); |
| 1098 | 1196 |
| 1099 // Now clear the preference, reinstall, then remove the reg key. The extension | 1197 // Now clear the preference, reinstall, then remove the reg key. The extension |
| 1100 // should be uninstalled. | 1198 // should be uninstalled. |
| 1101 SetPref(good_crx, L"state", Extension::ENABLED); | 1199 SetPref(good_crx, L"state", Extension::ENABLED); |
| 1102 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 1200 prefs_->ScheduleSavePersistentPrefs(); |
| 1103 | 1201 |
| 1104 loaded_.clear(); | 1202 loaded_.clear(); |
| 1105 service_->CheckForUpdates(); | 1203 service_->CheckForUpdates(); |
| 1106 loop_.RunAllPending(); | 1204 loop_.RunAllPending(); |
| 1107 ASSERT_EQ(1u, loaded_.size()); | 1205 ASSERT_EQ(1u, loaded_.size()); |
| 1108 ValidatePrefKeyCount(1); | 1206 ValidatePrefKeyCount(1); |
| 1109 ValidatePref(good_crx, L"state", Extension::ENABLED); | 1207 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 1110 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); | 1208 ValidatePref(good_crx, L"location", Extension::EXTERNAL_REGISTRY); |
| 1111 | 1209 |
| 1112 // Now test an externally triggered uninstall (deleting the registry key). | 1210 // Now test an externally triggered uninstall (deleting the registry key). |
| 1113 reg_provider->RemoveExtension(good_crx); | 1211 reg_provider->RemoveExtension(good_crx); |
| 1114 | 1212 |
| 1115 loaded_.clear(); | 1213 loaded_.clear(); |
| 1116 service_->LoadAllExtensions(); | 1214 service_->LoadAllExtensions(); |
| 1117 loop_.RunAllPending(); | 1215 loop_.RunAllPending(); |
| 1118 ASSERT_EQ(0u, loaded_.size()); | 1216 ASSERT_EQ(0u, loaded_.size()); |
| 1119 ValidatePrefKeyCount(0); | 1217 ValidatePrefKeyCount(0); |
| 1120 | 1218 |
| 1121 // The extension should also be gone from the install directory. | 1219 // The extension should also be gone from the install directory. |
| 1122 ASSERT_FALSE(file_util::PathExists(install_path)); | 1220 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 1123 } | 1221 } |
| 1124 | 1222 |
| 1125 #endif | 1223 #endif |
| 1126 | 1224 |
| 1127 TEST_F(ExtensionsServiceTest, ExternalInstallPref) { | 1225 TEST_F(ExtensionsServiceTest, ExternalInstallPref) { |
| 1226 InitializeEmptyExtensionsService(); |
| 1128 // Verify that starting with no providers loads no extensions. | 1227 // Verify that starting with no providers loads no extensions. |
| 1129 service_->Init(); | 1228 service_->Init(); |
| 1130 loop_.RunAllPending(); | 1229 loop_.RunAllPending(); |
| 1131 ASSERT_EQ(0u, loaded_.size()); | 1230 ASSERT_EQ(0u, loaded_.size()); |
| 1132 | 1231 |
| 1133 // Now add providers. Extension system takes ownership of the objects. | 1232 // Now add providers. Extension system takes ownership of the objects. |
| 1134 MockExtensionProvider* pref_provider = | 1233 MockExtensionProvider* pref_provider = |
| 1135 new MockExtensionProvider(Extension::EXTERNAL_PREF); | 1234 new MockExtensionProvider(Extension::EXTERNAL_PREF); |
| 1136 SetMockExternalProvider(Extension::EXTERNAL_PREF, pref_provider); | 1235 SetMockExternalProvider(Extension::EXTERNAL_PREF, pref_provider); |
| 1137 | 1236 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 ValidatePref(good_crx, L"state", Extension::ENABLED); | 1280 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 1182 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); | 1281 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); |
| 1183 | 1282 |
| 1184 // Uninstall the extension and reload. Nothing should happen because the | 1283 // Uninstall the extension and reload. Nothing should happen because the |
| 1185 // preference should prevent us from reinstalling. | 1284 // preference should prevent us from reinstalling. |
| 1186 std::string id = loaded_[0]->id(); | 1285 std::string id = loaded_[0]->id(); |
| 1187 service_->UninstallExtension(id, false); | 1286 service_->UninstallExtension(id, false); |
| 1188 loop_.RunAllPending(); | 1287 loop_.RunAllPending(); |
| 1189 | 1288 |
| 1190 // The extension should also be gone from the install directory. | 1289 // The extension should also be gone from the install directory. |
| 1191 FilePath install_path = | 1290 FilePath install_path = extensions_install_dir_.AppendASCII(id); |
| 1192 profile_->GetPath().AppendASCII("Extensions").AppendASCII(id); | |
| 1193 ASSERT_FALSE(file_util::PathExists(install_path)); | 1291 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 1194 | 1292 |
| 1195 loaded_.clear(); | 1293 loaded_.clear(); |
| 1196 service_->CheckForUpdates(); | 1294 service_->CheckForUpdates(); |
| 1197 loop_.RunAllPending(); | 1295 loop_.RunAllPending(); |
| 1198 ASSERT_EQ(0u, loaded_.size()); | 1296 ASSERT_EQ(0u, loaded_.size()); |
| 1199 ValidatePrefKeyCount(1); | 1297 ValidatePrefKeyCount(1); |
| 1200 ValidatePref(good_crx, L"state", Extension::KILLBIT); | 1298 ValidatePref(good_crx, L"state", Extension::KILLBIT); |
| 1201 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); | 1299 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); |
| 1202 | 1300 |
| 1203 // Now clear the preference and reinstall. | 1301 // Now clear the preference and reinstall. |
| 1204 SetPref(good_crx, L"state", Extension::ENABLED); | 1302 SetPref(good_crx, L"state", Extension::ENABLED); |
| 1205 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 1303 prefs_->ScheduleSavePersistentPrefs(); |
| 1206 | 1304 |
| 1207 loaded_.clear(); | 1305 loaded_.clear(); |
| 1208 service_->CheckForUpdates(); | 1306 service_->CheckForUpdates(); |
| 1209 loop_.RunAllPending(); | 1307 loop_.RunAllPending(); |
| 1210 ASSERT_EQ(1u, loaded_.size()); | 1308 ASSERT_EQ(1u, loaded_.size()); |
| 1211 ValidatePrefKeyCount(1); | 1309 ValidatePrefKeyCount(1); |
| 1212 ValidatePref(good_crx, L"state", Extension::ENABLED); | 1310 ValidatePref(good_crx, L"state", Extension::ENABLED); |
| 1213 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); | 1311 ValidatePref(good_crx, L"location", Extension::EXTERNAL_PREF); |
| 1214 | 1312 |
| 1215 // Now test an externally triggered uninstall (deleting id from json file). | 1313 // Now test an externally triggered uninstall (deleting id from json file). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1231 service_->CheckForUpdates(); | 1329 service_->CheckForUpdates(); |
| 1232 loop_.RunAllPending(); | 1330 loop_.RunAllPending(); |
| 1233 | 1331 |
| 1234 ASSERT_EQ(0u, loaded_.size()); | 1332 ASSERT_EQ(0u, loaded_.size()); |
| 1235 ASSERT_EQ(1u, GetErrors().size()); | 1333 ASSERT_EQ(1u, GetErrors().size()); |
| 1236 ASSERT_TRUE(GetErrors()[0].find("Extensions are not enabled") != | 1334 ASSERT_TRUE(GetErrors()[0].find("Extensions are not enabled") != |
| 1237 std::string::npos); | 1335 std::string::npos); |
| 1238 } | 1336 } |
| 1239 | 1337 |
| 1240 TEST_F(ExtensionsServiceTest, ExternalPrefProvider) { | 1338 TEST_F(ExtensionsServiceTest, ExternalPrefProvider) { |
| 1339 InitializeEmptyExtensionsService(); |
| 1241 std::string json_data = | 1340 std::string json_data = |
| 1242 "{" | 1341 "{" |
| 1243 "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" | 1342 "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 1244 "\"external_crx\": \"RandomExtension.crx\"," | 1343 "\"external_crx\": \"RandomExtension.crx\"," |
| 1245 "\"external_version\": \"1.0\"" | 1344 "\"external_version\": \"1.0\"" |
| 1246 "}," | 1345 "}," |
| 1247 "\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" | 1346 "\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 1248 "\"external_crx\": \"RandomExtension2.crx\"," | 1347 "\"external_crx\": \"RandomExtension2.crx\"," |
| 1249 "\"external_version\": \"2.0\"" | 1348 "\"external_version\": \"2.0\"" |
| 1250 "}" | 1349 "}" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 } | 1384 } |
| 1286 | 1385 |
| 1287 // Test that we get enabled/disabled correctly for all the pref/command-line | 1386 // Test that we get enabled/disabled correctly for all the pref/command-line |
| 1288 // combinations. We don't want to derive from the ExtensionsServiceTest class | 1387 // combinations. We don't want to derive from the ExtensionsServiceTest class |
| 1289 // for this test, so we use ExtensionsServiceTestSimple. | 1388 // for this test, so we use ExtensionsServiceTestSimple. |
| 1290 TEST(ExtensionsServiceTestSimple, Enabledness) { | 1389 TEST(ExtensionsServiceTestSimple, Enabledness) { |
| 1291 TestingProfile profile; | 1390 TestingProfile profile; |
| 1292 MessageLoop loop; | 1391 MessageLoop loop; |
| 1293 scoped_ptr<CommandLine> command_line; | 1392 scoped_ptr<CommandLine> command_line; |
| 1294 scoped_refptr<ExtensionsService> service; | 1393 scoped_refptr<ExtensionsService> service; |
| 1394 FilePath install_dir = profile.GetPath() |
| 1395 .AppendASCII(ExtensionsService::kInstallDirectoryName); |
| 1295 | 1396 |
| 1296 // By default, we are disabled. | 1397 // By default, we are disabled. |
| 1297 command_line.reset(new CommandLine(L"")); | 1398 command_line.reset(new CommandLine(L"")); |
| 1298 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop); | 1399 service = new ExtensionsService(&profile, command_line.get(), |
| 1400 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1299 EXPECT_FALSE(service->extensions_enabled()); | 1401 EXPECT_FALSE(service->extensions_enabled()); |
| 1300 | 1402 |
| 1301 // If either the command line or pref is set, we are enabled. | 1403 // If either the command line or pref is set, we are enabled. |
| 1302 command_line->AppendSwitch(switches::kEnableExtensions); | 1404 command_line->AppendSwitch(switches::kEnableExtensions); |
| 1303 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop); | 1405 service = new ExtensionsService(&profile, command_line.get(), |
| 1406 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1304 EXPECT_TRUE(service->extensions_enabled()); | 1407 EXPECT_TRUE(service->extensions_enabled()); |
| 1305 | 1408 |
| 1306 profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true); | 1409 profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true); |
| 1307 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop); | 1410 service = new ExtensionsService(&profile, command_line.get(), |
| 1411 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1308 EXPECT_TRUE(service->extensions_enabled()); | 1412 EXPECT_TRUE(service->extensions_enabled()); |
| 1309 | 1413 |
| 1310 command_line.reset(new CommandLine(L"")); | 1414 command_line.reset(new CommandLine(L"")); |
| 1311 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop); | 1415 service = new ExtensionsService(&profile, command_line.get(), |
| 1416 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1312 EXPECT_TRUE(service->extensions_enabled()); | 1417 EXPECT_TRUE(service->extensions_enabled()); |
| 1313 } | 1418 } |
| OLD | NEW |