| OLD | NEW |
| 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_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_value_serializer.h" | 8 #include "base/json/json_value_serializer.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace keys = extension_manifest_keys; | 18 namespace keys = extension_manifest_keys; |
| 19 | 19 |
| 20 #if defined(OS_WIN) |
| 20 // http://crbug.com/106381 | 21 // http://crbug.com/106381 |
| 21 TEST(ExtensionFileUtil, DISABLED_InstallUninstallGarbageCollect) { | 22 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect |
| 23 #endif |
| 24 TEST(ExtensionFileUtil, InstallUninstallGarbageCollect) { |
| 22 ScopedTempDir temp; | 25 ScopedTempDir temp; |
| 23 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 26 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 24 | 27 |
| 25 // Create a source extension. | 28 // Create a source extension. |
| 26 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 29 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 27 std::string version("1.0"); | 30 std::string version("1.0"); |
| 28 FilePath src = temp.path().AppendASCII(extension_id); | 31 FilePath src = temp.path().AppendASCII(extension_id); |
| 29 ASSERT_TRUE(file_util::CreateDirectory(src)); | 32 ASSERT_TRUE(file_util::CreateDirectory(src)); |
| 30 | 33 |
| 31 // Create a extensions tree. | 34 // Create a extensions tree. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 99 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
| 97 .AppendASCII("1.0"); | 100 .AppendASCII("1.0"); |
| 98 | 101 |
| 99 std::string error; | 102 std::string error; |
| 100 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 103 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
| 101 install_dir, Extension::LOAD, Extension::STRICT_ERROR_CHECKS, &error)); | 104 install_dir, Extension::LOAD, Extension::STRICT_ERROR_CHECKS, &error)); |
| 102 ASSERT_FALSE(extension == NULL); | 105 ASSERT_FALSE(extension == NULL); |
| 103 EXPECT_TRUE(error.empty()); | 106 EXPECT_TRUE(error.empty()); |
| 104 } | 107 } |
| 105 | 108 |
| 109 #if defined(OS_WIN) |
| 110 // http://crbug.com/106381 |
| 111 #define CheckIllegalFilenamesNoUnderscores \ |
| 112 DISABLED_CheckIllegalFilenamesNoUnderscores |
| 113 #endif |
| 106 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { | 114 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { |
| 107 ScopedTempDir temp; | 115 ScopedTempDir temp; |
| 108 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 116 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 109 | 117 |
| 110 FilePath src_path = temp.path().AppendASCII("some_dir"); | 118 FilePath src_path = temp.path().AppendASCII("some_dir"); |
| 111 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 119 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 112 | 120 |
| 113 std::string data = "{ \"name\": { \"message\": \"foobar\" } }"; | 121 std::string data = "{ \"name\": { \"message\": \"foobar\" } }"; |
| 114 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"), | 122 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"), |
| 115 data.c_str(), data.length())); | 123 data.c_str(), data.length())); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 kManifest, temp.path(), Extension::LOAD, 0, &error); | 286 kManifest, temp.path(), Extension::LOAD, 0, &error); |
| 279 ASSERT_TRUE(extension.get()) << error; | 287 ASSERT_TRUE(extension.get()) << error; |
| 280 | 288 |
| 281 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, &error)) << | 289 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, &error)) << |
| 282 error; | 290 error; |
| 283 } | 291 } |
| 284 | 292 |
| 285 // TODO(aa): More tests as motivation allows. Maybe steal some from | 293 // TODO(aa): More tests as motivation allows. Maybe steal some from |
| 286 // ExtensionService? Many of them could probably be tested here without the | 294 // ExtensionService? Many of them could probably be tested here without the |
| 287 // MessageLoop shenanigans. | 295 // MessageLoop shenanigans. |
| OLD | NEW |