| Index: chrome/common/extensions/extension_file_util_unittest.cc
|
| diff --git a/chrome/common/extensions/extension_file_util_unittest.cc b/chrome/common/extensions/extension_file_util_unittest.cc
|
| index e2d10664a4cfed13f42c1449b1f8f0ea4a760224..eef0a63f8c0f3e03a6cbef04420154f411f8dc0e 100644
|
| --- a/chrome/common/extensions/extension_file_util_unittest.cc
|
| +++ b/chrome/common/extensions/extension_file_util_unittest.cc
|
| @@ -215,9 +215,8 @@ TEST(ExtensionFileUtil, FailLoadingNonUTF8Scripts) {
|
| "It isn't UTF-8 encoded.", error.c_str());
|
| }
|
|
|
| -#define URL_PREFIX "chrome-extension://extension-id/"
|
| -
|
| TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
|
| +#define URL_PREFIX "chrome-extension://extension-id/"
|
| struct TestCase {
|
| const char* url;
|
| const char* expected_relative_path;
|
| @@ -243,6 +242,7 @@ TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
|
| { URL_PREFIX "\\\\foo\\simple.html",
|
| "foo/simple.html" },
|
| };
|
| +#undef URL_PREFIX
|
|
|
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
|
| GURL url(test_cases[i].url);
|
| @@ -261,6 +261,72 @@ TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
|
| }
|
| }
|
|
|
| +TEST(ExtensionFileUtil, ExtensionResourceURLToFilePath) {
|
| + // Setup filesystem for testing.
|
| + FilePath root_path;
|
| + ASSERT_TRUE(file_util::CreateNewTempDirectory(
|
| + FILE_PATH_LITERAL(""), &root_path));
|
| + ASSERT_TRUE(file_util::AbsolutePath(&root_path));
|
| +
|
| + FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname"));
|
| + ASSERT_TRUE(file_util::CreateDirectory(api_path));
|
| +
|
| + const char data[] = "Test Data";
|
| + FilePath resource_path = api_path.Append(FILE_PATH_LITERAL("test.js"));
|
| + ASSERT_TRUE(file_util::WriteFile(resource_path, data, sizeof(data)));
|
| + resource_path = api_path.Append(FILE_PATH_LITERAL("escape spaces.js"));
|
| + ASSERT_TRUE(file_util::WriteFile(resource_path, data, sizeof(data)));
|
| +
|
| +#ifdef FILE_PATH_USES_WIN_SEPARATORS
|
| +#define SEP "\\"
|
| +#else
|
| +#define SEP "/"
|
| +#endif
|
| +#define URL_PREFIX "chrome-extension-resource://"
|
| + struct TestCase {
|
| + const char* url;
|
| + const FilePath::CharType* expected_path;
|
| + } test_cases[] = {
|
| + { URL_PREFIX "apiname/test.js",
|
| + FILE_PATH_LITERAL("test.js") },
|
| + { URL_PREFIX "/apiname/test.js",
|
| + FILE_PATH_LITERAL("test.js") },
|
| + // Test % escape
|
| + { URL_PREFIX "apiname/%74%65st.js",
|
| + FILE_PATH_LITERAL("test.js") },
|
| + { URL_PREFIX "apiname/escape%20spaces.js",
|
| + FILE_PATH_LITERAL("escape spaces.js") },
|
| + // Test file does not exist.
|
| + { URL_PREFIX "apiname/directory/to/file.js",
|
| + NULL },
|
| + // Test apiname/../../test.js
|
| + { URL_PREFIX "apiname/../../test.js",
|
| + FILE_PATH_LITERAL("test.js") },
|
| + { URL_PREFIX "apiname/..%2F../test.js",
|
| + NULL },
|
| + { URL_PREFIX "apiname/f/../../../test.js",
|
| + FILE_PATH_LITERAL("test.js") },
|
| + { URL_PREFIX "apiname/f%2F..%2F..%2F../test.js",
|
| + NULL },
|
| + };
|
| +#undef SEP
|
| +#undef URL_PREFIX
|
| +
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
|
| + GURL url(test_cases[i].url);
|
| + FilePath expected_path;
|
| + if (test_cases[i].expected_path)
|
| + expected_path = root_path.Append(FILE_PATH_LITERAL("apiname")).Append(
|
| + test_cases[i].expected_path);
|
| + FilePath actual_path =
|
| + extension_file_util::ExtensionResourceURLToFilePath(url, root_path);
|
| + EXPECT_EQ(expected_path.value(), actual_path.value()) <<
|
| + " For the path " << url;
|
| + }
|
| + // Remove temp files.
|
| + ASSERT_TRUE(file_util::Delete(root_path, true));
|
| +}
|
| +
|
| static scoped_refptr<Extension> LoadExtensionManifest(
|
| DictionaryValue* manifest,
|
| const FilePath& manifest_dir,
|
|
|