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