Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/common/extensions/extension_unpacker_unittest.cc

Issue 390019: Parse messages.json in ExtensionUnpacker (like we do for manifest).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_util.h"
6 #include "base/path_service.h"
7 #include "base/string_util.h"
8 #include "base/values.h"
9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension_constants.h"
11 #include "chrome/common/extensions/extension_unpacker.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14
15 namespace errors = extension_manifest_errors;
16 namespace keys = extension_manifest_keys;
17
18 class ExtensionUnpackerTest : public testing::Test {
19 public:
20 void SetupUnpacker(const std::string& crx_name) {
21 FilePath original_path;
22 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
23 original_path = original_path.AppendASCII("extensions")
24 .AppendASCII("unpacker")
25 .AppendASCII(crx_name);
26 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value();
27
28 // Try bots won't let us write into DIR_TEST_DATA, so we have to create
29 // a temp folder to play in.
30 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &install_dir_));
31 install_dir_ = install_dir_.AppendASCII("extension_unpacker_test");
32 ASSERT_TRUE(file_util::Delete(install_dir_, true)) <<
33 install_dir_.value();
34 ASSERT_TRUE(file_util::CreateDirectory(install_dir_)) <<
35 install_dir_.value();
36
37 FilePath crx_path = install_dir_.AppendASCII(crx_name);
38 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) <<
39 "Original path " << original_path.value() <<
40 ", Crx path " << crx_path.value();
41
42 unpacker_.reset(new ExtensionUnpacker(crx_path));
43 }
44
45 virtual void TearDown() {
46 ASSERT_TRUE(file_util::Delete(install_dir_, true)) <<
47 install_dir_.value();
48 }
49
50 protected:
51 FilePath install_dir_;
52 scoped_ptr<ExtensionUnpacker> unpacker_;
53 };
54
55 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) {
56 SetupUnpacker("empty_default_locale.crx");
57 EXPECT_FALSE(unpacker_->Run());
58 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message());
59 }
60
61 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) {
62 SetupUnpacker("has_default_missing_locales.crx");
63 EXPECT_FALSE(unpacker_->Run());
64 EXPECT_EQ(errors::kLocalesTreeMissing, unpacker_->error_message());
65 }
66
67 TEST_F(ExtensionUnpackerTest, InvalidDefaultLocale) {
68 SetupUnpacker("invalid_default_locale.crx");
69 EXPECT_FALSE(unpacker_->Run());
70 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message());
71 }
72
73 TEST_F(ExtensionUnpackerTest, InvalidMessagesFile) {
74 SetupUnpacker("invalid_messages_file.crx");
75 EXPECT_FALSE(unpacker_->Run());
76 EXPECT_TRUE(MatchPattern(unpacker_->error_message(),
77 std::string("*_locales?en_US?messages.json: Line: 2, column: 3,"
78 " Dictionary keys must be quoted.")));
79 }
80
81 TEST_F(ExtensionUnpackerTest, MissingDefaultData) {
82 SetupUnpacker("missing_default_data.crx");
83 EXPECT_FALSE(unpacker_->Run());
84 EXPECT_EQ(errors::kLocalesNoDefaultMessages, unpacker_->error_message());
85 }
86
87 TEST_F(ExtensionUnpackerTest, MissingDefaultLocaleHasLocalesFolder) {
88 SetupUnpacker("missing_default_has_locales.crx");
89 EXPECT_FALSE(unpacker_->Run());
90 EXPECT_EQ(errors::kLocalesNoDefaultLocaleSpecified,
91 unpacker_->error_message());
92 }
93
94 TEST_F(ExtensionUnpackerTest, MissingMessagesFile) {
95 SetupUnpacker("missing_messages_file.crx");
96 EXPECT_FALSE(unpacker_->Run());
97 EXPECT_TRUE(MatchPattern(unpacker_->error_message(),
98 errors::kLocalesMessagesFileMissing +
99 std::string("*_locales?en_US?messages.json")));
100 }
101
102 TEST_F(ExtensionUnpackerTest, NoLocaleData) {
103 SetupUnpacker("no_locale_data.crx");
104 EXPECT_FALSE(unpacker_->Run());
105 EXPECT_EQ(errors::kLocalesTreeMissing, unpacker_->error_message());
106 }
107
108 TEST_F(ExtensionUnpackerTest, GoodL10n) {
109 SetupUnpacker("good_l10n.crx");
110 EXPECT_TRUE(unpacker_->Run());
111 EXPECT_TRUE(unpacker_->error_message().empty());
112 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->GetSize());
113 }
114
115 TEST_F(ExtensionUnpackerTest, NoL10n) {
116 SetupUnpacker("no_l10n.crx");
117 EXPECT_TRUE(unpacker_->Run());
118 EXPECT_TRUE(unpacker_->error_message().empty());
119 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->GetSize());
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698