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

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

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 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
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/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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 std::stable_sort(ret_val.begin(), ret_val.end()); 107 std::stable_sort(ret_val.begin(), ret_val.end());
108 108
109 return ret_val; 109 return ret_val;
110 } 110 }
111 111
112 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 112 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
113 int schemes = URLPattern::SCHEME_ALL; 113 int schemes = URLPattern::SCHEME_ALL;
114 extent->AddPattern(URLPattern(schemes, pattern)); 114 extent->AddPattern(URLPattern(schemes, pattern));
115 } 115 }
116 116
117 static void AssertEqualExtents(const URLPatternSet& extent1,
118 const URLPatternSet& extent2) {
119 URLPatternList patterns1 = extent1.patterns();
120 URLPatternList patterns2 = extent2.patterns();
121 std::set<std::string> strings1;
122 EXPECT_EQ(patterns1.size(), patterns2.size());
123
124 for (size_t i = 0; i < patterns1.size(); ++i)
125 strings1.insert(patterns1.at(i).GetAsString());
126
127 std::set<std::string> strings2;
128 for (size_t i = 0; i < patterns2.size(); ++i)
129 strings2.insert(patterns2.at(i).GetAsString());
130
131 EXPECT_EQ(strings1, strings2);
132 }
133
134 } // namespace 117 } // namespace
135 118
136 class MockExtensionProvider : public ExternalExtensionProviderInterface { 119 class MockExtensionProvider : public ExternalExtensionProviderInterface {
137 public: 120 public:
138 explicit MockExtensionProvider( 121 explicit MockExtensionProvider(
139 VisitorInterface* visitor, 122 VisitorInterface* visitor,
140 Extension::Location location) 123 Extension::Location location)
141 : location_(location), visitor_(visitor), visit_count_(0) { 124 : location_(location), visitor_(visitor), visit_count_(0) {
142 } 125 }
143 virtual ~MockExtensionProvider() {} 126 virtual ~MockExtensionProvider() {}
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); 981 EXPECT_EQ(expected_num_extensions, service_->extensions()->size());
999 982
1000 ValidatePrefKeyCount(3); 983 ValidatePrefKeyCount(3);
1001 ValidateIntegerPref(good0, "state", Extension::ENABLED); 984 ValidateIntegerPref(good0, "state", Extension::ENABLED);
1002 ValidateIntegerPref(good0, "location", Extension::INTERNAL); 985 ValidateIntegerPref(good0, "location", Extension::INTERNAL);
1003 ValidateIntegerPref(good1, "state", Extension::ENABLED); 986 ValidateIntegerPref(good1, "state", Extension::ENABLED);
1004 ValidateIntegerPref(good1, "location", Extension::INTERNAL); 987 ValidateIntegerPref(good1, "location", Extension::INTERNAL);
1005 ValidateIntegerPref(good2, "state", Extension::ENABLED); 988 ValidateIntegerPref(good2, "state", Extension::ENABLED);
1006 ValidateIntegerPref(good2, "location", Extension::INTERNAL); 989 ValidateIntegerPref(good2, "location", Extension::INTERNAL);
1007 990
991 URLPatternSet expected_patterns;
992 AddPattern(&expected_patterns, "file:///*");
993 AddPattern(&expected_patterns, "http://*.google.com/*");
994 AddPattern(&expected_patterns, "https://*.google.com/*");
1008 const Extension* extension = loaded_[0]; 995 const Extension* extension = loaded_[0];
1009 const UserScriptList& scripts = extension->content_scripts(); 996 const UserScriptList& scripts = extension->content_scripts();
1010 ASSERT_EQ(2u, scripts.size()); 997 ASSERT_EQ(2u, scripts.size());
1011 EXPECT_EQ(3u, scripts[0].url_patterns().size()); 998 EXPECT_EQ(expected_patterns, scripts[0].url_patterns());
1012 EXPECT_EQ("file:///*",
1013 scripts[0].url_patterns()[0].GetAsString());
1014 EXPECT_EQ("http://*.google.com/*",
1015 scripts[0].url_patterns()[1].GetAsString());
1016 EXPECT_EQ("https://*.google.com/*",
1017 scripts[0].url_patterns()[2].GetAsString());
1018 EXPECT_EQ(2u, scripts[0].js_scripts().size()); 999 EXPECT_EQ(2u, scripts[0].js_scripts().size());
1019 ExtensionResource resource00(extension->id(), 1000 ExtensionResource resource00(extension->id(),
1020 scripts[0].js_scripts()[0].extension_root(), 1001 scripts[0].js_scripts()[0].extension_root(),
1021 scripts[0].js_scripts()[0].relative_path()); 1002 scripts[0].js_scripts()[0].relative_path());
1022 FilePath expected_path(extension->path().AppendASCII("script1.js")); 1003 FilePath expected_path(extension->path().AppendASCII("script1.js"));
1023 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1004 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1024 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); 1005 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path));
1025 ExtensionResource resource01(extension->id(), 1006 ExtensionResource resource01(extension->id(),
1026 scripts[0].js_scripts()[1].extension_root(), 1007 scripts[0].js_scripts()[1].extension_root(),
1027 scripts[0].js_scripts()[1].relative_path()); 1008 scripts[0].js_scripts()[1].relative_path());
1028 expected_path = extension->path().AppendASCII("script2.js"); 1009 expected_path = extension->path().AppendASCII("script2.js");
1029 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1010 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1030 EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); 1011 EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path));
1031 EXPECT_TRUE(extension->plugins().empty()); 1012 EXPECT_TRUE(extension->plugins().empty());
1032 EXPECT_EQ(1u, scripts[1].url_patterns().size()); 1013 EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size());
1033 EXPECT_EQ("http://*.news.com/*", scripts[1].url_patterns()[0].GetAsString()); 1014 EXPECT_EQ("http://*.news.com/*",
1015 scripts[1].url_patterns().begin()->GetAsString());
1034 ExtensionResource resource10(extension->id(), 1016 ExtensionResource resource10(extension->id(),
1035 scripts[1].js_scripts()[0].extension_root(), 1017 scripts[1].js_scripts()[0].extension_root(),
1036 scripts[1].js_scripts()[0].relative_path()); 1018 scripts[1].js_scripts()[0].relative_path());
1037 expected_path = 1019 expected_path =
1038 extension->path().AppendASCII("js_files").AppendASCII("script3.js"); 1020 extension->path().AppendASCII("js_files").AppendASCII("script3.js");
1039 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); 1021 ASSERT_TRUE(file_util::AbsolutePath(&expected_path));
1040 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); 1022 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path));
1041 const URLPatternList permissions = 1023
1042 extension->permission_set()->explicit_hosts().patterns(); 1024 expected_patterns.ClearPatterns();
1043 ASSERT_EQ(2u, permissions.size()); 1025 AddPattern(&expected_patterns, "http://*.google.com/*");
1044 EXPECT_EQ("http://*.google.com/*", permissions[0].GetAsString()); 1026 AddPattern(&expected_patterns, "https://*.google.com/*");
1045 EXPECT_EQ("https://*.google.com/*", permissions[1].GetAsString()); 1027 EXPECT_EQ(expected_patterns, extension->permission_set()->explicit_hosts());
1046 1028
1047 EXPECT_EQ(std::string(good1), loaded_[1]->id()); 1029 EXPECT_EQ(std::string(good1), loaded_[1]->id());
1048 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); 1030 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
1049 EXPECT_EQ(std::string(""), loaded_[1]->description()); 1031 EXPECT_EQ(std::string(""), loaded_[1]->description());
1050 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), 1032 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
1051 loaded_[1]->background_url()); 1033 loaded_[1]->background_url());
1052 EXPECT_EQ(0u, loaded_[1]->content_scripts().size()); 1034 EXPECT_EQ(0u, loaded_[1]->content_scripts().size());
1053 // We don't parse the plugins section on Chrome OS. 1035 // We don't parse the plugins section on Chrome OS.
1054 #if defined(OS_CHROMEOS) 1036 #if defined(OS_CHROMEOS)
1055 EXPECT_EQ(0u, loaded_[1]->plugins().size()); 1037 EXPECT_EQ(0u, loaded_[1]->plugins().size());
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 AddPattern(&expected_host_perms, "http://*.google.com/*"); 1382 AddPattern(&expected_host_perms, "http://*.google.com/*");
1401 AddPattern(&expected_host_perms, "https://*.google.com/*"); 1383 AddPattern(&expected_host_perms, "https://*.google.com/*");
1402 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); 1384 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
1403 AddPattern(&expected_host_perms, "http://www.example.com/*"); 1385 AddPattern(&expected_host_perms, "http://www.example.com/*");
1404 1386
1405 known_perms.reset(prefs->GetGrantedPermissions(extension_id)); 1387 known_perms.reset(prefs->GetGrantedPermissions(extension_id));
1406 EXPECT_TRUE(known_perms.get()); 1388 EXPECT_TRUE(known_perms.get());
1407 EXPECT_FALSE(known_perms->IsEmpty()); 1389 EXPECT_FALSE(known_perms->IsEmpty());
1408 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1390 EXPECT_EQ(expected_api_perms, known_perms->apis());
1409 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1391 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1410 AssertEqualExtents(expected_host_perms, known_perms->effective_hosts()); 1392 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
1411 } 1393 }
1412 1394
1413 #if !defined(OS_CHROMEOS) 1395 #if !defined(OS_CHROMEOS)
1414 // Tests that the granted permissions full_access bit gets set correctly when 1396 // Tests that the granted permissions full_access bit gets set correctly when
1415 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS 1397 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS
1416 // since they don't support plugins. 1398 // since they don't support plugins.
1417 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { 1399 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1418 InitializeEmptyExtensionService(); 1400 InitializeEmptyExtensionService();
1419 1401
1420 FilePath path = data_dir_ 1402 FilePath path = data_dir_
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED); 1477 ASSERT_TRUE(prefs->GetExtensionState(extension_id) == Extension::ENABLED);
1496 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1478 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id));
1497 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1479 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1498 1480
1499 scoped_ptr<ExtensionPermissionSet> current_perms( 1481 scoped_ptr<ExtensionPermissionSet> current_perms(
1500 prefs->GetGrantedPermissions(extension_id)); 1482 prefs->GetGrantedPermissions(extension_id));
1501 ASSERT_TRUE(current_perms.get()); 1483 ASSERT_TRUE(current_perms.get());
1502 ASSERT_FALSE(current_perms->IsEmpty()); 1484 ASSERT_FALSE(current_perms->IsEmpty());
1503 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1485 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1504 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1486 ASSERT_EQ(expected_api_permissions, current_perms->apis());
1505 AssertEqualExtents(expected_host_permissions, 1487 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
1506 current_perms->effective_hosts());
1507 1488
1508 // Tests that the extension is disabled when a host permission is missing from 1489 // Tests that the extension is disabled when a host permission is missing from
1509 // the extension's granted host permissions preference. (This simulates 1490 // the extension's granted host permissions preference. (This simulates
1510 // updating the browser to a version which recognizes additional host 1491 // updating the browser to a version which recognizes additional host
1511 // permissions). 1492 // permissions).
1512 host_permissions.clear(); 1493 host_permissions.clear();
1513 current_perms.reset(); 1494 current_perms.reset();
1514 1495
1515 host_permissions.insert("http://*.google.com/*"); 1496 host_permissions.insert("http://*.google.com/*");
1516 host_permissions.insert("https://*.google.com/*"); 1497 host_permissions.insert("https://*.google.com/*");
(...skipping 20 matching lines...) Expand all
1537 service_->GrantPermissionsAndEnableExtension(extension); 1518 service_->GrantPermissionsAndEnableExtension(extension);
1538 1519
1539 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); 1520 ASSERT_TRUE(service_->IsExtensionEnabled(extension_id));
1540 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1521 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1541 1522
1542 current_perms.reset(prefs->GetGrantedPermissions(extension_id)); 1523 current_perms.reset(prefs->GetGrantedPermissions(extension_id));
1543 ASSERT_TRUE(current_perms.get()); 1524 ASSERT_TRUE(current_perms.get());
1544 ASSERT_FALSE(current_perms->IsEmpty()); 1525 ASSERT_FALSE(current_perms->IsEmpty());
1545 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1526 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1546 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1527 ASSERT_EQ(expected_api_permissions, current_perms->apis());
1547 AssertEqualExtents(expected_host_permissions, 1528 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
1548 current_perms->effective_hosts());
1549 } 1529 }
1550 1530
1551 // Test Packaging and installing an extension. 1531 // Test Packaging and installing an extension.
1552 TEST_F(ExtensionServiceTest, PackExtension) { 1532 TEST_F(ExtensionServiceTest, PackExtension) {
1553 InitializeEmptyExtensionService(); 1533 InitializeEmptyExtensionService();
1554 FilePath input_directory = data_dir_ 1534 FilePath input_directory = data_dir_
1555 .AppendASCII("good") 1535 .AppendASCII("good")
1556 .AppendASCII("Extensions") 1536 .AppendASCII("Extensions")
1557 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1537 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1558 .AppendASCII("1.0.0.0"); 1538 .AppendASCII("1.0.0.0");
(...skipping 2248 matching lines...) Expand 10 before | Expand all | Expand 10 after
3807 ASSERT_FALSE(AddPendingSyncInstall()); 3787 ASSERT_FALSE(AddPendingSyncInstall());
3808 3788
3809 // Wait for the external source to install. 3789 // Wait for the external source to install.
3810 WaitForCrxInstall(crx_path_, true); 3790 WaitForCrxInstall(crx_path_, true);
3811 ASSERT_TRUE(IsCrxInstalled()); 3791 ASSERT_TRUE(IsCrxInstalled());
3812 3792
3813 // Now that the extension is installed, sync request should fail 3793 // Now that the extension is installed, sync request should fail
3814 // because the extension is already installed. 3794 // because the extension is already installed.
3815 ASSERT_FALSE(AddPendingSyncInstall()); 3795 ASSERT_FALSE(AddPendingSyncInstall());
3816 } 3796 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs_unittest.cc ('k') | chrome/browser/extensions/user_script_master.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698