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

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

Issue 10387010: Select theme resources from ResourceBundle at requested scale factor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with master. Created 8 years, 7 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) 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 13 matching lines...) Expand all
24 TEST(DataPackTest, Load) { 24 TEST(DataPackTest, Load) {
25 ScopedTempDir dir; 25 ScopedTempDir dir;
26 ASSERT_TRUE(dir.CreateUniqueTempDir()); 26 ASSERT_TRUE(dir.CreateUniqueTempDir());
27 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 27 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
28 28
29 // Dump contents into the pak file. 29 // Dump contents into the pak file.
30 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), 30 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
31 static_cast<int>(kSamplePakSize)); 31 static_cast<int>(kSamplePakSize));
32 32
33 // Load the file through the data pack API. 33 // Load the file through the data pack API.
34 DataPack pack(ResourceHandle::kScaleFactor100x); 34 DataPack pack(SCALE_FACTOR_100P);
35 ASSERT_TRUE(pack.Load(data_path)); 35 ASSERT_TRUE(pack.Load(data_path));
36 36
37 base::StringPiece data; 37 base::StringPiece data;
38 ASSERT_TRUE(pack.HasResource(4));
38 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 39 ASSERT_TRUE(pack.GetStringPiece(4, &data));
39 EXPECT_EQ("this is id 4", data); 40 EXPECT_EQ("this is id 4", data);
41 ASSERT_TRUE(pack.HasResource(6));
40 ASSERT_TRUE(pack.GetStringPiece(6, &data)); 42 ASSERT_TRUE(pack.GetStringPiece(6, &data));
41 EXPECT_EQ("this is id 6", data); 43 EXPECT_EQ("this is id 6", data);
42 44
43 // Try reading zero-length data blobs, just in case. 45 // Try reading zero-length data blobs, just in case.
44 ASSERT_TRUE(pack.GetStringPiece(1, &data)); 46 ASSERT_TRUE(pack.GetStringPiece(1, &data));
45 EXPECT_EQ(0U, data.length()); 47 EXPECT_EQ(0U, data.length());
46 ASSERT_TRUE(pack.GetStringPiece(10, &data)); 48 ASSERT_TRUE(pack.GetStringPiece(10, &data));
47 EXPECT_EQ(0U, data.length()); 49 EXPECT_EQ(0U, data.length());
48 50
49 // Try looking up an invalid key. 51 // Try looking up an invalid key.
52 ASSERT_FALSE(pack.HasResource(140));
50 ASSERT_FALSE(pack.GetStringPiece(140, &data)); 53 ASSERT_FALSE(pack.GetStringPiece(140, &data));
51 } 54 }
52 55
53 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values( 56 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values(
54 DataPack::BINARY)); 57 DataPack::BINARY));
55 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values( 58 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values(
56 DataPack::UTF8)); 59 DataPack::UTF8));
57 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( 60 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values(
58 DataPack::UTF16)); 61 DataPack::UTF16));
59 62
60 TEST(DataPackTest, LoadFileWithTruncatedHeader) { 63 TEST(DataPackTest, LoadFileWithTruncatedHeader) {
61 FilePath data_path; 64 FilePath data_path;
62 PathService::Get(base::DIR_SOURCE_ROOT, &data_path); 65 PathService::Get(base::DIR_SOURCE_ROOT, &data_path);
63 data_path = data_path.Append(FILE_PATH_LITERAL( 66 data_path = data_path.Append(FILE_PATH_LITERAL(
64 "ui/base/test/data/data_pack_unittest/truncated-header.pak")); 67 "ui/base/test/data/data_pack_unittest/truncated-header.pak"));
65 68
66 DataPack pack(ResourceHandle::kScaleFactor100x); 69 DataPack pack(SCALE_FACTOR_100P);
67 ASSERT_FALSE(pack.Load(data_path)); 70 ASSERT_FALSE(pack.Load(data_path));
68 } 71 }
69 72
70 TEST_P(DataPackTest, Write) { 73 TEST_P(DataPackTest, Write) {
71 ScopedTempDir dir; 74 ScopedTempDir dir;
72 ASSERT_TRUE(dir.CreateUniqueTempDir()); 75 ASSERT_TRUE(dir.CreateUniqueTempDir());
73 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak")); 76 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak"));
74 77
75 std::string one("one"); 78 std::string one("one");
76 std::string two("two"); 79 std::string two("two");
77 std::string three("three"); 80 std::string three("three");
78 std::string four("four"); 81 std::string four("four");
79 std::string fifteen("fifteen"); 82 std::string fifteen("fifteen");
80 83
81 std::map<uint16, base::StringPiece> resources; 84 std::map<uint16, base::StringPiece> resources;
82 resources.insert(std::make_pair(1, base::StringPiece(one))); 85 resources.insert(std::make_pair(1, base::StringPiece(one)));
83 resources.insert(std::make_pair(2, base::StringPiece(two))); 86 resources.insert(std::make_pair(2, base::StringPiece(two)));
84 resources.insert(std::make_pair(15, base::StringPiece(fifteen))); 87 resources.insert(std::make_pair(15, base::StringPiece(fifteen)));
85 resources.insert(std::make_pair(3, base::StringPiece(three))); 88 resources.insert(std::make_pair(3, base::StringPiece(three)));
86 resources.insert(std::make_pair(4, base::StringPiece(four))); 89 resources.insert(std::make_pair(4, base::StringPiece(four)));
87 ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam())); 90 ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam()));
88 91
89 // Now try to read the data back in. 92 // Now try to read the data back in.
90 DataPack pack(ResourceHandle::kScaleFactor100x); 93 DataPack pack(SCALE_FACTOR_100P);
91 ASSERT_TRUE(pack.Load(file)); 94 ASSERT_TRUE(pack.Load(file));
92 EXPECT_EQ(pack.GetTextEncodingType(), GetParam()); 95 EXPECT_EQ(pack.GetTextEncodingType(), GetParam());
93 96
94 base::StringPiece data; 97 base::StringPiece data;
95 ASSERT_TRUE(pack.GetStringPiece(1, &data)); 98 ASSERT_TRUE(pack.GetStringPiece(1, &data));
96 EXPECT_EQ(one, data); 99 EXPECT_EQ(one, data);
97 ASSERT_TRUE(pack.GetStringPiece(2, &data)); 100 ASSERT_TRUE(pack.GetStringPiece(2, &data));
98 EXPECT_EQ(two, data); 101 EXPECT_EQ(two, data);
99 ASSERT_TRUE(pack.GetStringPiece(3, &data)); 102 ASSERT_TRUE(pack.GetStringPiece(3, &data));
100 EXPECT_EQ(three, data); 103 EXPECT_EQ(three, data);
101 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 104 ASSERT_TRUE(pack.GetStringPiece(4, &data));
102 EXPECT_EQ(four, data); 105 EXPECT_EQ(four, data);
103 ASSERT_TRUE(pack.GetStringPiece(15, &data)); 106 ASSERT_TRUE(pack.GetStringPiece(15, &data));
104 EXPECT_EQ(fifteen, data); 107 EXPECT_EQ(fifteen, data);
105 } 108 }
106 109
107 } // namespace ui 110 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698