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

Side by Side Diff: components/filesystem/directory_impl_unittest.cc

Issue 1157843002: Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « build/module_args/mojo.gni ('k') | components/filesystem/file_impl_unittest.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "components/filesystem/files_test_base.h" 8 #include "components/filesystem/files_test_base.h"
9 9
10 namespace filesystem { 10 namespace filesystem {
(...skipping 12 matching lines...) Expand all
23 uint32_t open_flags; 23 uint32_t open_flags;
24 } files_to_create[] = { 24 } files_to_create[] = {
25 {"my_file1", kOpenFlagRead | kOpenFlagWrite | kOpenFlagCreate}, 25 {"my_file1", kOpenFlagRead | kOpenFlagWrite | kOpenFlagCreate},
26 {"my_file2", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagExclusive}, 26 {"my_file2", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagExclusive},
27 {"my_file3", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagAppend}, 27 {"my_file3", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagAppend},
28 {"my_file4", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagTruncate}}; 28 {"my_file4", kOpenFlagWrite | kOpenFlagCreate | kOpenFlagTruncate}};
29 for (size_t i = 0; i < arraysize(files_to_create); i++) { 29 for (size_t i = 0; i < arraysize(files_to_create); i++) {
30 error = ERROR_INTERNAL; 30 error = ERROR_INTERNAL;
31 directory->OpenFile(files_to_create[i].name, nullptr, 31 directory->OpenFile(files_to_create[i].name, nullptr,
32 files_to_create[i].open_flags, Capture(&error)); 32 files_to_create[i].open_flags, Capture(&error));
33 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 33 ASSERT_TRUE(directory.WaitForIncomingResponse());
34 EXPECT_EQ(ERROR_OK, error); 34 EXPECT_EQ(ERROR_OK, error);
35 } 35 }
36 // Make a directory. 36 // Make a directory.
37 error = ERROR_INTERNAL; 37 error = ERROR_INTERNAL;
38 directory->OpenDirectory("my_dir", nullptr, 38 directory->OpenDirectory("my_dir", nullptr,
39 kOpenFlagRead | kOpenFlagWrite | kOpenFlagCreate, 39 kOpenFlagRead | kOpenFlagWrite | kOpenFlagCreate,
40 Capture(&error)); 40 Capture(&error));
41 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 41 ASSERT_TRUE(directory.WaitForIncomingResponse());
42 EXPECT_EQ(ERROR_OK, error); 42 EXPECT_EQ(ERROR_OK, error);
43 43
44 error = ERROR_INTERNAL; 44 error = ERROR_INTERNAL;
45 mojo::Array<DirectoryEntryPtr> directory_contents; 45 mojo::Array<DirectoryEntryPtr> directory_contents;
46 directory->Read(Capture(&error, &directory_contents)); 46 directory->Read(Capture(&error, &directory_contents));
47 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 47 ASSERT_TRUE(directory.WaitForIncomingResponse());
48 EXPECT_EQ(ERROR_OK, error); 48 EXPECT_EQ(ERROR_OK, error);
49 49
50 // Expected contents of the directory. 50 // Expected contents of the directory.
51 std::map<std::string, FileType> expected_contents; 51 std::map<std::string, FileType> expected_contents;
52 expected_contents["my_file1"] = FILE_TYPE_REGULAR_FILE; 52 expected_contents["my_file1"] = FILE_TYPE_REGULAR_FILE;
53 expected_contents["my_file2"] = FILE_TYPE_REGULAR_FILE; 53 expected_contents["my_file2"] = FILE_TYPE_REGULAR_FILE;
54 expected_contents["my_file3"] = FILE_TYPE_REGULAR_FILE; 54 expected_contents["my_file3"] = FILE_TYPE_REGULAR_FILE;
55 expected_contents["my_file4"] = FILE_TYPE_REGULAR_FILE; 55 expected_contents["my_file4"] = FILE_TYPE_REGULAR_FILE;
56 expected_contents["my_dir"] = FILE_TYPE_DIRECTORY; 56 expected_contents["my_dir"] = FILE_TYPE_DIRECTORY;
57 expected_contents["."] = FILE_TYPE_DIRECTORY; 57 expected_contents["."] = FILE_TYPE_DIRECTORY;
(...skipping 16 matching lines...) Expand all
74 // be harder to split this file. 74 // be harder to split this file.
75 TEST_F(DirectoryImplTest, StatTouch) { 75 TEST_F(DirectoryImplTest, StatTouch) {
76 DirectoryPtr directory; 76 DirectoryPtr directory;
77 GetTemporaryRoot(&directory); 77 GetTemporaryRoot(&directory);
78 Error error; 78 Error error;
79 79
80 // Stat it. 80 // Stat it.
81 error = ERROR_INTERNAL; 81 error = ERROR_INTERNAL;
82 FileInformationPtr file_info; 82 FileInformationPtr file_info;
83 directory->Stat(Capture(&error, &file_info)); 83 directory->Stat(Capture(&error, &file_info));
84 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 84 ASSERT_TRUE(directory.WaitForIncomingResponse());
85 EXPECT_EQ(ERROR_OK, error); 85 EXPECT_EQ(ERROR_OK, error);
86 ASSERT_FALSE(file_info.is_null()); 86 ASSERT_FALSE(file_info.is_null());
87 EXPECT_EQ(FILE_TYPE_DIRECTORY, file_info->type); 87 EXPECT_EQ(FILE_TYPE_DIRECTORY, file_info->type);
88 EXPECT_EQ(0, file_info->size); 88 EXPECT_EQ(0, file_info->size);
89 ASSERT_FALSE(file_info->atime.is_null()); 89 ASSERT_FALSE(file_info->atime.is_null());
90 EXPECT_GT(file_info->atime->seconds, 0); // Expect that it's not 1970-01-01. 90 EXPECT_GT(file_info->atime->seconds, 0); // Expect that it's not 1970-01-01.
91 ASSERT_FALSE(file_info->mtime.is_null()); 91 ASSERT_FALSE(file_info->mtime.is_null());
92 EXPECT_GT(file_info->mtime->seconds, 0); 92 EXPECT_GT(file_info->mtime->seconds, 0);
93 int64_t first_mtime = file_info->mtime->seconds; 93 int64_t first_mtime = file_info->mtime->seconds;
94 94
95 // Touch only the atime. 95 // Touch only the atime.
96 error = ERROR_INTERNAL; 96 error = ERROR_INTERNAL;
97 TimespecOrNowPtr t(TimespecOrNow::New()); 97 TimespecOrNowPtr t(TimespecOrNow::New());
98 t->now = false; 98 t->now = false;
99 t->timespec = Timespec::New(); 99 t->timespec = Timespec::New();
100 const int64_t kPartyTime1 = 1234567890; // Party like it's 2009-02-13. 100 const int64_t kPartyTime1 = 1234567890; // Party like it's 2009-02-13.
101 t->timespec->seconds = kPartyTime1; 101 t->timespec->seconds = kPartyTime1;
102 directory->Touch(t.Pass(), nullptr, Capture(&error)); 102 directory->Touch(t.Pass(), nullptr, Capture(&error));
103 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 103 ASSERT_TRUE(directory.WaitForIncomingResponse());
104 EXPECT_EQ(ERROR_OK, error); 104 EXPECT_EQ(ERROR_OK, error);
105 105
106 // Stat again. 106 // Stat again.
107 error = ERROR_INTERNAL; 107 error = ERROR_INTERNAL;
108 file_info.reset(); 108 file_info.reset();
109 directory->Stat(Capture(&error, &file_info)); 109 directory->Stat(Capture(&error, &file_info));
110 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 110 ASSERT_TRUE(directory.WaitForIncomingResponse());
111 EXPECT_EQ(ERROR_OK, error); 111 EXPECT_EQ(ERROR_OK, error);
112 ASSERT_FALSE(file_info.is_null()); 112 ASSERT_FALSE(file_info.is_null());
113 ASSERT_FALSE(file_info->atime.is_null()); 113 ASSERT_FALSE(file_info->atime.is_null());
114 EXPECT_EQ(kPartyTime1, file_info->atime->seconds); 114 EXPECT_EQ(kPartyTime1, file_info->atime->seconds);
115 ASSERT_FALSE(file_info->mtime.is_null()); 115 ASSERT_FALSE(file_info->mtime.is_null());
116 EXPECT_EQ(first_mtime, file_info->mtime->seconds); 116 EXPECT_EQ(first_mtime, file_info->mtime->seconds);
117 117
118 // Touch only the mtime. 118 // Touch only the mtime.
119 t = TimespecOrNow::New(); 119 t = TimespecOrNow::New();
120 t->now = false; 120 t->now = false;
121 t->timespec = Timespec::New(); 121 t->timespec = Timespec::New();
122 const int64_t kPartyTime2 = 1425059525; // No time like the present. 122 const int64_t kPartyTime2 = 1425059525; // No time like the present.
123 t->timespec->seconds = kPartyTime2; 123 t->timespec->seconds = kPartyTime2;
124 directory->Touch(nullptr, t.Pass(), Capture(&error)); 124 directory->Touch(nullptr, t.Pass(), Capture(&error));
125 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 125 ASSERT_TRUE(directory.WaitForIncomingResponse());
126 EXPECT_EQ(ERROR_OK, error); 126 EXPECT_EQ(ERROR_OK, error);
127 127
128 // Stat again. 128 // Stat again.
129 error = ERROR_INTERNAL; 129 error = ERROR_INTERNAL;
130 file_info.reset(); 130 file_info.reset();
131 directory->Stat(Capture(&error, &file_info)); 131 directory->Stat(Capture(&error, &file_info));
132 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 132 ASSERT_TRUE(directory.WaitForIncomingResponse());
133 EXPECT_EQ(ERROR_OK, error); 133 EXPECT_EQ(ERROR_OK, error);
134 ASSERT_FALSE(file_info.is_null()); 134 ASSERT_FALSE(file_info.is_null());
135 ASSERT_FALSE(file_info->atime.is_null()); 135 ASSERT_FALSE(file_info->atime.is_null());
136 EXPECT_EQ(kPartyTime1, file_info->atime->seconds); 136 EXPECT_EQ(kPartyTime1, file_info->atime->seconds);
137 ASSERT_FALSE(file_info->mtime.is_null()); 137 ASSERT_FALSE(file_info->mtime.is_null());
138 EXPECT_EQ(kPartyTime2, file_info->mtime->seconds); 138 EXPECT_EQ(kPartyTime2, file_info->mtime->seconds);
139 139
140 // TODO(vtl): Also test Touch() "now" options. 140 // TODO(vtl): Also test Touch() "now" options.
141 // TODO(vtl): Also test touching both atime and mtime. 141 // TODO(vtl): Also test touching both atime and mtime.
142 } 142 }
143 143
144 // TODO(vtl): Properly test OpenFile() and OpenDirectory() (including flags). 144 // TODO(vtl): Properly test OpenFile() and OpenDirectory() (including flags).
145 145
146 TEST_F(DirectoryImplTest, BasicRenameDelete) { 146 TEST_F(DirectoryImplTest, BasicRenameDelete) {
147 DirectoryPtr directory; 147 DirectoryPtr directory;
148 GetTemporaryRoot(&directory); 148 GetTemporaryRoot(&directory);
149 Error error; 149 Error error;
150 150
151 // Create my_file. 151 // Create my_file.
152 error = ERROR_INTERNAL; 152 error = ERROR_INTERNAL;
153 directory->OpenFile("my_file", nullptr, kOpenFlagWrite | kOpenFlagCreate, 153 directory->OpenFile("my_file", nullptr, kOpenFlagWrite | kOpenFlagCreate,
154 Capture(&error)); 154 Capture(&error));
155 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 155 ASSERT_TRUE(directory.WaitForIncomingResponse());
156 EXPECT_EQ(ERROR_OK, error); 156 EXPECT_EQ(ERROR_OK, error);
157 157
158 // Opening my_file should succeed. 158 // Opening my_file should succeed.
159 error = ERROR_INTERNAL; 159 error = ERROR_INTERNAL;
160 directory->OpenFile("my_file", nullptr, kOpenFlagRead, Capture(&error)); 160 directory->OpenFile("my_file", nullptr, kOpenFlagRead, Capture(&error));
161 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 161 ASSERT_TRUE(directory.WaitForIncomingResponse());
162 EXPECT_EQ(ERROR_OK, error); 162 EXPECT_EQ(ERROR_OK, error);
163 163
164 // Rename my_file to my_new_file. 164 // Rename my_file to my_new_file.
165 directory->Rename("my_file", "my_new_file", Capture(&error)); 165 directory->Rename("my_file", "my_new_file", Capture(&error));
166 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 166 ASSERT_TRUE(directory.WaitForIncomingResponse());
167 EXPECT_EQ(ERROR_OK, error); 167 EXPECT_EQ(ERROR_OK, error);
168 168
169 // Opening my_file should fail. 169 // Opening my_file should fail.
170 error = ERROR_INTERNAL; 170 error = ERROR_INTERNAL;
171 directory->OpenFile("my_file", nullptr, kOpenFlagRead, Capture(&error)); 171 directory->OpenFile("my_file", nullptr, kOpenFlagRead, Capture(&error));
172 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 172 ASSERT_TRUE(directory.WaitForIncomingResponse());
173 EXPECT_EQ(ERROR_UNKNOWN, error); 173 EXPECT_EQ(ERROR_UNKNOWN, error);
174 174
175 // Opening my_new_file should succeed. 175 // Opening my_new_file should succeed.
176 error = ERROR_INTERNAL; 176 error = ERROR_INTERNAL;
177 directory->OpenFile("my_new_file", nullptr, kOpenFlagRead, Capture(&error)); 177 directory->OpenFile("my_new_file", nullptr, kOpenFlagRead, Capture(&error));
178 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 178 ASSERT_TRUE(directory.WaitForIncomingResponse());
179 EXPECT_EQ(ERROR_OK, error); 179 EXPECT_EQ(ERROR_OK, error);
180 180
181 // Delete my_new_file (no flags). 181 // Delete my_new_file (no flags).
182 directory->Delete("my_new_file", 0, Capture(&error)); 182 directory->Delete("my_new_file", 0, Capture(&error));
183 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 183 ASSERT_TRUE(directory.WaitForIncomingResponse());
184 EXPECT_EQ(ERROR_OK, error); 184 EXPECT_EQ(ERROR_OK, error);
185 185
186 // Opening my_new_file should fail. 186 // Opening my_new_file should fail.
187 error = ERROR_INTERNAL; 187 error = ERROR_INTERNAL;
188 directory->OpenFile("my_new_file", nullptr, kOpenFlagRead, Capture(&error)); 188 directory->OpenFile("my_new_file", nullptr, kOpenFlagRead, Capture(&error));
189 ASSERT_TRUE(directory.WaitForIncomingMethodCall()); 189 ASSERT_TRUE(directory.WaitForIncomingResponse());
190 EXPECT_EQ(ERROR_UNKNOWN, error); 190 EXPECT_EQ(ERROR_UNKNOWN, error);
191 } 191 }
192 192
193 // TODO(vtl): Test that an open file can be moved (by someone else) without 193 // TODO(vtl): Test that an open file can be moved (by someone else) without
194 // operations on it being affected. 194 // operations on it being affected.
195 // TODO(vtl): Test delete flags. 195 // TODO(vtl): Test delete flags.
196 196
197 } // namespace 197 } // namespace
198 } // namespace filesystem 198 } // namespace filesystem
OLDNEW
« no previous file with comments | « build/module_args/mojo.gni ('k') | components/filesystem/file_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698