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

Side by Side Diff: components/zip/zip_reader_unittest.cc

Issue 13257004: [components] Make zip a component so that src/chromeos can use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DEPS, OWNERS Created 7 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
« no previous file with comments | « components/zip/zip_reader.cc ('k') | components/zip/zip_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/common/zip_reader.h" 5 #include "components/zip/zip_reader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "components/zip/zip_internal.h"
19 #include "chrome/common/zip_internal.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 20 #include "testing/platform_test.h"
22 21
23 namespace { 22 namespace {
24 23
25 // Wrap PlatformFiles in a class so that we don't leak them in tests. 24 // Wrap PlatformFiles in a class so that we don't leak them in tests.
26 class PlatformFileWrapper { 25 class PlatformFileWrapper {
27 public: 26 public:
28 typedef enum { 27 typedef enum {
29 READ_ONLY, 28 READ_ONLY,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 67
69 // Make the test a PlatformTest to setup autorelease pools properly on Mac. 68 // Make the test a PlatformTest to setup autorelease pools properly on Mac.
70 class ZipReaderTest : public PlatformTest { 69 class ZipReaderTest : public PlatformTest {
71 protected: 70 protected:
72 virtual void SetUp() { 71 virtual void SetUp() {
73 PlatformTest::SetUp(); 72 PlatformTest::SetUp();
74 73
75 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
76 test_dir_ = temp_dir_.path(); 75 test_dir_ = temp_dir_.path();
77 76
78 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); 77 ASSERT_TRUE(GetTestDataDirectory(&test_data_dir_));
79 test_data_dir_ = test_data_dir_.AppendASCII("zip"); 78 test_data_dir_ = test_data_dir_.AppendASCII("zip");
80 79
81 test_zip_file_ = test_data_dir_.AppendASCII("test.zip"); 80 test_zip_file_ = test_data_dir_.AppendASCII("test.zip");
82 evil_zip_file_ = test_data_dir_.AppendASCII("evil.zip"); 81 evil_zip_file_ = test_data_dir_.AppendASCII("evil.zip");
83 evil_via_invalid_utf8_zip_file_ = test_data_dir_.AppendASCII( 82 evil_via_invalid_utf8_zip_file_ = test_data_dir_.AppendASCII(
84 "evil_via_invalid_utf8.zip"); 83 "evil_via_invalid_utf8.zip");
85 evil_via_absolute_file_name_zip_file_ = test_data_dir_.AppendASCII( 84 evil_via_absolute_file_name_zip_file_ = test_data_dir_.AppendASCII(
86 "evil_via_absolute_file_name.zip"); 85 "evil_via_absolute_file_name.zip");
87 86
88 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/"))); 87 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/")));
89 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/"))); 88 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo/bar/")));
90 test_zip_contents_.insert( 89 test_zip_contents_.insert(
91 base::FilePath(FILE_PATH_LITERAL("foo/bar/baz.txt"))); 90 base::FilePath(FILE_PATH_LITERAL("foo/bar/baz.txt")));
92 test_zip_contents_.insert( 91 test_zip_contents_.insert(
93 base::FilePath(FILE_PATH_LITERAL("foo/bar/quux.txt"))); 92 base::FilePath(FILE_PATH_LITERAL("foo/bar/quux.txt")));
94 test_zip_contents_.insert( 93 test_zip_contents_.insert(
95 base::FilePath(FILE_PATH_LITERAL("foo/bar.txt"))); 94 base::FilePath(FILE_PATH_LITERAL("foo/bar.txt")));
96 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo.txt"))); 95 test_zip_contents_.insert(base::FilePath(FILE_PATH_LITERAL("foo.txt")));
97 test_zip_contents_.insert( 96 test_zip_contents_.insert(
98 base::FilePath(FILE_PATH_LITERAL("foo/bar/.hidden"))); 97 base::FilePath(FILE_PATH_LITERAL("foo/bar/.hidden")));
99 } 98 }
100 99
101 virtual void TearDown() { 100 virtual void TearDown() {
102 PlatformTest::TearDown(); 101 PlatformTest::TearDown();
103 } 102 }
104 103
104 bool GetTestDataDirectory(base::FilePath* path) {
105 bool success = PathService::Get(base::DIR_SOURCE_ROOT, path);
106 EXPECT_TRUE(success);
107 if (!success)
108 return false;
109 *path = path->AppendASCII("components");
110 *path = path->AppendASCII("test");
111 *path = path->AppendASCII("data");
112 return true;
113 }
114
105 // The path to temporary directory used to contain the test operations. 115 // The path to temporary directory used to contain the test operations.
106 base::FilePath test_dir_; 116 base::FilePath test_dir_;
107 // The path to the test data directory where test.zip etc. are located. 117 // The path to the test data directory where test.zip etc. are located.
108 base::FilePath test_data_dir_; 118 base::FilePath test_data_dir_;
109 // The path to test.zip in the test data directory. 119 // The path to test.zip in the test data directory.
110 base::FilePath test_zip_file_; 120 base::FilePath test_zip_file_;
111 // The path to evil.zip in the test data directory. 121 // The path to evil.zip in the test data directory.
112 base::FilePath evil_zip_file_; 122 base::FilePath evil_zip_file_;
113 // The path to evil_via_invalid_utf8.zip in the test data directory. 123 // The path to evil_via_invalid_utf8.zip in the test data directory.
114 base::FilePath evil_via_invalid_utf8_zip_file_; 124 base::FilePath evil_via_invalid_utf8_zip_file_;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath( 421 ASSERT_TRUE(reader.ExtractCurrentEntryToFilePath(
412 test_dir_.AppendASCII("test.txt"))); 422 test_dir_.AppendASCII("test.txt")));
413 423
414 std::string actual; 424 std::string actual;
415 ASSERT_TRUE(file_util::ReadFileToString( 425 ASSERT_TRUE(file_util::ReadFileToString(
416 test_dir_.AppendASCII("test.txt"), &actual)); 426 test_dir_.AppendASCII("test.txt"), &actual));
417 EXPECT_EQ(std::string("This is a test.\n"), actual); 427 EXPECT_EQ(std::string("This is a test.\n"), actual);
418 } 428 }
419 429
420 } // namespace zip 430 } // namespace zip
OLDNEW
« no previous file with comments | « components/zip/zip_reader.cc ('k') | components/zip/zip_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698