| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 void RemoveExtension(const std::string& id) { | 244 void RemoveExtension(const std::string& id) { |
| 245 extension_map_.erase(id); | 245 extension_map_.erase(id); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // ExternalProvider implementation: | 248 // ExternalProvider implementation: |
| 249 virtual void VisitRegisteredExtension() OVERRIDE { | 249 virtual void VisitRegisteredExtension() OVERRIDE { |
| 250 visit_count_++; | 250 visit_count_++; |
| 251 for (DataMap::const_iterator i = extension_map_.begin(); | 251 for (DataMap::const_iterator i = extension_map_.begin(); |
| 252 i != extension_map_.end(); ++i) { | 252 i != extension_map_.end(); ++i) { |
| 253 base::Version version(i->second.first); | 253 Version version(i->second.first); |
| 254 | 254 |
| 255 visitor_->OnExternalExtensionFileFound( | 255 visitor_->OnExternalExtensionFileFound( |
| 256 i->first, &version, i->second.second, location_, | 256 i->first, &version, i->second.second, location_, |
| 257 Extension::NO_FLAGS, false); | 257 Extension::NO_FLAGS, false); |
| 258 } | 258 } |
| 259 visitor_->OnExternalProviderReady(this); | 259 visitor_->OnExternalProviderReady(this); |
| 260 } | 260 } |
| 261 | 261 |
| 262 virtual bool HasExtension(const std::string& id) const OVERRIDE { | 262 virtual bool HasExtension(const std::string& id) const OVERRIDE { |
| 263 return extension_map_.find(id) != extension_map_.end(); | 263 return extension_map_.find(id) != extension_map_.end(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 virtual bool GetExtensionDetails( | 266 virtual bool GetExtensionDetails( |
| 267 const std::string& id, | 267 const std::string& id, |
| 268 Manifest::Location* location, | 268 Manifest::Location* location, |
| 269 scoped_ptr<base::Version>* version) const OVERRIDE { | 269 scoped_ptr<Version>* version) const OVERRIDE { |
| 270 DataMap::const_iterator it = extension_map_.find(id); | 270 DataMap::const_iterator it = extension_map_.find(id); |
| 271 if (it == extension_map_.end()) | 271 if (it == extension_map_.end()) |
| 272 return false; | 272 return false; |
| 273 | 273 |
| 274 if (version) | 274 if (version) |
| 275 version->reset(new base::Version(it->second.first)); | 275 version->reset(new Version(it->second.first)); |
| 276 | 276 |
| 277 if (location) | 277 if (location) |
| 278 *location = location_; | 278 *location = location_; |
| 279 | 279 |
| 280 return true; | 280 return true; |
| 281 } | 281 } |
| 282 | 282 |
| 283 virtual bool IsReady() const OVERRIDE { | 283 virtual bool IsReady() const OVERRIDE { |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 354 |
| 355 // Reset our counter. | 355 // Reset our counter. |
| 356 ids_found_ = 0; | 356 ids_found_ = 0; |
| 357 // Ask the provider to look up all extensions and return them. | 357 // Ask the provider to look up all extensions and return them. |
| 358 provider_->VisitRegisteredExtension(); | 358 provider_->VisitRegisteredExtension(); |
| 359 | 359 |
| 360 return ids_found_; | 360 return ids_found_; |
| 361 } | 361 } |
| 362 | 362 |
| 363 virtual bool OnExternalExtensionFileFound(const std::string& id, | 363 virtual bool OnExternalExtensionFileFound(const std::string& id, |
| 364 const base::Version* version, | 364 const Version* version, |
| 365 const base::FilePath& path, | 365 const base::FilePath& path, |
| 366 Manifest::Location unused, | 366 Manifest::Location unused, |
| 367 int creation_flags, | 367 int creation_flags, |
| 368 bool mark_acknowledged) OVERRIDE { | 368 bool mark_acknowledged) OVERRIDE { |
| 369 EXPECT_EQ(expected_creation_flags_, creation_flags); | 369 EXPECT_EQ(expected_creation_flags_, creation_flags); |
| 370 | 370 |
| 371 ++ids_found_; | 371 ++ids_found_; |
| 372 base::DictionaryValue* pref; | 372 base::DictionaryValue* pref; |
| 373 // This tests is to make sure that the provider only notifies us of the | 373 // This tests is to make sure that the provider only notifies us of the |
| 374 // values we gave it. So if the id we doesn't exist in our internal | 374 // values we gave it. So if the id we doesn't exist in our internal |
| 375 // dictionary then something is wrong. | 375 // dictionary then something is wrong. |
| 376 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 376 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 377 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 377 << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
| 378 | 378 |
| 379 EXPECT_TRUE(path.IsAbsolute()); | 379 EXPECT_TRUE(path.IsAbsolute()); |
| 380 if (!fake_base_path_.empty()) | 380 if (!fake_base_path_.empty()) |
| 381 EXPECT_TRUE(fake_base_path_.IsParent(path)); | 381 EXPECT_TRUE(fake_base_path_.IsParent(path)); |
| 382 | 382 |
| 383 if (pref) { | 383 if (pref) { |
| 384 EXPECT_TRUE(provider_->HasExtension(id)); | 384 EXPECT_TRUE(provider_->HasExtension(id)); |
| 385 | 385 |
| 386 // Ask provider if the extension we got back is registered. | 386 // Ask provider if the extension we got back is registered. |
| 387 Manifest::Location location = Manifest::INVALID_LOCATION; | 387 Manifest::Location location = Manifest::INVALID_LOCATION; |
| 388 scoped_ptr<base::Version> v1; | 388 scoped_ptr<Version> v1; |
| 389 base::FilePath crx_path; | 389 base::FilePath crx_path; |
| 390 | 390 |
| 391 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); | 391 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); |
| 392 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 392 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 393 | 393 |
| 394 scoped_ptr<base::Version> v2; | 394 scoped_ptr<Version> v2; |
| 395 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); | 395 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); |
| 396 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 396 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 397 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); | 397 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
| 398 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); | 398 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
| 399 | 399 |
| 400 // Remove it so we won't count it ever again. | 400 // Remove it so we won't count it ever again. |
| 401 prefs_->Remove(id, NULL); | 401 prefs_->Remove(id, NULL); |
| 402 } | 402 } |
| 403 return true; | 403 return true; |
| 404 } | 404 } |
| 405 | 405 |
| 406 virtual bool OnExternalExtensionUpdateUrlFound( | 406 virtual bool OnExternalExtensionUpdateUrlFound( |
| 407 const std::string& id, const GURL& update_url, | 407 const std::string& id, const GURL& update_url, |
| 408 Manifest::Location location, | 408 Manifest::Location location, |
| 409 int creation_flags, | 409 int creation_flags, |
| 410 bool mark_acknowledged) OVERRIDE { | 410 bool mark_acknowledged) OVERRIDE { |
| 411 ++ids_found_; | 411 ++ids_found_; |
| 412 base::DictionaryValue* pref; | 412 base::DictionaryValue* pref; |
| 413 // This tests is to make sure that the provider only notifies us of the | 413 // This tests is to make sure that the provider only notifies us of the |
| 414 // values we gave it. So if the id we doesn't exist in our internal | 414 // values we gave it. So if the id we doesn't exist in our internal |
| 415 // dictionary then something is wrong. | 415 // dictionary then something is wrong. |
| 416 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 416 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 417 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 417 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
| 418 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); | 418 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
| 419 | 419 |
| 420 if (pref) { | 420 if (pref) { |
| 421 EXPECT_TRUE(provider_->HasExtension(id)); | 421 EXPECT_TRUE(provider_->HasExtension(id)); |
| 422 | 422 |
| 423 // External extensions with update URLs do not have versions. | 423 // External extensions with update URLs do not have versions. |
| 424 scoped_ptr<base::Version> v1; | 424 scoped_ptr<Version> v1; |
| 425 Manifest::Location location1 = Manifest::INVALID_LOCATION; | 425 Manifest::Location location1 = Manifest::INVALID_LOCATION; |
| 426 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 426 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
| 427 EXPECT_FALSE(v1.get()); | 427 EXPECT_FALSE(v1.get()); |
| 428 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); | 428 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
| 429 | 429 |
| 430 // Remove it so we won't count it again. | 430 // Remove it so we won't count it again. |
| 431 prefs_->Remove(id, NULL); | 431 prefs_->Remove(id, NULL); |
| 432 } | 432 } |
| 433 return true; | 433 return true; |
| 434 } | 434 } |
| (...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 // extension object. | 1770 // extension object. |
| 1771 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { | 1771 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
| 1772 const char kPrefFromBookmark[] = "from_bookmark"; | 1772 const char kPrefFromBookmark[] = "from_bookmark"; |
| 1773 | 1773 |
| 1774 InitializeEmptyExtensionService(); | 1774 InitializeEmptyExtensionService(); |
| 1775 | 1775 |
| 1776 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1776 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1777 set_extensions_enabled(true); | 1777 set_extensions_enabled(true); |
| 1778 | 1778 |
| 1779 // Register and install an external extension. | 1779 // Register and install an external extension. |
| 1780 base::Version version("1.0.0.0"); | 1780 Version version("1.0.0.0"); |
| 1781 content::WindowedNotificationObserver observer( | 1781 content::WindowedNotificationObserver observer( |
| 1782 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1782 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1783 content::NotificationService::AllSources()); | 1783 content::NotificationService::AllSources()); |
| 1784 if (service_->OnExternalExtensionFileFound( | 1784 if (service_->OnExternalExtensionFileFound( |
| 1785 good_crx, | 1785 good_crx, |
| 1786 &version, | 1786 &version, |
| 1787 path, | 1787 path, |
| 1788 Manifest::EXTERNAL_PREF, | 1788 Manifest::EXTERNAL_PREF, |
| 1789 Extension::FROM_BOOKMARK, | 1789 Extension::FROM_BOOKMARK, |
| 1790 false /* mark_acknowledged */)) { | 1790 false /* mark_acknowledged */)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1806 } | 1806 } |
| 1807 | 1807 |
| 1808 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1808 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
| 1809 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1809 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
| 1810 InitializeEmptyExtensionService(); | 1810 InitializeEmptyExtensionService(); |
| 1811 | 1811 |
| 1812 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1812 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1813 set_extensions_enabled(true); | 1813 set_extensions_enabled(true); |
| 1814 | 1814 |
| 1815 // Install an external extension. | 1815 // Install an external extension. |
| 1816 base::Version version("1.0.0.0"); | 1816 Version version("1.0.0.0"); |
| 1817 content::WindowedNotificationObserver observer( | 1817 content::WindowedNotificationObserver observer( |
| 1818 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1818 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1819 content::NotificationService::AllSources()); | 1819 content::NotificationService::AllSources()); |
| 1820 if (service_->OnExternalExtensionFileFound(good_crx, &version, | 1820 if (service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1821 path, Manifest::EXTERNAL_PREF, | 1821 path, Manifest::EXTERNAL_PREF, |
| 1822 Extension::NO_FLAGS, false)) { | 1822 Extension::NO_FLAGS, false)) { |
| 1823 observer.Wait(); | 1823 observer.Wait(); |
| 1824 } | 1824 } |
| 1825 | 1825 |
| 1826 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1826 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1827 | 1827 |
| 1828 // Uninstall it and check that its killbit gets set. | 1828 // Uninstall it and check that its killbit gets set. |
| 1829 UninstallExtension(good_crx, false); | 1829 UninstallExtension(good_crx, false); |
| 1830 ValidateIntegerPref(good_crx, "location", | 1830 ValidateIntegerPref(good_crx, "location", |
| 1831 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1831 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1832 | 1832 |
| 1833 // Try to re-install it externally. This should fail because of the killbit. | 1833 // Try to re-install it externally. This should fail because of the killbit. |
| 1834 service_->OnExternalExtensionFileFound(good_crx, &version, | 1834 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1835 path, Manifest::EXTERNAL_PREF, | 1835 path, Manifest::EXTERNAL_PREF, |
| 1836 Extension::NO_FLAGS, false); | 1836 Extension::NO_FLAGS, false); |
| 1837 base::RunLoop().RunUntilIdle(); | 1837 base::RunLoop().RunUntilIdle(); |
| 1838 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1838 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
| 1839 ValidateIntegerPref(good_crx, "location", | 1839 ValidateIntegerPref(good_crx, "location", |
| 1840 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1840 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1841 | 1841 |
| 1842 version = base::Version("1.0.0.1"); | 1842 version = Version("1.0.0.1"); |
| 1843 // Repeat the same thing with a newer version of the extension. | 1843 // Repeat the same thing with a newer version of the extension. |
| 1844 path = data_dir_.AppendASCII("good2.crx"); | 1844 path = data_dir_.AppendASCII("good2.crx"); |
| 1845 service_->OnExternalExtensionFileFound(good_crx, &version, | 1845 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1846 path, Manifest::EXTERNAL_PREF, | 1846 path, Manifest::EXTERNAL_PREF, |
| 1847 Extension::NO_FLAGS, false); | 1847 Extension::NO_FLAGS, false); |
| 1848 base::RunLoop().RunUntilIdle(); | 1848 base::RunLoop().RunUntilIdle(); |
| 1849 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); | 1849 ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
| 1850 ValidateIntegerPref(good_crx, "location", | 1850 ValidateIntegerPref(good_crx, "location", |
| 1851 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1851 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1852 | 1852 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); | 1888 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
| 1889 service_->OnExternalProviderReady(&provider); | 1889 service_->OnExternalProviderReady(&provider); |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 // Test that external extensions with incorrect IDs are not installed. | 1892 // Test that external extensions with incorrect IDs are not installed. |
| 1893 TEST_F(ExtensionServiceTest, FailOnWrongId) { | 1893 TEST_F(ExtensionServiceTest, FailOnWrongId) { |
| 1894 InitializeEmptyExtensionService(); | 1894 InitializeEmptyExtensionService(); |
| 1895 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1895 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1896 set_extensions_enabled(true); | 1896 set_extensions_enabled(true); |
| 1897 | 1897 |
| 1898 base::Version version("1.0.0.0"); | 1898 Version version("1.0.0.0"); |
| 1899 | 1899 |
| 1900 const std::string wrong_id = all_zero; | 1900 const std::string wrong_id = all_zero; |
| 1901 const std::string correct_id = good_crx; | 1901 const std::string correct_id = good_crx; |
| 1902 ASSERT_NE(correct_id, wrong_id); | 1902 ASSERT_NE(correct_id, wrong_id); |
| 1903 | 1903 |
| 1904 // Install an external extension with an ID from the external | 1904 // Install an external extension with an ID from the external |
| 1905 // source that is not equal to the ID in the extension manifest. | 1905 // source that is not equal to the ID in the extension manifest. |
| 1906 content::WindowedNotificationObserver observer( | 1906 content::WindowedNotificationObserver observer( |
| 1907 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1907 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1908 content::NotificationService::AllSources()); | 1908 content::NotificationService::AllSources()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1926 } | 1926 } |
| 1927 | 1927 |
| 1928 // Test that external extensions with incorrect versions are not installed. | 1928 // Test that external extensions with incorrect versions are not installed. |
| 1929 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1929 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
| 1930 InitializeEmptyExtensionService(); | 1930 InitializeEmptyExtensionService(); |
| 1931 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1931 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1932 set_extensions_enabled(true); | 1932 set_extensions_enabled(true); |
| 1933 | 1933 |
| 1934 // Install an external extension with a version from the external | 1934 // Install an external extension with a version from the external |
| 1935 // source that is not equal to the version in the extension manifest. | 1935 // source that is not equal to the version in the extension manifest. |
| 1936 base::Version wrong_version("1.2.3.4"); | 1936 Version wrong_version("1.2.3.4"); |
| 1937 content::WindowedNotificationObserver observer( | 1937 content::WindowedNotificationObserver observer( |
| 1938 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1938 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1939 content::NotificationService::AllSources()); | 1939 content::NotificationService::AllSources()); |
| 1940 service_->OnExternalExtensionFileFound( | 1940 service_->OnExternalExtensionFileFound( |
| 1941 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, | 1941 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, |
| 1942 Extension::NO_FLAGS, false); | 1942 Extension::NO_FLAGS, false); |
| 1943 | 1943 |
| 1944 observer.Wait(); | 1944 observer.Wait(); |
| 1945 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1945 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1946 | 1946 |
| 1947 // Try again with the right version. Expect success. | 1947 // Try again with the right version. Expect success. |
| 1948 service_->pending_extension_manager()->Remove(good_crx); | 1948 service_->pending_extension_manager()->Remove(good_crx); |
| 1949 base::Version correct_version("1.0.0.0"); | 1949 Version correct_version("1.0.0.0"); |
| 1950 content::WindowedNotificationObserver observer2( | 1950 content::WindowedNotificationObserver observer2( |
| 1951 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 1951 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1952 content::NotificationService::AllSources()); | 1952 content::NotificationService::AllSources()); |
| 1953 if (service_->OnExternalExtensionFileFound( | 1953 if (service_->OnExternalExtensionFileFound( |
| 1954 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, | 1954 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, |
| 1955 Extension::NO_FLAGS, false)) { | 1955 Extension::NO_FLAGS, false)) { |
| 1956 observer2.Wait(); | 1956 observer2.Wait(); |
| 1957 } | 1957 } |
| 1958 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1958 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1959 } | 1959 } |
| (...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3344 | 3344 |
| 3345 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3345 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 3346 const Extension* good = InstallCRX(path, INSTALL_NEW); | 3346 const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3347 ASSERT_EQ(1u, service_->extensions()->size()); | 3347 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3348 | 3348 |
| 3349 EXPECT_FALSE(good->is_theme()); | 3349 EXPECT_FALSE(good->is_theme()); |
| 3350 | 3350 |
| 3351 // Use AddExtensionImpl() as AddFrom*() would balk. | 3351 // Use AddExtensionImpl() as AddFrom*() would balk. |
| 3352 service_->pending_extension_manager()->AddExtensionImpl( | 3352 service_->pending_extension_manager()->AddExtensionImpl( |
| 3353 good->id(), extensions::ManifestURL::GetUpdateURL(good), | 3353 good->id(), extensions::ManifestURL::GetUpdateURL(good), |
| 3354 base::Version(), &IsExtension, kGoodIsFromSync, | 3354 Version(), &IsExtension, kGoodIsFromSync, |
| 3355 kGoodInstallSilently, Manifest::INTERNAL, | 3355 kGoodInstallSilently, Manifest::INTERNAL, |
| 3356 Extension::NO_FLAGS, false); | 3356 Extension::NO_FLAGS, false); |
| 3357 UpdateExtension(good->id(), path, ENABLED); | 3357 UpdateExtension(good->id(), path, ENABLED); |
| 3358 | 3358 |
| 3359 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 3359 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
| 3360 } | 3360 } |
| 3361 | 3361 |
| 3362 #if defined(ENABLE_BLACKLIST_TESTS) | 3362 #if defined(ENABLE_BLACKLIST_TESTS) |
| 3363 // Tests blacklisting then unblacklisting extensions after the service has been | 3363 // Tests blacklisting then unblacklisting extensions after the service has been |
| 3364 // initialized. | 3364 // initialized. |
| (...skipping 2704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6069 // Skip install when the location has the same priority as the installed | 6069 // Skip install when the location has the same priority as the installed |
| 6070 // location. | 6070 // location. |
| 6071 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( | 6071 EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( |
| 6072 kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL, | 6072 kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL, |
| 6073 Extension::NO_FLAGS, false)); | 6073 Extension::NO_FLAGS, false)); |
| 6074 | 6074 |
| 6075 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 6075 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6076 } | 6076 } |
| 6077 | 6077 |
| 6078 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { | 6078 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
| 6079 base::Version older_version("0.1.0.0"); | 6079 Version older_version("0.1.0.0"); |
| 6080 base::Version newer_version("2.0.0.0"); | 6080 Version newer_version("2.0.0.0"); |
| 6081 | 6081 |
| 6082 // We don't want the extension to be installed. A path that doesn't | 6082 // We don't want the extension to be installed. A path that doesn't |
| 6083 // point to a valid CRX ensures this. | 6083 // point to a valid CRX ensures this. |
| 6084 const base::FilePath kInvalidPathToCrx = base::FilePath(); | 6084 const base::FilePath kInvalidPathToCrx = base::FilePath(); |
| 6085 | 6085 |
| 6086 const int kCreationFlags = 0; | 6086 const int kCreationFlags = 0; |
| 6087 const bool kDontMarkAcknowledged = false; | 6087 const bool kDontMarkAcknowledged = false; |
| 6088 | 6088 |
| 6089 InitializeEmptyExtensionService(); | 6089 InitializeEmptyExtensionService(); |
| 6090 | 6090 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6248 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, | 6248 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 6249 // adding from external pref will now fail. | 6249 // adding from external pref will now fail. |
| 6250 EXPECT_FALSE( | 6250 EXPECT_FALSE( |
| 6251 service_->OnExternalExtensionFileFound( | 6251 service_->OnExternalExtensionFileFound( |
| 6252 kGoodId, &newer_version, kInvalidPathToCrx, | 6252 kGoodId, &newer_version, kInvalidPathToCrx, |
| 6253 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); | 6253 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 6254 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 6254 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6255 } | 6255 } |
| 6256 | 6256 |
| 6257 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { | 6257 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
| 6258 base::Version kVersion123("1.2.3"); | 6258 Version kVersion123("1.2.3"); |
| 6259 base::Version kVersion124("1.2.4"); | 6259 Version kVersion124("1.2.4"); |
| 6260 base::Version kVersion125("1.2.5"); | 6260 Version kVersion125("1.2.5"); |
| 6261 const base::FilePath kInvalidPathToCrx = base::FilePath(); | 6261 const base::FilePath kInvalidPathToCrx = base::FilePath(); |
| 6262 const int kCreationFlags = 0; | 6262 const int kCreationFlags = 0; |
| 6263 const bool kDontMarkAcknowledged = false; | 6263 const bool kDontMarkAcknowledged = false; |
| 6264 | 6264 |
| 6265 InitializeEmptyExtensionService(); | 6265 InitializeEmptyExtensionService(); |
| 6266 | 6266 |
| 6267 extensions::PendingExtensionManager* pending = | 6267 extensions::PendingExtensionManager* pending = |
| 6268 service_->pending_extension_manager(); | 6268 service_->pending_extension_manager(); |
| 6269 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 6269 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6270 | 6270 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6354 | 6354 |
| 6355 // Fake an external source adding a URL to fetch an extension from. | 6355 // Fake an external source adding a URL to fetch an extension from. |
| 6356 bool AddPendingExternalPrefUrl() { | 6356 bool AddPendingExternalPrefUrl() { |
| 6357 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( | 6357 return service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 6358 crx_id_, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD, | 6358 crx_id_, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6359 Extension::NO_FLAGS, false); | 6359 Extension::NO_FLAGS, false); |
| 6360 } | 6360 } |
| 6361 | 6361 |
| 6362 // Fake an external file from external_extensions.json. | 6362 // Fake an external file from external_extensions.json. |
| 6363 bool AddPendingExternalPrefFileInstall() { | 6363 bool AddPendingExternalPrefFileInstall() { |
| 6364 base::Version version("1.0.0.0"); | 6364 Version version("1.0.0.0"); |
| 6365 | 6365 |
| 6366 return service_->OnExternalExtensionFileFound( | 6366 return service_->OnExternalExtensionFileFound( |
| 6367 crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, | 6367 crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, |
| 6368 Extension::NO_FLAGS, false); | 6368 Extension::NO_FLAGS, false); |
| 6369 } | 6369 } |
| 6370 | 6370 |
| 6371 // Fake a request from sync to install an extension. | 6371 // Fake a request from sync to install an extension. |
| 6372 bool AddPendingSyncInstall() { | 6372 bool AddPendingSyncInstall() { |
| 6373 return service_->pending_extension_manager()->AddFromSync( | 6373 return service_->pending_extension_manager()->AddFromSync( |
| 6374 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); | 6374 crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6780 // ReconcileKnownDisabled(). | 6780 // ReconcileKnownDisabled(). |
| 6781 service_->EnableExtension(good2); | 6781 service_->EnableExtension(good2); |
| 6782 service_->ReconcileKnownDisabled(); | 6782 service_->ReconcileKnownDisabled(); |
| 6783 expected_extensions.insert(good2); | 6783 expected_extensions.insert(good2); |
| 6784 expected_disabled_extensions.erase(good2); | 6784 expected_disabled_extensions.erase(good2); |
| 6785 | 6785 |
| 6786 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); | 6786 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6787 EXPECT_EQ(expected_disabled_extensions, | 6787 EXPECT_EQ(expected_disabled_extensions, |
| 6788 service_->disabled_extensions()->GetIDs()); | 6788 service_->disabled_extensions()->GetIDs()); |
| 6789 } | 6789 } |
| OLD | NEW |