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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); | 208 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); |
209 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 209 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
210 EXPECT_TRUE(extension->permissions_data()->HasEffectiveAccessToAllHosts()); | 210 EXPECT_TRUE(extension->permissions_data()->HasEffectiveAccessToAllHosts()); |
211 | 211 |
212 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 212 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
213 hosts = extension->permissions_data()->GetEffectiveHostPermissions(); | 213 hosts = extension->permissions_data()->GetEffectiveHostPermissions(); |
214 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); | 214 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); |
215 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); | 215 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); |
216 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 216 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
217 EXPECT_TRUE(extension->permissions_data()->HasEffectiveAccessToAllHosts()); | 217 EXPECT_TRUE(extension->permissions_data()->HasEffectiveAccessToAllHosts()); |
| 218 |
| 219 // Tab-specific permissions should be included in the effective hosts. |
| 220 GURL tab_url("http://www.example.com/"); |
| 221 URLPatternSet new_hosts; |
| 222 new_hosts.AddOrigin(URLPattern::SCHEME_ALL, tab_url); |
| 223 extension->permissions_data()->UpdateTabSpecificPermissions( |
| 224 1, |
| 225 new PermissionSet(APIPermissionSet(), |
| 226 ManifestPermissionSet(), |
| 227 new_hosts, |
| 228 URLPatternSet())); |
| 229 EXPECT_TRUE(extension->permissions_data()->GetEffectiveHostPermissions(). |
| 230 MatchesURL(tab_url)); |
| 231 extension->permissions_data()->ClearTabSpecificPermissions(1); |
| 232 EXPECT_FALSE(extension->permissions_data()->GetEffectiveHostPermissions(). |
| 233 MatchesURL(tab_url)); |
218 } | 234 } |
219 | 235 |
220 TEST(PermissionsDataTest, SocketPermissions) { | 236 TEST(PermissionsDataTest, SocketPermissions) { |
221 scoped_refptr<Extension> extension; | 237 scoped_refptr<Extension> extension; |
222 std::string error; | 238 std::string error; |
223 | 239 |
224 extension = LoadManifest("socket_permissions", "empty.json"); | 240 extension = LoadManifest("socket_permissions", "empty.json"); |
225 EXPECT_FALSE(CheckSocketPermission(extension, | 241 EXPECT_FALSE(CheckSocketPermission(extension, |
226 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 242 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
227 | 243 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 760 |
745 permissions_data->ClearTabSpecificPermissions(1); | 761 permissions_data->ClearTabSpecificPermissions(1); |
746 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1).get()); | 762 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1).get()); |
747 | 763 |
748 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 764 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
749 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 765 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
750 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 766 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
751 } | 767 } |
752 | 768 |
753 } // namespace extensions | 769 } // namespace extensions |
OLD | NEW |