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

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

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: About a third of the way done. Created 9 years, 8 months 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
OLDNEW
1 // Copyright (c) 2010 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/string_util.h" 7 #include "base/string_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "base/memory/scoped_temp_dir.h"
9 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension_constants.h" 11 #include "chrome/common/extensions/extension_constants.h"
11 #include "chrome/common/extensions/extension_unpacker.h" 12 #include "chrome/common/extensions/extension_unpacker.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
14 15
15 namespace errors = extension_manifest_errors; 16 namespace errors = extension_manifest_errors;
16 namespace keys = extension_manifest_keys; 17 namespace keys = extension_manifest_keys;
17 18
18 class ExtensionUnpackerTest : public testing::Test { 19 class ExtensionUnpackerTest : public testing::Test {
19 public: 20 public:
20 void SetupUnpacker(const std::string& crx_name) { 21 void SetupUnpacker(const std::string& crx_name) {
21 FilePath original_path; 22 FilePath original_path;
22 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); 23 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
23 original_path = original_path.AppendASCII("extensions") 24 original_path = original_path.AppendASCII("extensions")
24 .AppendASCII("unpacker") 25 .AppendASCII("unpacker")
25 .AppendASCII(crx_name); 26 .AppendASCII(crx_name);
26 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); 27 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value();
27 28
28 // Try bots won't let us write into DIR_TEST_DATA, so we have to create 29 // Try bots won't let us write into DIR_TEST_DATA, so we have to create
29 // a temp folder to play in. 30 // a temp folder to play in.
30 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &install_dir_)); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
31 install_dir_ = install_dir_.AppendASCII("extension_unpacker_test");
32 file_util::Delete(install_dir_, true);
33 file_util::CreateDirectory(install_dir_);
34 32
35 FilePath crx_path = install_dir_.AppendASCII(crx_name); 33 FilePath crx_path = temp_dir_.path().AppendASCII(crx_name);
36 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) << 34 ASSERT_TRUE(file_util::CopyFile(original_path, crx_path)) <<
37 "Original path " << original_path.value() << 35 "Original path " << original_path.value() <<
38 ", Crx path " << crx_path.value(); 36 ", Crx path " << crx_path.value();
39 37
40 unpacker_.reset(new ExtensionUnpacker(crx_path)); 38 unpacker_.reset(new ExtensionUnpacker(crx_path));
41 } 39 }
42 40
43 virtual void TearDown() { 41 virtual void TearDown() {
Paweł Hajdan Jr. 2011/04/08 15:58:17 An empty TearDown can be removed.
Mike West 2011/04/11 14:47:04 Done.
44 ASSERT_TRUE(file_util::Delete(install_dir_, true)) <<
45 install_dir_.value();
46 } 42 }
47 43
48 protected: 44 protected:
49 FilePath install_dir_; 45 ScopedTempDir temp_dir_;
50 scoped_ptr<ExtensionUnpacker> unpacker_; 46 scoped_ptr<ExtensionUnpacker> unpacker_;
51 }; 47 };
52 48
53 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) { 49 TEST_F(ExtensionUnpackerTest, EmptyDefaultLocale) {
54 SetupUnpacker("empty_default_locale.crx"); 50 SetupUnpacker("empty_default_locale.crx");
55 EXPECT_FALSE(unpacker_->Run()); 51 EXPECT_FALSE(unpacker_->Run());
56 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message()); 52 EXPECT_EQ(errors::kInvalidDefaultLocale, unpacker_->error_message());
57 } 53 }
58 54
59 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) { 55 TEST_F(ExtensionUnpackerTest, HasDefaultLocaleMissingLocalesFolder) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 EXPECT_TRUE(unpacker_->error_message().empty()); 105 EXPECT_TRUE(unpacker_->error_message().empty());
110 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size()); 106 ASSERT_EQ(2U, unpacker_->parsed_catalogs()->size());
111 } 107 }
112 108
113 TEST_F(ExtensionUnpackerTest, NoL10n) { 109 TEST_F(ExtensionUnpackerTest, NoL10n) {
114 SetupUnpacker("no_l10n.crx"); 110 SetupUnpacker("no_l10n.crx");
115 EXPECT_TRUE(unpacker_->Run()); 111 EXPECT_TRUE(unpacker_->Run());
116 EXPECT_TRUE(unpacker_->error_message().empty()); 112 EXPECT_TRUE(unpacker_->error_message().empty());
117 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size()); 113 EXPECT_EQ(0U, unpacker_->parsed_catalogs()->size());
118 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698