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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
11 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
12 #include "chrome/common/extensions/extension_unpacker.h" | 13 #include "chrome/common/extensions/extension_unpacker.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
15 | 16 |
16 namespace errors = extension_manifest_errors; | 17 namespace errors = extension_manifest_errors; |
17 namespace keys = extension_manifest_keys; | 18 namespace keys = extension_manifest_keys; |
18 | 19 |
(...skipping 22 matching lines...) Expand all Loading... |
41 } | 42 } |
42 | 43 |
43 protected: | 44 protected: |
44 ScopedTempDir temp_dir_; | 45 ScopedTempDir temp_dir_; |
45 scoped_ptr<ExtensionUnpacker> unpacker_; | 46 scoped_ptr<ExtensionUnpacker> unpacker_; |
46 }; | 47 }; |
47 | 48 |
48 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) { | 49 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) { |
49 SetupUnpacker("empty_default_locale.crx"); | 50 SetupUnpacker("empty_default_locale.crx"); |
50 EXPECT_FALSE(unpacker_->Run()); | 51 EXPECT_FALSE(unpacker_->Run()); |
51 EXPECT_EQ(std::string(errors::kInvalidDefaultLocale), | 52 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), |
52 unpacker_->error_message()); | 53 unpacker_->error_message()); |
53 } | 54 } |
54 | 55 |
55 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) { | 56 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) { |
56 SetupUnpacker("has_default_missing_locales.crx"); | 57 SetupUnpacker("has_default_missing_locales.crx"); |
57 EXPECT_FALSE(unpacker_->Run()); | 58 EXPECT_FALSE(unpacker_->Run()); |
58 EXPECT_EQ(std::string(errors::kLocalesTreeMissing), | 59 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesTreeMissing), |
59 unpacker_->error_message()); | 60 unpacker_->error_message()); |
60 } | 61 } |
61 | 62 |
62 TEST_F(ExtensionUnpackerTest, InvalidDefaultLocale) { | 63 TEST_F(ExtensionUnpackerTest, InvalidDefaultLocale) { |
63 SetupUnpacker("invalid_default_locale.crx"); | 64 SetupUnpacker("invalid_default_locale.crx"); |
64 EXPECT_FALSE(unpacker_->Run()); | 65 EXPECT_FALSE(unpacker_->Run()); |
65 EXPECT_EQ(std::string(errors::kInvalidDefaultLocale), | 66 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), |
66 unpacker_->error_message()); | 67 unpacker_->error_message()); |
67 } | 68 } |
68 | 69 |
69 TEST_F(ExtensionUnpackerTest, InvalidMessagesFile) { | 70 TEST_F(ExtensionUnpackerTest, InvalidMessagesFile) { |
70 SetupUnpacker("invalid_messages_file.crx"); | 71 SetupUnpacker("invalid_messages_file.crx"); |
71 EXPECT_FALSE(unpacker_->Run()); | 72 EXPECT_FALSE(unpacker_->Run()); |
72 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), | 73 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), |
73 std::string("*_locales?en_US?messages.json: Line: 2, column: 3," | 74 ASCIIToUTF16("*_locales?en_US?messages.json: Line: 2, column: 3," |
74 " Dictionary keys must be quoted."))); | 75 " Dictionary keys must be quoted."))); |
75 } | 76 } |
76 | 77 |
77 TEST_F(ExtensionUnpackerTest, MissingDefaultData) { | 78 TEST_F(ExtensionUnpackerTest, MissingDefaultData) { |
78 SetupUnpacker("missing_default_data.crx"); | 79 SetupUnpacker("missing_default_data.crx"); |
79 EXPECT_FALSE(unpacker_->Run()); | 80 EXPECT_FALSE(unpacker_->Run()); |
80 EXPECT_EQ(std::string(errors::kLocalesNoDefaultMessages), | 81 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
81 unpacker_->error_message()); | 82 unpacker_->error_message()); |
82 } | 83 } |
83 | 84 |
84 TEST_F(ExtensionUnpackerTest, MissingDefaultLocaleHasLocalesFolder) { | 85 TEST_F(ExtensionUnpackerTest, MissingDefaultLocaleHasLocalesFolder) { |
85 SetupUnpacker("missing_default_has_locales.crx"); | 86 SetupUnpacker("missing_default_has_locales.crx"); |
86 EXPECT_FALSE(unpacker_->Run()); | 87 EXPECT_FALSE(unpacker_->Run()); |
87 EXPECT_EQ(std::string(errors::kLocalesNoDefaultLocaleSpecified), | 88 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), |
88 unpacker_->error_message()); | 89 unpacker_->error_message()); |
89 } | 90 } |
90 | 91 |
91 TEST_F(ExtensionUnpackerTest, MissingMessagesFile) { | 92 TEST_F(ExtensionUnpackerTest, MissingMessagesFile) { |
92 SetupUnpacker("missing_messages_file.crx"); | 93 SetupUnpacker("missing_messages_file.crx"); |
93 EXPECT_FALSE(unpacker_->Run()); | 94 EXPECT_FALSE(unpacker_->Run()); |
94 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), | 95 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), |
95 errors::kLocalesMessagesFileMissing + | 96 ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + |
96 std::string("*_locales?en_US?messages.json"))); | 97 ASCIIToUTF16("*_locales?en_US?messages.json"))); |
97 } | 98 } |
98 | 99 |
99 TEST_F(ExtensionUnpackerTest, NoLocaleData) { | 100 TEST_F(ExtensionUnpackerTest, NoLocaleData) { |
100 SetupUnpacker("no_locale_data.crx"); | 101 SetupUnpacker("no_locale_data.crx"); |
101 EXPECT_FALSE(unpacker_->Run()); | 102 EXPECT_FALSE(unpacker_->Run()); |
102 EXPECT_EQ(std::string(errors::kLocalesNoDefaultMessages), | 103 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
103 unpacker_->error_message()); | 104 unpacker_->error_message()); |
104 } | 105 } |
105 | 106 |
106 TEST_F(ExtensionUnpackerTest, GoodL10n) { | 107 TEST_F(ExtensionUnpackerTest, GoodL10n) { |
107 SetupUnpacker("good_l10n.crx"); | 108 SetupUnpacker("good_l10n.crx"); |
108 EXPECT_TRUE(unpacker_->Run()); | 109 EXPECT_TRUE(unpacker_->Run()); |
109 EXPECT_TRUE(unpacker_->error_message().empty()); | 110 EXPECT_TRUE(unpacker_->error_message().empty()); |
110 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); | 111 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); |
111 } | 112 } |
112 | 113 |
113 TEST_F(ExtensionUnpackerTest, NoL10n) { | 114 TEST_F(ExtensionUnpackerTest, NoL10n) { |
114 SetupUnpacker("no_l10n.crx"); | 115 SetupUnpacker("no_l10n.crx"); |
115 EXPECT_TRUE(unpacker_->Run()); | 116 EXPECT_TRUE(unpacker_->Run()); |
116 EXPECT_TRUE(unpacker_->error_message().empty()); | 117 EXPECT_TRUE(unpacker_->error_message().empty()); |
117 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); | 118 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); |
118 } | 119 } |
OLD | NEW |