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

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

Issue 1969313005: [headless] Embed pak file into binary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated years in copyright Created 3 years, 10 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 | « ui/base/resource/data_pack.cc ('k') | ui/base/resource/resource_bundle.h » ('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) 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 "ui/base/resource/data_pack.h" 5 #include "ui/base/resource/data_pack.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ASSERT_TRUE(pack.GetStringPiece(1, &data)); 135 ASSERT_TRUE(pack.GetStringPiece(1, &data));
136 EXPECT_EQ(0U, data.length()); 136 EXPECT_EQ(0U, data.length());
137 ASSERT_TRUE(pack.GetStringPiece(10, &data)); 137 ASSERT_TRUE(pack.GetStringPiece(10, &data));
138 EXPECT_EQ(0U, data.length()); 138 EXPECT_EQ(0U, data.length());
139 139
140 // Try looking up an invalid key. 140 // Try looking up an invalid key.
141 ASSERT_FALSE(pack.HasResource(140)); 141 ASSERT_FALSE(pack.HasResource(140));
142 ASSERT_FALSE(pack.GetStringPiece(140, &data)); 142 ASSERT_FALSE(pack.GetStringPiece(140, &data));
143 } 143 }
144 144
145 TEST(DataPackTest, LoadFromBuffer) {
146 DataPack pack(SCALE_FACTOR_100P);
147
148 ASSERT_TRUE(pack.LoadFromBuffer(
149 base::StringPiece(kSamplePakContents, kSamplePakSize)));
150
151 base::StringPiece data;
152 ASSERT_TRUE(pack.HasResource(4));
153 ASSERT_TRUE(pack.GetStringPiece(4, &data));
154 EXPECT_EQ("this is id 4", data);
155 ASSERT_TRUE(pack.HasResource(6));
156 ASSERT_TRUE(pack.GetStringPiece(6, &data));
157 EXPECT_EQ("this is id 6", data);
158
159 // Try reading zero-length data blobs, just in case.
160 ASSERT_TRUE(pack.GetStringPiece(1, &data));
161 EXPECT_EQ(0U, data.length());
162 ASSERT_TRUE(pack.GetStringPiece(10, &data));
163 EXPECT_EQ(0U, data.length());
164
165 // Try looking up an invalid key.
166 ASSERT_FALSE(pack.HasResource(140));
167 ASSERT_FALSE(pack.GetStringPiece(140, &data));
168 }
169
145 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values( 170 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values(
146 DataPack::BINARY)); 171 DataPack::BINARY));
147 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values( 172 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values(
148 DataPack::UTF8)); 173 DataPack::UTF8));
149 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( 174 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values(
150 DataPack::UTF16)); 175 DataPack::UTF16));
151 176
152 TEST(DataPackTest, LoadFileWithTruncatedHeader) { 177 TEST(DataPackTest, LoadFileWithTruncatedHeader) {
153 base::FilePath data_path; 178 base::FilePath data_path;
154 ASSERT_TRUE(PathService::Get(UI_DIR_TEST_DATA, &data_path)); 179 ASSERT_TRUE(PathService::Get(UI_DIR_TEST_DATA, &data_path));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 kSampleCorruptPakSize), 246 kSampleCorruptPakSize),
222 static_cast<int>(kSampleCorruptPakSize)); 247 static_cast<int>(kSampleCorruptPakSize));
223 248
224 // Reading asset #10 should now fail as it extends past the end of the file. 249 // Reading asset #10 should now fail as it extends past the end of the file.
225 ASSERT_TRUE(pack.HasResource(10)); 250 ASSERT_TRUE(pack.HasResource(10));
226 ASSERT_FALSE(pack.GetStringPiece(10, &data)); 251 ASSERT_FALSE(pack.GetStringPiece(10, &data));
227 } 252 }
228 #endif 253 #endif
229 254
230 } // namespace ui 255 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack.cc ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698