| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 using extensions::ExtensionBuilder; | 32 using extensions::ExtensionBuilder; |
| 33 using extensions::ListBuilder; | 33 using extensions::ListBuilder; |
| 34 | 34 |
| 35 class ContentCapabilitiesTest : public ExtensionApiTest { | 35 class ContentCapabilitiesTest : public ExtensionApiTest { |
| 36 protected: | 36 protected: |
| 37 void SetUpCommandLine(base::CommandLine* command_line) override { | 37 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 38 ExtensionApiTest::SetUpCommandLine(command_line); | 38 ExtensionApiTest::SetUpCommandLine(command_line); |
| 39 command_line->AppendSwitchASCII( | 39 command_line->AppendSwitchASCII( |
| 40 extensions::switches::kWhitelistedExtensionID, | 40 extensions::switches::kWhitelistedExtensionID, |
| 41 crx_file::id_util::GenerateIdForPath( | 41 crx_file::id_util::GenerateIdForPath( |
| 42 base::MakeAbsoluteFilePath(test_extension_dir_.unpacked_path()))); | 42 base::MakeAbsoluteFilePath(test_extension_dir_.UnpackedPath()))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Builds an extension manifest with the given content_capabilities matches | 45 // Builds an extension manifest with the given content_capabilities matches |
| 46 // and permissions. The extension always has the same (whitelisted) ID. | 46 // and permissions. The extension always has the same (whitelisted) ID. |
| 47 scoped_refptr<const Extension> LoadExtensionWithCapabilities( | 47 scoped_refptr<const Extension> LoadExtensionWithCapabilities( |
| 48 const std::string& matches, | 48 const std::string& matches, |
| 49 const std::string& permissions, | 49 const std::string& permissions, |
| 50 const std::string& extension_permissions = "[]") { | 50 const std::string& extension_permissions = "[]") { |
| 51 std::string manifest = base::StringPrintf( | 51 std::string manifest = base::StringPrintf( |
| 52 "{\n" | 52 "{\n" |
| 53 " \"name\": \"content_capabilities test extensions\",\n" | 53 " \"name\": \"content_capabilities test extensions\",\n" |
| 54 " \"version\": \"1\",\n" | 54 " \"version\": \"1\",\n" |
| 55 " \"manifest_version\": 2,\n" | 55 " \"manifest_version\": 2,\n" |
| 56 " \"content_capabilities\": {\n" | 56 " \"content_capabilities\": {\n" |
| 57 " \"matches\": %s,\n" | 57 " \"matches\": %s,\n" |
| 58 " \"permissions\": %s\n" | 58 " \"permissions\": %s\n" |
| 59 " },\n" | 59 " },\n" |
| 60 " \"permissions\": %s\n" | 60 " \"permissions\": %s\n" |
| 61 "}\n", | 61 "}\n", |
| 62 matches.c_str(), permissions.c_str(), extension_permissions.c_str()); | 62 matches.c_str(), permissions.c_str(), extension_permissions.c_str()); |
| 63 test_extension_dir_.WriteManifest(manifest); | 63 test_extension_dir_.WriteManifest(manifest); |
| 64 return LoadExtension(test_extension_dir_.unpacked_path()); | 64 return LoadExtension(test_extension_dir_.UnpackedPath()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 std::string MakeJSONList(const std::string& s0 = "", | 67 std::string MakeJSONList(const std::string& s0 = "", |
| 68 const std::string& s1 = "", | 68 const std::string& s1 = "", |
| 69 const std::string& s2 = "") { | 69 const std::string& s2 = "") { |
| 70 std::vector<std::string> v; | 70 std::vector<std::string> v; |
| 71 if (!s0.empty()) | 71 if (!s0.empty()) |
| 72 v.push_back(s0); | 72 v.push_back(s0); |
| 73 if (!s1.empty()) | 73 if (!s1.empty()) |
| 74 v.push_back(s1); | 74 v.push_back(s1); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // This extension has unlimitedStorage but doesn't grant it to foo.example.com | 256 // This extension has unlimitedStorage but doesn't grant it to foo.example.com |
| 257 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( | 257 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( |
| 258 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead"), | 258 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead"), |
| 259 MakeJSONList("unlimitedStorage")); | 259 MakeJSONList("unlimitedStorage")); |
| 260 | 260 |
| 261 EXPECT_TRUE( | 261 EXPECT_TRUE( |
| 262 HasUnlimitedStorage(extension.get(), extension->GetResourceURL(""))); | 262 HasUnlimitedStorage(extension.get(), extension->GetResourceURL(""))); |
| 263 EXPECT_FALSE( | 263 EXPECT_FALSE( |
| 264 HasUnlimitedStorage(extension.get(), GetTestURLFor("foo.example.com"))); | 264 HasUnlimitedStorage(extension.get(), GetTestURLFor("foo.example.com"))); |
| 265 } | 265 } |
| OLD | NEW |