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

Side by Side Diff: chrome/common/zip_unittest.cc

Issue 8437016: Fix subtle flakiness from ZipTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
« no previous file with comments | « no previous file | no next file » | 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 <set> 5 #include <set>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 TEST_F(ZipTest, UnzipUncompressed) { 94 TEST_F(ZipTest, UnzipUncompressed) {
95 TestUnzipFile(FILE_PATH_LITERAL("test_nocompress.zip"), true); 95 TestUnzipFile(FILE_PATH_LITERAL("test_nocompress.zip"), true);
96 } 96 }
97 97
98 TEST_F(ZipTest, UnzipEvil) { 98 TEST_F(ZipTest, UnzipEvil) {
99 FilePath path; 99 FilePath path;
100 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 100 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
101 path = path.AppendASCII("zip").AppendASCII("evil.zip"); 101 path = path.AppendASCII("zip").AppendASCII("evil.zip");
102 ASSERT_FALSE(zip::Unzip(path, test_dir_)); 102 // Unzip the zip file into a sub directory of test_dir_ so evil.zip
103 FilePath evil_file = test_dir_; 103 // won't create a persistent file outside test_dir_ in case of a
104 // failure.
105 FilePath output_dir = test_dir_.AppendASCII("out");
106 ASSERT_FALSE(zip::Unzip(path, output_dir));
107 FilePath evil_file = output_dir;
104 evil_file = evil_file.AppendASCII( 108 evil_file = evil_file.AppendASCII(
105 "../levilevilevilevilevilevilevilevilevilevilevilevil"); 109 "../levilevilevilevilevilevilevilevilevilevilevilevil");
106 ASSERT_FALSE(file_util::PathExists(evil_file)); 110 ASSERT_FALSE(file_util::PathExists(evil_file));
107 } 111 }
108 112
109 TEST_F(ZipTest, UnzipEvil2) { 113 TEST_F(ZipTest, UnzipEvil2) {
110 FilePath path; 114 FilePath path;
111 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 115 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
112 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip"); 116 path = path.AppendASCII("zip").AppendASCII("evil_via_invalid_utf8.zip");
113 ASSERT_TRUE(zip::Unzip(path, test_dir_)); 117 // See the comment at UnzipEvil() for why we do this.
114 FilePath evil_file = test_dir_; 118 FilePath output_dir = test_dir_.AppendASCII("out");
119 ASSERT_TRUE(zip::Unzip(path, output_dir));
120 FilePath evil_file = output_dir;
115 evil_file = evil_file.AppendASCII("../evil.txt"); 121 evil_file = evil_file.AppendASCII("../evil.txt");
116 ASSERT_FALSE(file_util::PathExists(evil_file)); 122 ASSERT_FALSE(file_util::PathExists(evil_file));
117 } 123 }
118 124
119 TEST_F(ZipTest, Zip) { 125 TEST_F(ZipTest, Zip) {
120 FilePath src_dir; 126 FilePath src_dir;
121 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir)); 127 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &src_dir));
122 src_dir = src_dir.AppendASCII("zip").AppendASCII("test"); 128 src_dir = src_dir.AppendASCII("zip").AppendASCII("test");
123 129
124 ScopedTempDir temp_dir; 130 ScopedTempDir temp_dir;
(...skipping 11 matching lines...) Expand all
136 142
137 ScopedTempDir temp_dir; 143 ScopedTempDir temp_dir;
138 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 144 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
139 FilePath zip_file = temp_dir.path().AppendASCII("out.zip"); 145 FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
140 146
141 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false)); 147 EXPECT_TRUE(zip::Zip(src_dir, zip_file, false));
142 TestUnzipFile(zip_file, false); 148 TestUnzipFile(zip_file, false);
143 } 149 }
144 150
145 } // namespace 151 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698