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

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 6772022: Make <all_urls> and file:///* in permissions trigger "Allow file access" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 data.clear(); 770 data.clear();
771 result.clear(); 771 result.clear();
772 path = path.DirName().AppendASCII("bad_magic.crx"); 772 path = path.DirName().AppendASCII("bad_magic.crx");
773 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 773 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
774 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 774 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
775 GURL("http://www.example.com/foo.crx"), "", &result)); 775 GURL("http://www.example.com/foo.crx"), "", &result));
776 EXPECT_EQ("application/octet-stream", result); 776 EXPECT_EQ("application/octet-stream", result);
777 } 777 }
778 778
779 static scoped_refptr<Extension> LoadManifest(const std::string& dir, 779 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
780 const std::string& test_file) { 780 const std::string& test_file,
781 int extra_flags) {
781 FilePath path; 782 FilePath path;
782 PathService::Get(chrome::DIR_TEST_DATA, &path); 783 PathService::Get(chrome::DIR_TEST_DATA, &path);
783 path = path.AppendASCII("extensions") 784 path = path.AppendASCII("extensions")
784 .AppendASCII(dir) 785 .AppendASCII(dir)
785 .AppendASCII(test_file); 786 .AppendASCII(test_file);
786 787
787 JSONFileValueSerializer serializer(path); 788 JSONFileValueSerializer serializer(path);
788 std::string error; 789 std::string error;
789 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error)); 790 scoped_ptr<Value> result(serializer.Deserialize(NULL, &error));
790 if (!result.get()) { 791 if (!result.get()) {
791 EXPECT_EQ("", error); 792 EXPECT_EQ("", error);
792 return NULL; 793 return NULL;
793 } 794 }
794 795
795 scoped_refptr<Extension> extension = Extension::Create( 796 scoped_refptr<Extension> extension = Extension::Create(
796 path.DirName(), Extension::INVALID, 797 path.DirName(), Extension::INVALID,
797 *static_cast<DictionaryValue*>(result.get()), 798 *static_cast<DictionaryValue*>(result.get()),
798 Extension::STRICT_ERROR_CHECKS, &error); 799 Extension::STRICT_ERROR_CHECKS | extra_flags, &error);
799 EXPECT_TRUE(extension) << error; 800 EXPECT_TRUE(extension) << error;
800 return extension; 801 return extension;
801 } 802 }
802 803
804 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
805 const std::string& test_file) {
806 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
807 }
808
803 TEST(ExtensionTest, EffectiveHostPermissions) { 809 TEST(ExtensionTest, EffectiveHostPermissions) {
804 scoped_refptr<Extension> extension; 810 scoped_refptr<Extension> extension;
805 ExtensionExtent hosts; 811 ExtensionExtent hosts;
806 812
807 extension = LoadManifest("effective_host_permissions", "empty.json"); 813 extension = LoadManifest("effective_host_permissions", "empty.json");
808 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 814 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
809 EXPECT_FALSE(hosts.ContainsURL(GURL("http://www.google.com"))); 815 EXPECT_FALSE(hosts.ContainsURL(GURL("http://www.google.com")));
810 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 816 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
811 817
812 extension = LoadManifest("effective_host_permissions", "one_host.json"); 818 extension = LoadManifest("effective_host_permissions", "one_host.json");
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 1164
1159 TEST(ExtensionTest, GetHostPermissionMessages_ManyHosts) { 1165 TEST(ExtensionTest, GetHostPermissionMessages_ManyHosts) {
1160 scoped_refptr<Extension> extension; 1166 scoped_refptr<Extension> extension;
1161 extension = LoadManifest("permissions", "many-hosts.json"); 1167 extension = LoadManifest("permissions", "many-hosts.json");
1162 std::vector<string16> warnings = extension->GetPermissionMessages(); 1168 std::vector<string16> warnings = extension->GetPermissionMessages();
1163 ASSERT_EQ(1u, warnings.size()); 1169 ASSERT_EQ(1u, warnings.size());
1164 EXPECT_EQ("Your data on www.google.com and encrypted.google.com", 1170 EXPECT_EQ("Your data on www.google.com and encrypted.google.com",
1165 UTF16ToUTF8(warnings[0])); 1171 UTF16ToUTF8(warnings[0]));
1166 } 1172 }
1167 1173
1174 TEST(ExtensionTest, WantsFileAccess) {
1175 scoped_refptr<Extension> extension;
1176 GURL file_url("file:///etc/passwd");
1177
1178 // <all_urls> permission
1179 extension = LoadManifest("permissions", "permissions_all_urls.json");
1180 EXPECT_TRUE(extension->wants_file_access());
1181 EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1182 extension = LoadManifest(
1183 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS);
1184 EXPECT_TRUE(extension->wants_file_access());
1185 EXPECT_TRUE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1186
1187 // file:///* permission
1188 extension = LoadManifest("permissions", "permissions_file_scheme.json");
1189 EXPECT_TRUE(extension->wants_file_access());
1190 EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1191 extension = LoadManifest("permissions", "permissions_file_scheme.json",
1192 Extension::ALLOW_FILE_ACCESS);
1193 EXPECT_TRUE(extension->wants_file_access());
1194 EXPECT_TRUE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1195
1196 // http://* permission
1197 extension = LoadManifest("permissions", "permissions_http_scheme.json");
1198 EXPECT_FALSE(extension->wants_file_access());
1199 EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1200 extension = LoadManifest("permissions", "permissions_http_scheme.json",
1201 Extension::ALLOW_FILE_ACCESS);
1202 EXPECT_FALSE(extension->wants_file_access());
1203 EXPECT_FALSE(extension->CanExecuteScriptOnPage(file_url, NULL, NULL));
1204
1205 // <all_urls> content script match
1206 extension = LoadManifest("permissions", "content_script_all_urls.json");
1207 EXPECT_TRUE(extension->wants_file_access());
1208 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
1209 file_url, &extension->content_scripts()[0], NULL));
1210 extension = LoadManifest("permissions", "content_script_all_urls.json",
1211 Extension::ALLOW_FILE_ACCESS);
1212 EXPECT_TRUE(extension->wants_file_access());
1213 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
1214 file_url, &extension->content_scripts()[0], NULL));
1215
1216 // file:///* content script match
1217 extension = LoadManifest("permissions", "content_script_file_scheme.json");
1218 EXPECT_TRUE(extension->wants_file_access());
1219 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
1220 file_url, &extension->content_scripts()[0], NULL));
1221 extension = LoadManifest("permissions", "content_script_file_scheme.json",
1222 Extension::ALLOW_FILE_ACCESS);
1223 EXPECT_TRUE(extension->wants_file_access());
1224 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
1225 file_url, &extension->content_scripts()[0], NULL));
1226
1227 // http://* content script match
1228 extension = LoadManifest("permissions", "content_script_http_scheme.json");
1229 EXPECT_FALSE(extension->wants_file_access());
1230 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
1231 file_url, &extension->content_scripts()[0], NULL));
1232 extension = LoadManifest("permissions", "content_script_http_scheme.json",
1233 Extension::ALLOW_FILE_ACCESS);
1234 EXPECT_FALSE(extension->wants_file_access());
1235 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
1236 file_url, &extension->content_scripts()[0], NULL));
1237 }
1238
1168 TEST(ExtensionTest, GetDistinctHostsForDisplay) { 1239 TEST(ExtensionTest, GetDistinctHostsForDisplay) {
1169 std::vector<std::string> expected; 1240 std::vector<std::string> expected;
1170 expected.push_back("www.foo.com"); 1241 expected.push_back("www.foo.com");
1171 expected.push_back("www.bar.com"); 1242 expected.push_back("www.bar.com");
1172 expected.push_back("www.baz.com"); 1243 expected.push_back("www.baz.com");
1173 URLPatternList actual; 1244 URLPatternList actual;
1174 1245
1175 { 1246 {
1176 SCOPED_TRACE("no dupes"); 1247 SCOPED_TRACE("no dupes");
1177 1248
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 EXPECT_TRUE(Extension::GenerateId("test", &result)); 1494 EXPECT_TRUE(Extension::GenerateId("test", &result));
1424 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); 1495 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
1425 1496
1426 EXPECT_TRUE(Extension::GenerateId("_", &result)); 1497 EXPECT_TRUE(Extension::GenerateId("_", &result));
1427 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); 1498 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
1428 1499
1429 EXPECT_TRUE(Extension::GenerateId( 1500 EXPECT_TRUE(Extension::GenerateId(
1430 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); 1501 "this_string_is_longer_than_a_single_sha256_hash_digest", &result));
1431 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); 1502 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi");
1432 } 1503 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698