| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extensions_service_unittest.h" | 5 #include "chrome/browser/extensions/extensions_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 service_ = NULL; | 280 service_ = NULL; |
| 281 profile_.reset(NULL); | 281 profile_.reset(NULL); |
| 282 MessageLoop::current()->RunAllPending(); | 282 MessageLoop::current()->RunAllPending(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void ExtensionsServiceTestBase::InitializeExtensionsService( | 285 void ExtensionsServiceTestBase::InitializeExtensionsService( |
| 286 const FilePath& pref_file, const FilePath& extensions_install_dir) { | 286 const FilePath& pref_file, const FilePath& extensions_install_dir) { |
| 287 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); | 287 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); |
| 288 // Create a preference service that only contains user defined | 288 // Create a preference service that only contains user defined |
| 289 // preference values. | 289 // preference values. |
| 290 prefs_.reset(PrefService::CreateUserPrefService(pref_file)); | 290 PrefService* prefs = PrefService::CreateUserPrefService(pref_file); |
| 291 Profile::RegisterUserPrefs(prefs); |
| 292 browser::RegisterUserPrefs(prefs); |
| 293 profile->SetPrefService(prefs); |
| 291 | 294 |
| 292 Profile::RegisterUserPrefs(prefs_.get()); | |
| 293 browser::RegisterUserPrefs(prefs_.get()); | |
| 294 profile_.reset(profile); | 295 profile_.reset(profile); |
| 295 | 296 |
| 296 // TODO(scherkus): Remove this when we no longer need to have Talk | 297 // TODO(scherkus): Remove this when we no longer need to have Talk |
| 297 // component extension state as a preference http://crbug.com/56429 | 298 // component extension state as a preference http://crbug.com/56429 |
| 298 DictionaryValue* dict = | 299 DictionaryValue* dict = |
| 299 prefs_->GetMutableDictionary("extensions.settings"); | 300 profile->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 300 dict->Remove("ggnioahjipcehijkhpdjekioddnjoben", NULL); | 301 dict->Remove("ggnioahjipcehijkhpdjekioddnjoben", NULL); |
| 301 | 302 |
| 302 service_ = new ExtensionsService(profile_.get(), | 303 service_ = profile->CreateExtensionsService( |
| 303 CommandLine::ForCurrentProcess(), | 304 CommandLine::ForCurrentProcess(), |
| 304 prefs_.get(), | 305 extensions_install_dir); |
| 305 extensions_install_dir, | |
| 306 false); | |
| 307 service_->set_extensions_enabled(true); | 306 service_->set_extensions_enabled(true); |
| 308 service_->set_show_extensions_prompts(false); | 307 service_->set_show_extensions_prompts(false); |
| 309 profile->set_extensions_service(service_.get()); | 308 profile->set_extensions_service(service_.get()); |
| 310 | 309 |
| 311 // When we start up, we want to make sure there is no external provider, | 310 // When we start up, we want to make sure there is no external provider, |
| 312 // since the ExtensionService on Windows will use the Registry as a default | 311 // since the ExtensionService on Windows will use the Registry as a default |
| 313 // provider and if there is something already registered there then it will | 312 // provider and if there is something already registered there then it will |
| 314 // interfere with the tests. Those tests that need an external provider | 313 // interfere with the tests. Those tests that need an external provider |
| 315 // will register one specifically. | 314 // will register one specifically. |
| 316 service_->ClearProvidersForTesting(); | 315 service_->ClearProvidersForTesting(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 EXPECT_EQ(expected_enabled_extension_count, | 516 EXPECT_EQ(expected_enabled_extension_count, |
| 518 enabled_extension_count); | 517 enabled_extension_count); |
| 519 } | 518 } |
| 520 | 519 |
| 521 // Update() should delete the temporary input file. | 520 // Update() should delete the temporary input file. |
| 522 EXPECT_FALSE(file_util::PathExists(path)); | 521 EXPECT_FALSE(file_util::PathExists(path)); |
| 523 } | 522 } |
| 524 | 523 |
| 525 void ValidatePrefKeyCount(size_t count) { | 524 void ValidatePrefKeyCount(size_t count) { |
| 526 DictionaryValue* dict = | 525 DictionaryValue* dict = |
| 527 prefs_->GetMutableDictionary("extensions.settings"); | 526 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 528 ASSERT_TRUE(dict != NULL); | 527 ASSERT_TRUE(dict != NULL); |
| 529 EXPECT_EQ(count, dict->size()); | 528 EXPECT_EQ(count, dict->size()); |
| 530 } | 529 } |
| 531 | 530 |
| 532 void ValidateBooleanPref(const std::string& extension_id, | 531 void ValidateBooleanPref(const std::string& extension_id, |
| 533 const std::string& pref_path, | 532 const std::string& pref_path, |
| 534 bool expected_val) { | 533 bool expected_val) { |
| 535 std::string msg = " while checking: "; | 534 std::string msg = " while checking: "; |
| 536 msg += extension_id; | 535 msg += extension_id; |
| 537 msg += " "; | 536 msg += " "; |
| 538 msg += pref_path; | 537 msg += pref_path; |
| 539 msg += " == "; | 538 msg += " == "; |
| 540 msg += expected_val ? "true" : "false"; | 539 msg += expected_val ? "true" : "false"; |
| 541 | 540 |
| 542 const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); | 541 PrefService* prefs = profile_->GetPrefs(); |
| 542 const DictionaryValue* dict = |
| 543 prefs->GetDictionary("extensions.settings"); |
| 543 ASSERT_TRUE(dict != NULL) << msg; | 544 ASSERT_TRUE(dict != NULL) << msg; |
| 544 DictionaryValue* pref = NULL; | 545 DictionaryValue* pref = NULL; |
| 545 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 546 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 546 EXPECT_TRUE(pref != NULL) << msg; | 547 EXPECT_TRUE(pref != NULL) << msg; |
| 547 bool val; | 548 bool val; |
| 548 ASSERT_TRUE(pref->GetBoolean(pref_path, &val)) << msg; | 549 ASSERT_TRUE(pref->GetBoolean(pref_path, &val)) << msg; |
| 549 EXPECT_EQ(expected_val, val) << msg; | 550 EXPECT_EQ(expected_val, val) << msg; |
| 550 } | 551 } |
| 551 | 552 |
| 552 bool IsPrefExist(const std::string& extension_id, | 553 bool IsPrefExist(const std::string& extension_id, |
| 553 const std::string& pref_path) { | 554 const std::string& pref_path) { |
| 554 const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); | 555 const DictionaryValue* dict = |
| 556 profile_->GetPrefs()->GetDictionary("extensions.settings"); |
| 555 if (dict == NULL) return false; | 557 if (dict == NULL) return false; |
| 556 DictionaryValue* pref = NULL; | 558 DictionaryValue* pref = NULL; |
| 557 if (!dict->GetDictionary(extension_id, &pref)) { | 559 if (!dict->GetDictionary(extension_id, &pref)) { |
| 558 return false; | 560 return false; |
| 559 } | 561 } |
| 560 if (pref == NULL) { | 562 if (pref == NULL) { |
| 561 return false; | 563 return false; |
| 562 } | 564 } |
| 563 bool val; | 565 bool val; |
| 564 if (!pref->GetBoolean(pref_path, &val)) { | 566 if (!pref->GetBoolean(pref_path, &val)) { |
| 565 return false; | 567 return false; |
| 566 } | 568 } |
| 567 return true; | 569 return true; |
| 568 } | 570 } |
| 569 | 571 |
| 570 void ValidateIntegerPref(const std::string& extension_id, | 572 void ValidateIntegerPref(const std::string& extension_id, |
| 571 const std::string& pref_path, | 573 const std::string& pref_path, |
| 572 int expected_val) { | 574 int expected_val) { |
| 573 std::string msg = " while checking: "; | 575 std::string msg = " while checking: "; |
| 574 msg += extension_id; | 576 msg += extension_id; |
| 575 msg += " "; | 577 msg += " "; |
| 576 msg += pref_path; | 578 msg += pref_path; |
| 577 msg += " == "; | 579 msg += " == "; |
| 578 msg += base::IntToString(expected_val); | 580 msg += base::IntToString(expected_val); |
| 579 | 581 |
| 580 const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); | 582 PrefService* prefs = profile_->GetPrefs(); |
| 583 const DictionaryValue* dict = |
| 584 prefs->GetDictionary("extensions.settings"); |
| 581 ASSERT_TRUE(dict != NULL) << msg; | 585 ASSERT_TRUE(dict != NULL) << msg; |
| 582 DictionaryValue* pref = NULL; | 586 DictionaryValue* pref = NULL; |
| 583 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 587 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 584 EXPECT_TRUE(pref != NULL) << msg; | 588 EXPECT_TRUE(pref != NULL) << msg; |
| 585 int val; | 589 int val; |
| 586 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; | 590 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; |
| 587 EXPECT_EQ(expected_val, val) << msg; | 591 EXPECT_EQ(expected_val, val) << msg; |
| 588 } | 592 } |
| 589 | 593 |
| 590 void ValidateStringPref(const std::string& extension_id, | 594 void ValidateStringPref(const std::string& extension_id, |
| 591 const std::string& pref_path, | 595 const std::string& pref_path, |
| 592 const std::string& expected_val) { | 596 const std::string& expected_val) { |
| 593 std::string msg = " while checking: "; | 597 std::string msg = " while checking: "; |
| 594 msg += extension_id; | 598 msg += extension_id; |
| 595 msg += ".manifest."; | 599 msg += ".manifest."; |
| 596 msg += pref_path; | 600 msg += pref_path; |
| 597 msg += " == "; | 601 msg += " == "; |
| 598 msg += expected_val; | 602 msg += expected_val; |
| 599 | 603 |
| 600 const DictionaryValue* dict = prefs_->GetDictionary("extensions.settings"); | 604 const DictionaryValue* dict = |
| 605 profile_->GetPrefs()->GetDictionary("extensions.settings"); |
| 601 ASSERT_TRUE(dict != NULL) << msg; | 606 ASSERT_TRUE(dict != NULL) << msg; |
| 602 DictionaryValue* pref = NULL; | 607 DictionaryValue* pref = NULL; |
| 603 std::string manifest_path = extension_id + ".manifest"; | 608 std::string manifest_path = extension_id + ".manifest"; |
| 604 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; | 609 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
| 605 EXPECT_TRUE(pref != NULL) << msg; | 610 EXPECT_TRUE(pref != NULL) << msg; |
| 606 std::string val; | 611 std::string val; |
| 607 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; | 612 ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 608 EXPECT_EQ(expected_val, val) << msg; | 613 EXPECT_EQ(expected_val, val) << msg; |
| 609 } | 614 } |
| 610 | 615 |
| 611 void SetPrefInteg(const std::string& extension_id, | 616 void SetPrefInteg(const std::string& extension_id, |
| 612 const std::string& pref_path, | 617 const std::string& pref_path, |
| 613 int value) { | 618 int value) { |
| 614 std::string msg = " while setting: "; | 619 std::string msg = " while setting: "; |
| 615 msg += extension_id; | 620 msg += extension_id; |
| 616 msg += " "; | 621 msg += " "; |
| 617 msg += pref_path; | 622 msg += pref_path; |
| 618 msg += " = "; | 623 msg += " = "; |
| 619 msg += base::IntToString(value); | 624 msg += base::IntToString(value); |
| 620 | 625 |
| 621 const DictionaryValue* dict = | 626 const DictionaryValue* dict = |
| 622 prefs_->GetMutableDictionary("extensions.settings"); | 627 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 623 ASSERT_TRUE(dict != NULL) << msg; | 628 ASSERT_TRUE(dict != NULL) << msg; |
| 624 DictionaryValue* pref = NULL; | 629 DictionaryValue* pref = NULL; |
| 625 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 630 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 626 EXPECT_TRUE(pref != NULL) << msg; | 631 EXPECT_TRUE(pref != NULL) << msg; |
| 627 pref->SetInteger(pref_path, value); | 632 pref->SetInteger(pref_path, value); |
| 628 } | 633 } |
| 629 | 634 |
| 630 protected: | 635 protected: |
| 631 ExtensionList loaded_; | 636 ExtensionList loaded_; |
| 632 std::string unloaded_id_; | 637 std::string unloaded_id_; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 .AppendASCII("extensions") | 843 .AppendASCII("extensions") |
| 839 .AppendASCII("good") | 844 .AppendASCII("good") |
| 840 .AppendASCII("Extensions"); | 845 .AppendASCII("Extensions"); |
| 841 FilePath pref_path = source_install_dir | 846 FilePath pref_path = source_install_dir |
| 842 .DirName() | 847 .DirName() |
| 843 .AppendASCII("Preferences"); | 848 .AppendASCII("Preferences"); |
| 844 | 849 |
| 845 InitializeInstalledExtensionsService(pref_path, source_install_dir); | 850 InitializeInstalledExtensionsService(pref_path, source_install_dir); |
| 846 | 851 |
| 847 // Simulate that one of them got partially deleted by clearing its pref. | 852 // Simulate that one of them got partially deleted by clearing its pref. |
| 848 DictionaryValue* dict = prefs_->GetMutableDictionary("extensions.settings"); | 853 DictionaryValue* dict = |
| 854 profile_->GetPrefs()->GetMutableDictionary("extensions.settings"); |
| 849 ASSERT_TRUE(dict != NULL); | 855 ASSERT_TRUE(dict != NULL); |
| 850 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); | 856 dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); |
| 851 | 857 |
| 852 service_->Init(); | 858 service_->Init(); |
| 853 loop_.RunAllPending(); | 859 loop_.RunAllPending(); |
| 854 | 860 |
| 855 file_util::FileEnumerator dirs(extensions_install_dir_, false, | 861 file_util::FileEnumerator dirs(extensions_install_dir_, false, |
| 856 file_util::FileEnumerator::DIRECTORIES); | 862 file_util::FileEnumerator::DIRECTORIES); |
| 857 size_t count = 0; | 863 size_t count = 0; |
| 858 while (!dirs.Next().empty()) | 864 while (!dirs.Next().empty()) |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 | 1867 |
| 1862 EXPECT_NE(std::string(good1), loaded_[0]->id()); | 1868 EXPECT_NE(std::string(good1), loaded_[0]->id()); |
| 1863 EXPECT_NE(std::string(good1), loaded_[1]->id()); | 1869 EXPECT_NE(std::string(good1), loaded_[1]->id()); |
| 1864 } | 1870 } |
| 1865 #endif | 1871 #endif |
| 1866 | 1872 |
| 1867 // Will not install extension blacklisted by policy. | 1873 // Will not install extension blacklisted by policy. |
| 1868 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { | 1874 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { |
| 1869 InitializeEmptyExtensionsService(); | 1875 InitializeEmptyExtensionsService(); |
| 1870 | 1876 |
| 1871 ListValue* whitelist = prefs_->GetMutableList("extensions.install.allowlist"); | 1877 ListValue* whitelist = |
| 1872 ListValue* blacklist = prefs_->GetMutableList("extensions.install.denylist"); | 1878 profile_->GetPrefs()->GetMutableList("extensions.install.allowlist"); |
| 1879 ListValue* blacklist = |
| 1880 profile_->GetPrefs()->GetMutableList("extensions.install.denylist"); |
| 1873 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); | 1881 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); |
| 1874 | 1882 |
| 1875 // Blacklist everything. | 1883 // Blacklist everything. |
| 1876 blacklist->Append(Value::CreateStringValue("*")); | 1884 blacklist->Append(Value::CreateStringValue("*")); |
| 1877 | 1885 |
| 1878 // Blacklist prevents us from installing good_crx. | 1886 // Blacklist prevents us from installing good_crx. |
| 1879 FilePath extensions_path; | 1887 FilePath extensions_path; |
| 1880 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1888 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 1881 extensions_path = extensions_path.AppendASCII("extensions"); | 1889 extensions_path = extensions_path.AppendASCII("extensions"); |
| 1882 FilePath path = extensions_path.AppendASCII("good.crx"); | 1890 FilePath path = extensions_path.AppendASCII("good.crx"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1899 | 1907 |
| 1900 // Install good_crx. | 1908 // Install good_crx. |
| 1901 FilePath extensions_path; | 1909 FilePath extensions_path; |
| 1902 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 1910 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 1903 extensions_path = extensions_path.AppendASCII("extensions"); | 1911 extensions_path = extensions_path.AppendASCII("extensions"); |
| 1904 FilePath path = extensions_path.AppendASCII("good.crx"); | 1912 FilePath path = extensions_path.AppendASCII("good.crx"); |
| 1905 service_->InstallExtension(path); | 1913 service_->InstallExtension(path); |
| 1906 loop_.RunAllPending(); | 1914 loop_.RunAllPending(); |
| 1907 EXPECT_EQ(1u, service_->extensions()->size()); | 1915 EXPECT_EQ(1u, service_->extensions()->size()); |
| 1908 | 1916 |
| 1909 ListValue* blacklist = prefs_->GetMutableList("extensions.install.denylist"); | 1917 PrefService* prefs = profile_->GetPrefs(); |
| 1918 ListValue* blacklist = |
| 1919 prefs->GetMutableList("extensions.install.denylist"); |
| 1910 ASSERT_TRUE(blacklist != NULL); | 1920 ASSERT_TRUE(blacklist != NULL); |
| 1911 | 1921 |
| 1912 // Blacklist this extension. | 1922 // Blacklist this extension. |
| 1913 blacklist->Append(Value::CreateStringValue(good_crx)); | 1923 blacklist->Append(Value::CreateStringValue(good_crx)); |
| 1914 prefs_->ScheduleSavePersistentPrefs(); | 1924 prefs->ScheduleSavePersistentPrefs(); |
| 1915 | 1925 |
| 1916 // Programmatically appending to the prefs doesn't seem to notify the | 1926 // Programmatically appending to the prefs doesn't seem to notify the |
| 1917 // observers... :/ | 1927 // observers... :/ |
| 1918 prefs_->pref_notifier()->FireObservers("extensions.install.denylist"); | 1928 prefs->pref_notifier()->FireObservers("extensions.install.denylist"); |
| 1919 | 1929 |
| 1920 // Extension should not be running now. | 1930 // Extension should not be running now. |
| 1921 loop_.RunAllPending(); | 1931 loop_.RunAllPending(); |
| 1922 EXPECT_EQ(0u, service_->extensions()->size()); | 1932 EXPECT_EQ(0u, service_->extensions()->size()); |
| 1923 } | 1933 } |
| 1924 | 1934 |
| 1925 // Tests disabling extensions | 1935 // Tests disabling extensions |
| 1926 TEST_F(ExtensionsServiceTest, DisableExtension) { | 1936 TEST_F(ExtensionsServiceTest, DisableExtension) { |
| 1927 InitializeEmptyExtensionsService(); | 1937 InitializeEmptyExtensionsService(); |
| 1928 FilePath extensions_path; | 1938 FilePath extensions_path; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 loaded_.clear(); | 2236 loaded_.clear(); |
| 2227 service_->CheckForExternalUpdates(); | 2237 service_->CheckForExternalUpdates(); |
| 2228 loop_.RunAllPending(); | 2238 loop_.RunAllPending(); |
| 2229 ASSERT_EQ(0u, loaded_.size()); | 2239 ASSERT_EQ(0u, loaded_.size()); |
| 2230 ValidatePrefKeyCount(1); | 2240 ValidatePrefKeyCount(1); |
| 2231 ValidateIntegerPref(good_crx, "state", Extension::KILLBIT); | 2241 ValidateIntegerPref(good_crx, "state", Extension::KILLBIT); |
| 2232 ValidateIntegerPref(good_crx, "location", location); | 2242 ValidateIntegerPref(good_crx, "location", location); |
| 2233 | 2243 |
| 2234 // Now clear the preference and reinstall. | 2244 // Now clear the preference and reinstall. |
| 2235 SetPrefInteg(good_crx, "state", Extension::ENABLED); | 2245 SetPrefInteg(good_crx, "state", Extension::ENABLED); |
| 2236 prefs_->ScheduleSavePersistentPrefs(); | 2246 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
| 2237 | 2247 |
| 2238 loaded_.clear(); | 2248 loaded_.clear(); |
| 2239 service_->CheckForExternalUpdates(); | 2249 service_->CheckForExternalUpdates(); |
| 2240 loop_.RunAllPending(); | 2250 loop_.RunAllPending(); |
| 2241 ASSERT_EQ(1u, loaded_.size()); | 2251 ASSERT_EQ(1u, loaded_.size()); |
| 2242 ValidatePrefKeyCount(1); | 2252 ValidatePrefKeyCount(1); |
| 2243 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 2253 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 2244 ValidateIntegerPref(good_crx, "location", location); | 2254 ValidateIntegerPref(good_crx, "location", location); |
| 2245 | 2255 |
| 2246 // Now test an externally triggered uninstall (deleting the registry key or | 2256 // Now test an externally triggered uninstall (deleting the registry key or |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2454 MessageLoop loop; | 2464 MessageLoop loop; |
| 2455 ChromeThread ui_thread(ChromeThread::UI, &loop); | 2465 ChromeThread ui_thread(ChromeThread::UI, &loop); |
| 2456 ChromeThread file_thread(ChromeThread::FILE, &loop); | 2466 ChromeThread file_thread(ChromeThread::FILE, &loop); |
| 2457 scoped_ptr<CommandLine> command_line; | 2467 scoped_ptr<CommandLine> command_line; |
| 2458 scoped_refptr<ExtensionsService> service; | 2468 scoped_refptr<ExtensionsService> service; |
| 2459 FilePath install_dir = profile->GetPath() | 2469 FilePath install_dir = profile->GetPath() |
| 2460 .AppendASCII(ExtensionsService::kInstallDirectoryName); | 2470 .AppendASCII(ExtensionsService::kInstallDirectoryName); |
| 2461 | 2471 |
| 2462 // By default, we are enabled. | 2472 // By default, we are enabled. |
| 2463 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 2473 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
| 2464 service = new ExtensionsService(profile.get(), command_line.get(), | 2474 service = profile->CreateExtensionsService(command_line.get(), |
| 2465 profile->GetPrefs(), install_dir, false); | 2475 install_dir); |
| 2466 EXPECT_TRUE(service->extensions_enabled()); | 2476 EXPECT_TRUE(service->extensions_enabled()); |
| 2467 service->Init(); | 2477 service->Init(); |
| 2468 loop.RunAllPending(); | 2478 loop.RunAllPending(); |
| 2469 EXPECT_TRUE(recorder.ready()); | 2479 EXPECT_TRUE(recorder.ready()); |
| 2470 | 2480 |
| 2471 // If either the command line or pref is set, we are disabled. | 2481 // If either the command line or pref is set, we are disabled. |
| 2472 recorder.set_ready(false); | 2482 recorder.set_ready(false); |
| 2473 profile.reset(new TestingProfile()); | 2483 profile.reset(new TestingProfile()); |
| 2474 command_line->AppendSwitch(switches::kDisableExtensions); | 2484 command_line->AppendSwitch(switches::kDisableExtensions); |
| 2475 service = new ExtensionsService(profile.get(), command_line.get(), | 2485 service = profile->CreateExtensionsService(command_line.get(), |
| 2476 profile->GetPrefs(), install_dir, false); | 2486 install_dir); |
| 2477 EXPECT_FALSE(service->extensions_enabled()); | 2487 EXPECT_FALSE(service->extensions_enabled()); |
| 2478 service->Init(); | 2488 service->Init(); |
| 2479 loop.RunAllPending(); | 2489 loop.RunAllPending(); |
| 2480 EXPECT_TRUE(recorder.ready()); | 2490 EXPECT_TRUE(recorder.ready()); |
| 2481 | 2491 |
| 2482 recorder.set_ready(false); | 2492 recorder.set_ready(false); |
| 2483 profile.reset(new TestingProfile()); | 2493 profile.reset(new TestingProfile()); |
| 2484 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 2494 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
| 2485 service = new ExtensionsService(profile.get(), command_line.get(), | 2495 service = profile->CreateExtensionsService(command_line.get(), |
| 2486 profile->GetPrefs(), install_dir, false); | 2496 install_dir); |
| 2487 EXPECT_FALSE(service->extensions_enabled()); | 2497 EXPECT_FALSE(service->extensions_enabled()); |
| 2488 service->Init(); | 2498 service->Init(); |
| 2489 loop.RunAllPending(); | 2499 loop.RunAllPending(); |
| 2490 EXPECT_TRUE(recorder.ready()); | 2500 EXPECT_TRUE(recorder.ready()); |
| 2491 | 2501 |
| 2492 recorder.set_ready(false); | 2502 recorder.set_ready(false); |
| 2493 profile.reset(new TestingProfile()); | 2503 profile.reset(new TestingProfile()); |
| 2494 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 2504 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
| 2495 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 2505 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
| 2496 service = new ExtensionsService(profile.get(), command_line.get(), | 2506 service = profile->CreateExtensionsService(command_line.get(), |
| 2497 profile->GetPrefs(), install_dir, false); | 2507 install_dir); |
| 2498 EXPECT_FALSE(service->extensions_enabled()); | 2508 EXPECT_FALSE(service->extensions_enabled()); |
| 2499 service->Init(); | 2509 service->Init(); |
| 2500 loop.RunAllPending(); | 2510 loop.RunAllPending(); |
| 2501 EXPECT_TRUE(recorder.ready()); | 2511 EXPECT_TRUE(recorder.ready()); |
| 2502 } | 2512 } |
| 2503 | 2513 |
| 2504 // Test loading extensions that require limited and unlimited storage quotas. | 2514 // Test loading extensions that require limited and unlimited storage quotas. |
| 2505 TEST_F(ExtensionsServiceTest, StorageQuota) { | 2515 TEST_F(ExtensionsServiceTest, StorageQuota) { |
| 2506 InitializeEmptyExtensionsService(); | 2516 InitializeEmptyExtensionsService(); |
| 2507 | 2517 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2592 // Component extensions shouldn't get recourded in the prefs. | 2602 // Component extensions shouldn't get recourded in the prefs. |
| 2593 ValidatePrefKeyCount(0); | 2603 ValidatePrefKeyCount(0); |
| 2594 | 2604 |
| 2595 // Reload all extensions, and make sure it comes back. | 2605 // Reload all extensions, and make sure it comes back. |
| 2596 std::string extension_id = service_->extensions()->at(0)->id(); | 2606 std::string extension_id = service_->extensions()->at(0)->id(); |
| 2597 loaded_.clear(); | 2607 loaded_.clear(); |
| 2598 service_->ReloadExtensions(); | 2608 service_->ReloadExtensions(); |
| 2599 ASSERT_EQ(1u, service_->extensions()->size()); | 2609 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2600 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 2610 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
| 2601 } | 2611 } |
| OLD | NEW |