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

Unified Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 4687005: Track permissions granted to extensions in prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extensions_service_unittest.cc
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 2e7e67578bdcdfaaeffb74385be99aa78b290719..e115e32f751484d7be620a01e870dec102cac74a 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -72,6 +72,7 @@ const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln";
const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad";
const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
+const char* const permissions_unknown_crx = "bcflfiohkjolmhmjjocpfbloomonhpkc";
struct ExtensionsOrder {
bool operator()(const Extension* a, const Extension* b) {
@@ -1010,6 +1011,149 @@ TEST_F(ExtensionsServiceTest, InstallUserScript) {
ExtensionErrorReporter::GetInstance()->ClearErrors();
}
+// This tests that the granted permissions preferences are correctly set when
+// installing an extension.
+TEST_F(ExtensionsServiceTest, GrantedPermissions) {
+ InitializeEmptyExtensionsService();
+
+ FilePath path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
+ path = path.AppendASCII("extensions")
+ .AppendASCII("permissions-unknown-v1.crx");
Aaron Boodman 2010/11/12 00:05:24 It is better to use unpacked extensions in tests s
jstritar 2010/11/19 21:38:36 Done.
+ ASSERT_TRUE(file_util::PathExists(path));
+
+ InstallExtension(path, true);
Aaron Boodman 2010/11/12 00:05:24 Add a test to validate that there are no granted p
jstritar 2010/11/19 21:38:36 Now that I'm packing the extensions dynamically, I
+
+ ExtensionPrefs* prefs = service_->extension_prefs();
+ const char* extension_id = permissions_unknown_crx;
+
+ // Verify that the valid API permissions have been recognized.
+ std::set<std::string> known_api_perms;
+ std::set<std::string> known_host_perms;
+
+ std::set<std::string> expected_api_perms;
+ expected_api_perms.insert("tabs");
+
+ std::set<std::string> expected_host_perms;
+ expected_host_perms.insert("http://*.google.com/*");
+ expected_host_perms.insert("https://*.google.com/*");
+
+
+ EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id,
+ &known_api_perms,
+ &known_host_perms));
+
+ EXPECT_EQ(expected_api_perms, known_api_perms);
+ EXPECT_EQ(expected_host_perms, known_host_perms);
+}
+
+// Tests that the extension is disabled when an API permission is missing from
+// the extension's granted api permissions preference. (This simulates updating
+// the browser to a version which recognizes a new API permission).
+TEST_F(ExtensionsServiceTest, GrantedAPIPermissions) {
+ FilePath extensions_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
+ extensions_path = extensions_path.AppendASCII("extensions");
+
+ FilePath source_install_dir = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Extensions");
+ FilePath pref_path = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Preferences-unknown-api");
+
+ const char* extension_id = permissions_unknown_crx;
+
+ InitializeInstalledExtensionsService(pref_path, source_install_dir);
Aaron Boodman 2010/11/12 00:05:24 I think it would be a little bit better to test th
jstritar 2010/11/19 21:38:36 Done. I also combined these tests into one, so I d
+ service_->Init();
+ loop_.RunAllPending();
+
+ ExtensionPrefs* prefs = service_->extension_prefs();
+
+ ASSERT_EQ(0u, GetErrors().size());
+ ASSERT_EQ(0u, loaded_.size());
+
+ ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED);
+ ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
+}
+
+// Tests that the extension is disabled when a host permission is missing from
+// the extension's granted host permissions preference. (This simulates updating
+// the browser to a version which recognizes additional host permissions).
+TEST_F(ExtensionsServiceTest, GrantedHostPermissions) {
+ FilePath extensions_path;
Aaron Boodman 2010/11/12 00:05:24 Same thing here.
jstritar 2010/11/19 21:38:36 Done.
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
+ extensions_path = extensions_path.AppendASCII("extensions");
+
+ FilePath source_install_dir = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Extensions");
+ FilePath pref_path = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Preferences-unknown-host");
+
+ const char* extension_id = permissions_unknown_crx;
+
+ InitializeInstalledExtensionsService(pref_path, source_install_dir);
+ service_->Init();
+ loop_.RunAllPending();
+
+ ExtensionPrefs* prefs = service_->extension_prefs();
+
+ ASSERT_EQ(0u, GetErrors().size());
+ ASSERT_EQ(0u, loaded_.size());
+
+ ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::DISABLED);
+ ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
+}
+
+// Tests that the granted permissions preferences are initialized when
+// migrating from the old pref schema.
+TEST_F(ExtensionsServiceTest, GrantedPermissionsInitialization) {
+ FilePath extensions_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
Aaron Boodman 2010/11/12 00:05:24 Same thing here.
jstritar 2010/11/19 21:38:36 Done.
+ extensions_path = extensions_path.AppendASCII("extensions");
+
+ FilePath source_install_dir = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Extensions");
+ FilePath pref_path = extensions_path
+ .AppendASCII("permissions")
+ .AppendASCII("Preferences-initialization");
+
+ const char* extension_id = permissions_unknown_crx;
+
+ InitializeInstalledExtensionsService(pref_path, source_install_dir);
+ service_->Init();
+ loop_.RunAllPending();
+
+ ExtensionPrefs* prefs = service_->extension_prefs();
+
+ ASSERT_EQ(0u, GetErrors().size());
+ ASSERT_EQ(1u, loaded_.size());
+
+ ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
+ ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
+
+ std::set<std::string> known_api_perms;
+ std::set<std::string> known_host_perms;
+
+ std::set<std::string> expected_api_perms;
+ expected_api_perms.insert("tabs");
+
+ std::set<std::string> expected_host_perms;
+ expected_host_perms.insert("http://*.google.com/*");
+ expected_host_perms.insert("https://*.google.com/*");
+
+
+ EXPECT_TRUE(prefs->GetGrantedPermissions(extension_id,
+ &known_api_perms,
+ &known_host_perms));
+
+ EXPECT_EQ(expected_api_perms, known_api_perms);
+ EXPECT_EQ(expected_host_perms, known_host_perms);
+}
+
// Test Packaging and installing an extension.
TEST_F(ExtensionsServiceTest, PackExtension) {
InitializeEmptyExtensionsService();

Powered by Google App Engine
This is Rietveld 408576698