Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 9320021: Fix crash in ExtensionService::InitializePermissions(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: add the test data Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/installed_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 91 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
92 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; 92 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
93 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 93 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj";
94 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; 94 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk";
95 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; 95 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa";
96 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 96 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
97 const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; 97 const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln";
98 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; 98 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad";
99 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 99 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
100 const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; 100 const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin";
101 const char* const unpacked = "cbcdidchbppangcjoddlpdjlenngjldk";
101 102
102 struct ExtensionsOrder { 103 struct ExtensionsOrder {
103 bool operator()(const Extension* a, const Extension* b) { 104 bool operator()(const Extension* a, const Extension* b) {
104 return a->name() < b->name(); 105 return a->name() < b->name();
105 } 106 }
106 }; 107 };
107 108
108 static std::vector<string16> GetErrors() { 109 static std::vector<string16> GetErrors() {
109 const std::vector<string16>* errors = 110 const std::vector<string16>* errors =
110 ExtensionErrorReporter::GetInstance()->GetErrors(); 111 ExtensionErrorReporter::GetInstance()->GetErrors();
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); 1889 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
1889 loop_.RunAllPending(); 1890 loop_.RunAllPending();
1890 EXPECT_EQ(0u, GetErrors().size()); 1891 EXPECT_EQ(0u, GetErrors().size());
1891 ASSERT_EQ(1u, loaded_.size()); 1892 ASSERT_EQ(1u, loaded_.size());
1892 EXPECT_EQ(1u, service_->extensions()->size()); 1893 EXPECT_EQ(1u, service_->extensions()->size());
1893 const Extension* theme = *service_->extensions()->begin(); 1894 const Extension* theme = *service_->extensions()->begin();
1894 EXPECT_EQ("name", theme->name()); 1895 EXPECT_EQ("name", theme->name());
1895 EXPECT_EQ("description", theme->description()); 1896 EXPECT_EQ("description", theme->description());
1896 } 1897 }
1897 1898
1899 // Tests that we can change the ID of an unpacked extension by adding a key
1900 // to its manifest.
1901 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) {
1902 InitializeEmptyExtensionService();
1903
1904 ScopedTempDir temp;
1905 ASSERT_TRUE(temp.CreateUniqueTempDir());
1906
1907 FilePath extension_path = temp.path();
1908 FilePath manifest_path = extension_path.Append(Extension::kManifestFilename);
1909 FilePath manifest_no_key = data_dir_.
1910 AppendASCII("unpacked").
1911 AppendASCII("manifest_no_key.json");
1912
1913 FilePath manifest_with_key = data_dir_.
1914 AppendASCII("unpacked").
1915 AppendASCII("manifest_with_key.json");
1916
1917 ASSERT_TRUE(file_util::PathExists(manifest_no_key));
1918 ASSERT_TRUE(file_util::PathExists(manifest_with_key));
1919
1920 // Load the unpacked extension with no key.
1921 file_util::CopyFile(manifest_no_key, manifest_path);
1922 extensions::UnpackedInstaller::Create(service_)->Load(extension_path);
1923
1924 loop_.RunAllPending();
1925 EXPECT_EQ(0u, GetErrors().size());
1926 ASSERT_EQ(1u, loaded_.size());
1927 EXPECT_EQ(1u, service_->extensions()->size());
1928
1929 // Add the key to the manifest.
1930 file_util::CopyFile(manifest_with_key, manifest_path);
1931 loaded_.clear();
1932
1933 // Reload the extensions.
1934 service_->ReloadExtensions();
1935 const Extension* extension = service_->GetExtensionById(unpacked, false);
1936 EXPECT_EQ(unpacked, extension->id());
1937 ASSERT_EQ(1u, loaded_.size());
1938
1939 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but
1940 // we should also test that preferences are preserved.
1941 }
1942
1898 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { 1943 TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
1899 InitializeEmptyExtensionService(); 1944 InitializeEmptyExtensionService();
1900 FilePath theme_path = data_dir_ 1945 FilePath theme_path = data_dir_
1901 .AppendASCII("theme_i18n"); 1946 .AppendASCII("theme_i18n");
1902 1947
1903 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); 1948 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
1904 1949
1905 EXPECT_EQ(0u, GetErrors().size()); 1950 EXPECT_EQ(0u, GetErrors().size());
1906 EXPECT_EQ(1u, service_->extensions()->size()); 1951 EXPECT_EQ(1u, service_->extensions()->size());
1907 EXPECT_EQ("name", theme->name()); 1952 EXPECT_EQ("name", theme->name());
(...skipping 2835 matching lines...) Expand 10 before | Expand all | Expand 10 after
4743 ASSERT_FALSE(AddPendingSyncInstall()); 4788 ASSERT_FALSE(AddPendingSyncInstall());
4744 4789
4745 // Wait for the external source to install. 4790 // Wait for the external source to install.
4746 WaitForCrxInstall(crx_path_, INSTALL_NEW); 4791 WaitForCrxInstall(crx_path_, INSTALL_NEW);
4747 ASSERT_TRUE(IsCrxInstalled()); 4792 ASSERT_TRUE(IsCrxInstalled());
4748 4793
4749 // Now that the extension is installed, sync request should fail 4794 // Now that the extension is installed, sync request should fail
4750 // because the extension is already installed. 4795 // because the extension is already installed.
4751 ASSERT_FALSE(AddPendingSyncInstall()); 4796 ASSERT_FALSE(AddPendingSyncInstall());
4752 } 4797 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/installed_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698