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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/strings/pattern.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
12 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_paths.h" | 14 #include "extensions/common/extension_paths.h" |
14 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
15 #include "extensions/test/test_extensions_client.h" | 16 #include "extensions/test/test_extensions_client.h" |
16 #include "extensions/utility/unpacker.h" | 17 #include "extensions/utility/unpacker.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 TEST_F(UnpackerTest, InvalidDefaultLocale) { | 74 TEST_F(UnpackerTest, InvalidDefaultLocale) { |
74 SetupUnpacker("invalid_default_locale.crx"); | 75 SetupUnpacker("invalid_default_locale.crx"); |
75 EXPECT_FALSE(unpacker_->Run()); | 76 EXPECT_FALSE(unpacker_->Run()); |
76 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), | 77 EXPECT_EQ(ASCIIToUTF16(errors::kInvalidDefaultLocale), |
77 unpacker_->error_message()); | 78 unpacker_->error_message()); |
78 } | 79 } |
79 | 80 |
80 TEST_F(UnpackerTest, InvalidMessagesFile) { | 81 TEST_F(UnpackerTest, InvalidMessagesFile) { |
81 SetupUnpacker("invalid_messages_file.crx"); | 82 SetupUnpacker("invalid_messages_file.crx"); |
82 EXPECT_FALSE(unpacker_->Run()); | 83 EXPECT_FALSE(unpacker_->Run()); |
83 EXPECT_TRUE( | 84 EXPECT_TRUE(base::MatchPattern( |
84 MatchPattern(unpacker_->error_message(), | 85 unpacker_->error_message(), |
85 ASCIIToUTF16( | 86 ASCIIToUTF16( |
86 "*_locales?en_US?messages.json: Line: 2, column: 11," | 87 "*_locales?en_US?messages.json: Line: 2, column: 11," |
87 " Syntax error."))) | 88 " Syntax error."))) |
88 << unpacker_->error_message(); | 89 << unpacker_->error_message(); |
89 } | 90 } |
90 | 91 |
91 TEST_F(UnpackerTest, MissingDefaultData) { | 92 TEST_F(UnpackerTest, MissingDefaultData) { |
92 SetupUnpacker("missing_default_data.crx"); | 93 SetupUnpacker("missing_default_data.crx"); |
93 EXPECT_FALSE(unpacker_->Run()); | 94 EXPECT_FALSE(unpacker_->Run()); |
94 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), | 95 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
95 unpacker_->error_message()); | 96 unpacker_->error_message()); |
96 } | 97 } |
97 | 98 |
98 TEST_F(UnpackerTest, MissingDefaultLocaleHasLocalesFolder) { | 99 TEST_F(UnpackerTest, MissingDefaultLocaleHasLocalesFolder) { |
99 SetupUnpacker("missing_default_has_locales.crx"); | 100 SetupUnpacker("missing_default_has_locales.crx"); |
100 EXPECT_FALSE(unpacker_->Run()); | 101 EXPECT_FALSE(unpacker_->Run()); |
101 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), | 102 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultLocaleSpecified), |
102 unpacker_->error_message()); | 103 unpacker_->error_message()); |
103 } | 104 } |
104 | 105 |
105 TEST_F(UnpackerTest, MissingMessagesFile) { | 106 TEST_F(UnpackerTest, MissingMessagesFile) { |
106 SetupUnpacker("missing_messages_file.crx"); | 107 SetupUnpacker("missing_messages_file.crx"); |
107 EXPECT_FALSE(unpacker_->Run()); | 108 EXPECT_FALSE(unpacker_->Run()); |
108 EXPECT_TRUE(MatchPattern(unpacker_->error_message(), | 109 EXPECT_TRUE( |
109 ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + | 110 base::MatchPattern(unpacker_->error_message(), |
110 ASCIIToUTF16("*_locales?en_US?messages.json"))); | 111 ASCIIToUTF16(errors::kLocalesMessagesFileMissing) + |
| 112 ASCIIToUTF16("*_locales?en_US?messages.json"))); |
111 } | 113 } |
112 | 114 |
113 TEST_F(UnpackerTest, NoLocaleData) { | 115 TEST_F(UnpackerTest, NoLocaleData) { |
114 SetupUnpacker("no_locale_data.crx"); | 116 SetupUnpacker("no_locale_data.crx"); |
115 EXPECT_FALSE(unpacker_->Run()); | 117 EXPECT_FALSE(unpacker_->Run()); |
116 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), | 118 EXPECT_EQ(ASCIIToUTF16(errors::kLocalesNoDefaultMessages), |
117 unpacker_->error_message()); | 119 unpacker_->error_message()); |
118 } | 120 } |
119 | 121 |
120 TEST_F(UnpackerTest, GoodL10n) { | 122 TEST_F(UnpackerTest, GoodL10n) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 const char kExpected[] = "Could not decode image: "; | 180 const char kExpected[] = "Could not decode image: "; |
179 SetupUnpacker("bad_image.crx"); | 181 SetupUnpacker("bad_image.crx"); |
180 EXPECT_FALSE(unpacker_->Run()); | 182 EXPECT_FALSE(unpacker_->Run()); |
181 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), | 183 EXPECT_TRUE(base::StartsWith(unpacker_->error_message(), |
182 ASCIIToUTF16(kExpected), false)) | 184 ASCIIToUTF16(kExpected), false)) |
183 << "Expected prefix: \"" << kExpected << "\", actual error: \"" | 185 << "Expected prefix: \"" << kExpected << "\", actual error: \"" |
184 << unpacker_->error_message() << "\""; | 186 << unpacker_->error_message() << "\""; |
185 } | 187 } |
186 | 188 |
187 } // namespace extensions | 189 } // namespace extensions |
OLD | NEW |