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

Side by Side Diff: ui/base/resource/data_pack_unittest.cc

Issue 614893004: Refactor AppendToFile and WriteFileDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 6 years, 2 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
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 TEST(DataPackTest, LoadFromFileRegion) { 95 TEST(DataPackTest, LoadFromFileRegion) {
96 base::ScopedTempDir dir; 96 base::ScopedTempDir dir;
97 ASSERT_TRUE(dir.CreateUniqueTempDir()); 97 ASSERT_TRUE(dir.CreateUniqueTempDir());
98 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 98 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
99 99
100 // Construct a file which has a non page-aligned zero-filled header followed 100 // Construct a file which has a non page-aligned zero-filled header followed
101 // by the actual pak file content. 101 // by the actual pak file content.
102 const char kPadding[5678] = {0}; 102 const char kPadding[5678] = {0};
103 ASSERT_EQ(static_cast<int>(sizeof(kPadding)), 103 ASSERT_EQ(static_cast<int>(sizeof(kPadding)),
104 base::WriteFile(data_path, kPadding, sizeof(kPadding))); 104 base::WriteFile(data_path, kPadding, sizeof(kPadding)));
105 ASSERT_EQ(static_cast<int>(kSamplePakSize), 105 ASSERT_TRUE(base::AppendToFile(
106 base::AppendToFile(data_path, kSamplePakContents, kSamplePakSize)); 106 data_path, kSamplePakContents, kSamplePakSize));
107 107
108 base::File file(data_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 108 base::File file(data_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
109 ASSERT_TRUE(file.IsValid()); 109 ASSERT_TRUE(file.IsValid());
110 110
111 // Load the file through the data pack API. 111 // Load the file through the data pack API.
112 DataPack pack(SCALE_FACTOR_100P); 112 DataPack pack(SCALE_FACTOR_100P);
113 base::MemoryMappedFile::Region region(sizeof(kPadding), kSamplePakSize); 113 base::MemoryMappedFile::Region region(sizeof(kPadding), kSamplePakSize);
114 ASSERT_TRUE(pack.LoadFromFileRegion(file.Pass(), region)); 114 ASSERT_TRUE(pack.LoadFromFileRegion(file.Pass(), region));
115 115
116 base::StringPiece data; 116 base::StringPiece data;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 kSampleCorruptPakSize), 210 kSampleCorruptPakSize),
211 static_cast<int>(kSampleCorruptPakSize)); 211 static_cast<int>(kSampleCorruptPakSize));
212 212
213 // Reading asset #10 should now fail as it extends past the end of the file. 213 // Reading asset #10 should now fail as it extends past the end of the file.
214 ASSERT_TRUE(pack.HasResource(10)); 214 ASSERT_TRUE(pack.HasResource(10));
215 ASSERT_FALSE(pack.GetStringPiece(10, &data)); 215 ASSERT_FALSE(pack.GetStringPiece(10, &data));
216 } 216 }
217 #endif 217 #endif
218 218
219 } // namespace ui 219 } // namespace ui
OLDNEW
« no previous file with comments | « third_party/zlib/google/zip_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698