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

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

Issue 12217101: Replace FilePath with base::FilePath in some more top level directories. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« 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 "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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/path_service.h" 8 #include "base/path_service.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"
11 #include "ui/base/resource/data_pack.h" 11 #include "ui/base/resource/data_pack.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 class DataPackTest 15 class DataPackTest
16 : public testing::TestWithParam<DataPack::TextEncodingType> { 16 : public testing::TestWithParam<DataPack::TextEncodingType> {
17 public: 17 public:
18 DataPackTest() {} 18 DataPackTest() {}
19 }; 19 };
20 20
21 extern const char kSamplePakContents[]; 21 extern const char kSamplePakContents[];
22 extern const size_t kSamplePakSize; 22 extern const size_t kSamplePakSize;
23 23
24 TEST(DataPackTest, LoadFromPath) { 24 TEST(DataPackTest, LoadFromPath) {
25 base::ScopedTempDir dir; 25 base::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 base::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(SCALE_FACTOR_100P); 34 DataPack pack(SCALE_FACTOR_100P);
35 ASSERT_TRUE(pack.LoadFromPath(data_path)); 35 ASSERT_TRUE(pack.LoadFromPath(data_path));
36 36
37 base::StringPiece data; 37 base::StringPiece data;
(...skipping 11 matching lines...) Expand all
49 EXPECT_EQ(0U, data.length()); 49 EXPECT_EQ(0U, data.length());
50 50
51 // Try looking up an invalid key. 51 // Try looking up an invalid key.
52 ASSERT_FALSE(pack.HasResource(140)); 52 ASSERT_FALSE(pack.HasResource(140));
53 ASSERT_FALSE(pack.GetStringPiece(140, &data)); 53 ASSERT_FALSE(pack.GetStringPiece(140, &data));
54 } 54 }
55 55
56 TEST(DataPackTest, LoadFromFile) { 56 TEST(DataPackTest, LoadFromFile) {
57 base::ScopedTempDir dir; 57 base::ScopedTempDir dir;
58 ASSERT_TRUE(dir.CreateUniqueTempDir()); 58 ASSERT_TRUE(dir.CreateUniqueTempDir());
59 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 59 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
60 60
61 // Dump contents into the pak file. 61 // Dump contents into the pak file.
62 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), 62 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
63 static_cast<int>(kSamplePakSize)); 63 static_cast<int>(kSamplePakSize));
64 64
65 bool created = false; 65 bool created = false;
66 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 66 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
67 base::PlatformFile file = base::CreatePlatformFile( 67 base::PlatformFile file = base::CreatePlatformFile(
68 data_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, 68 data_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
69 &created, &error_code); 69 &created, &error_code);
(...skipping 24 matching lines...) Expand all
94 } 94 }
95 95
96 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values( 96 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values(
97 DataPack::BINARY)); 97 DataPack::BINARY));
98 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values( 98 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values(
99 DataPack::UTF8)); 99 DataPack::UTF8));
100 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( 100 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values(
101 DataPack::UTF16)); 101 DataPack::UTF16));
102 102
103 TEST(DataPackTest, LoadFileWithTruncatedHeader) { 103 TEST(DataPackTest, LoadFileWithTruncatedHeader) {
104 FilePath data_path; 104 base::FilePath data_path;
105 PathService::Get(base::DIR_SOURCE_ROOT, &data_path); 105 PathService::Get(base::DIR_SOURCE_ROOT, &data_path);
106 data_path = data_path.Append(FILE_PATH_LITERAL( 106 data_path = data_path.Append(FILE_PATH_LITERAL(
107 "ui/base/test/data/data_pack_unittest/truncated-header.pak")); 107 "ui/base/test/data/data_pack_unittest/truncated-header.pak"));
108 108
109 DataPack pack(SCALE_FACTOR_100P); 109 DataPack pack(SCALE_FACTOR_100P);
110 ASSERT_FALSE(pack.LoadFromPath(data_path)); 110 ASSERT_FALSE(pack.LoadFromPath(data_path));
111 } 111 }
112 112
113 TEST_P(DataPackTest, Write) { 113 TEST_P(DataPackTest, Write) {
114 base::ScopedTempDir dir; 114 base::ScopedTempDir dir;
115 ASSERT_TRUE(dir.CreateUniqueTempDir()); 115 ASSERT_TRUE(dir.CreateUniqueTempDir());
116 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak")); 116 base::FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak"));
117 117
118 std::string one("one"); 118 std::string one("one");
119 std::string two("two"); 119 std::string two("two");
120 std::string three("three"); 120 std::string three("three");
121 std::string four("four"); 121 std::string four("four");
122 std::string fifteen("fifteen"); 122 std::string fifteen("fifteen");
123 123
124 std::map<uint16, base::StringPiece> resources; 124 std::map<uint16, base::StringPiece> resources;
125 resources.insert(std::make_pair(1, base::StringPiece(one))); 125 resources.insert(std::make_pair(1, base::StringPiece(one)));
126 resources.insert(std::make_pair(2, base::StringPiece(two))); 126 resources.insert(std::make_pair(2, base::StringPiece(two)));
(...skipping 14 matching lines...) Expand all
141 EXPECT_EQ(two, data); 141 EXPECT_EQ(two, data);
142 ASSERT_TRUE(pack.GetStringPiece(3, &data)); 142 ASSERT_TRUE(pack.GetStringPiece(3, &data));
143 EXPECT_EQ(three, data); 143 EXPECT_EQ(three, data);
144 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 144 ASSERT_TRUE(pack.GetStringPiece(4, &data));
145 EXPECT_EQ(four, data); 145 EXPECT_EQ(four, data);
146 ASSERT_TRUE(pack.GetStringPiece(15, &data)); 146 ASSERT_TRUE(pack.GetStringPiece(15, &data));
147 EXPECT_EQ(fifteen, data); 147 EXPECT_EQ(fifteen, data);
148 } 148 }
149 149
150 } // namespace ui 150 } // 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