OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 7 #include <set> |
| 8 #include <string> |
8 | 9 |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
11 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
12 #include "extensions/common/file_util.h" | 13 #include "extensions/common/file_util.h" |
13 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
(...skipping 13 matching lines...) Expand all Loading... |
31 install_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); | 32 install_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
32 ASSERT_TRUE(extension.get()); | 33 ASSERT_TRUE(extension.get()); |
33 | 34 |
34 // The extension contains one icon. | 35 // The extension contains one icon. |
35 std::set<base::FilePath> paths = | 36 std::set<base::FilePath> paths = |
36 extension_file_util::GetBrowserImagePaths(extension.get()); | 37 extension_file_util::GetBrowserImagePaths(extension.get()); |
37 ASSERT_EQ(1u, paths.size()); | 38 ASSERT_EQ(1u, paths.size()); |
38 EXPECT_EQ("icon.png", paths.begin()->BaseName().AsUTF8Unsafe()); | 39 EXPECT_EQ("icon.png", paths.begin()->BaseName().AsUTF8Unsafe()); |
39 } | 40 } |
40 | 41 |
| 42 // Test that extensions with zero-length action icons will not load. |
| 43 TEST_F(ExtensionFileUtilTest, CheckZeroLengthActionIconFiles) { |
| 44 base::FilePath install_dir; |
| 45 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 46 |
| 47 // Try to install an extension with a zero-length browser action icon file. |
| 48 base::FilePath ext_dir = install_dir.AppendASCII("extensions") |
| 49 .AppendASCII("bad") |
| 50 .AppendASCII("Extensions") |
| 51 .AppendASCII("gggggggggggggggggggggggggggggggg"); |
| 52 |
| 53 std::string error; |
| 54 scoped_refptr<Extension> extension2(file_util::LoadExtension( |
| 55 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
| 56 EXPECT_FALSE(extension2.get()); |
| 57 EXPECT_STREQ("Could not load icon 'icon.png' for browser action.", |
| 58 error.c_str()); |
| 59 |
| 60 // Try to install an extension with a zero-length page action icon file. |
| 61 ext_dir = install_dir.AppendASCII("extensions") |
| 62 .AppendASCII("bad") |
| 63 .AppendASCII("Extensions") |
| 64 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); |
| 65 |
| 66 scoped_refptr<Extension> extension3(file_util::LoadExtension( |
| 67 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
| 68 EXPECT_FALSE(extension3.get()); |
| 69 EXPECT_STREQ("Could not load icon 'icon.png' for page action.", |
| 70 error.c_str()); |
| 71 } |
| 72 |
41 } // namespace extensions | 73 } // namespace extensions |
OLD | NEW |