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

Side by Side Diff: chrome/browser/chromeos/drive/drive_resource_metadata_storage_unittest.cc

Issue 14249007: chromeos: Perform strict check on parent-shild relationship of DriveResourceMetadata DB (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « chrome/browser/chromeos/drive/drive_resource_metadata_storage.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 265 }
266 266
267 TEST_F(DriveResourceMetadataStorageTest, CheckValidity) { 267 TEST_F(DriveResourceMetadataStorageTest, CheckValidity) {
268 const std::string key1 = "foo"; 268 const std::string key1 = "foo";
269 const std::string name1 = "hoge"; 269 const std::string name1 = "hoge";
270 const std::string key2 = "bar"; 270 const std::string key2 = "bar";
271 const std::string name2 = "fuga"; 271 const std::string name2 = "fuga";
272 const std::string key3 = "boo"; 272 const std::string key3 = "boo";
273 const std::string name3 = "piyo"; 273 const std::string name3 = "piyo";
274 274
275 // Empty storage is valid.
276 EXPECT_TRUE(CheckValidity());
277
275 // Put entry with key1. 278 // Put entry with key1.
276 DriveEntryProto entry; 279 DriveEntryProto entry;
277 entry.set_resource_id(key1); 280 entry.set_resource_id(key1);
278 entry.set_base_name(name1); 281 entry.set_base_name(name1);
279 storage_->PutEntry(entry); 282 storage_->PutEntry(entry);
280 EXPECT_TRUE(CheckValidity()); 283 EXPECT_TRUE(CheckValidity());
281 284
282 // Put entry with key2 under key1. 285 // Put entry with key2 under key1.
283 entry.set_resource_id(key2); 286 entry.set_resource_id(key2);
284 entry.set_parent_resource_id(key1); 287 entry.set_parent_resource_id(key1);
285 entry.set_base_name(name2); 288 entry.set_base_name(name2);
286 storage_->PutEntry(entry); 289 storage_->PutEntry(entry);
287 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship. 290 EXPECT_FALSE(CheckValidity()); // Missing parent-child relationship.
288 291
289 // Add missing parent-child relationship between key1 and key2. 292 // Add missing parent-child relationship between key1 and key2.
290 storage_->PutChild(key1, name2, key2); 293 storage_->PutChild(key1, name2, key2);
291 EXPECT_TRUE(CheckValidity()); 294 EXPECT_TRUE(CheckValidity());
292 295
293 // Add parent-child relationship between key1 and key3. 296 // Add parent-child relationship between key2 and key3.
294 storage_->PutChild(key1, name3, key3); 297 storage_->PutChild(key2, name3, key3);
295 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage. 298 EXPECT_FALSE(CheckValidity()); // key3 is not stored in the storage.
296 299
297 // Put entry with key3 under key1. 300 // Put entry with key3 under key2.
298 entry.set_resource_id(key3); 301 entry.set_resource_id(key3);
299 entry.set_parent_resource_id(key1); 302 entry.set_parent_resource_id(key2);
300 entry.set_base_name(name3); 303 entry.set_base_name(name3);
301 storage_->PutEntry(entry); 304 storage_->PutEntry(entry);
302 EXPECT_TRUE(CheckValidity()); 305 EXPECT_TRUE(CheckValidity());
303 306
304 // Parent-child relationship with wrong name. 307 // Parent-child relationship with wrong name.
305 storage_->PutChild(key1, name2, key3); 308 storage_->RemoveChild(key2, name3);
306 EXPECT_FALSE(CheckValidity()); 309 EXPECT_FALSE(CheckValidity());
310 storage_->PutChild(key2, name2, key3);
311 EXPECT_FALSE(CheckValidity());
312
313 // Fix up the relationship between key2 and key3.
314 storage_->RemoveChild(key2, name2);
315 EXPECT_FALSE(CheckValidity());
316 storage_->PutChild(key2, name3, key3);
317 EXPECT_TRUE(CheckValidity());
318
319 // Remove key2.
320 storage_->RemoveChild(key1, name2);
321 EXPECT_FALSE(CheckValidity());
322 storage_->RemoveEntry(key2);
323 EXPECT_FALSE(CheckValidity());
324
325 // Remove key3.
326 storage_->RemoveChild(key2, name3);
327 EXPECT_FALSE(CheckValidity());
328 storage_->RemoveEntry(key3);
329 EXPECT_TRUE(CheckValidity());
330
331 // Remove key1.
332 storage_->RemoveEntry(key1);
333 EXPECT_TRUE(CheckValidity());
307 } 334 }
308 335
309 } // namespace drive 336 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_resource_metadata_storage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698