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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_files_unittest.cc

Issue 10444082: Refresh drive file system metadata for entries in search results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a nit Created 8 years, 6 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 "chrome/browser/chromeos/gdata/gdata_files.h" 5 #include "chrome/browser/chromeos/gdata/gdata_files.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 10 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Set the correct resource ID. 65 // Set the correct resource ID.
66 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); 66 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId);
67 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); 67 ASSERT_TRUE(proto.SerializeToString(&serialized_proto));
68 68
69 // This should succeed as the resource ID is correct. 69 // This should succeed as the resource ID is correct.
70 ASSERT_TRUE(root.ParseFromString(serialized_proto)); 70 ASSERT_TRUE(root.ParseFromString(serialized_proto));
71 EXPECT_EQ(kGDataRootDirectoryResourceId, root.resource_id()); 71 EXPECT_EQ(kGDataRootDirectoryResourceId, root.resource_id());
72 } 72 }
73 73
74 TEST(GDataRootDirectoryTest, RefreshFile) {
75 GDataRootDirectory root;
76 // Add a directory to the file system.
77 GDataDirectory* directory_entry = new GDataDirectory(&root, &root);
78 directory_entry->set_resource_id("folder:directory_resource_id");
79 root.AddEntry(directory_entry);
80
81 // Add a new file to the directory.
82 GDataFile* initial_file_entry = new GDataFile(NULL, &root);
83 initial_file_entry->set_resource_id("file:file_resource_id");
84 directory_entry->AddEntry(initial_file_entry);
85 ASSERT_EQ(directory_entry, initial_file_entry->parent());
86
87 // Initial file system state set, let's try refreshing entries.
88
89 // New value for the entry with resource id "file:file_resource_id".
90 GDataFile* new_file_entry = new GDataFile(NULL, &root);
91 new_file_entry->set_resource_id("file:file_resource_id");
92 root.RefreshFile(scoped_ptr<GDataEntry>(new_file_entry).Pass());
93 // Root should have |new_file_entry|, not |initial_file_entry|.
94 // If this is not true, |new_file_entry| has probably been destroyed, hence
95 // ASSERT (we're trying to access |new_file_entry| later on).
96 ASSERT_EQ(new_file_entry, root.GetEntryByResourceId("file:file_resource_id"));
97 // We have just verified new_file_entry exists inside root, so accessing
98 // |new_file_entry->parent()| should be safe.
99 EXPECT_EQ(directory_entry, new_file_entry->parent());
100
101 // Let's try refreshing file that didn't prviously exist.
102 GDataFile* non_existent_entry = new GDataFile(NULL, &root);
103 non_existent_entry->set_resource_id("file:does_not_exist");
104 root.RefreshFile(scoped_ptr<GDataEntry>(non_existent_entry).Pass());
105 // File with non existent resource id should not be added.
106 EXPECT_FALSE(root.GetEntryByResourceId("file:does_not_exist"));
107 }
108
74 TEST(GDataRootDirectoryTest, GetEntryByResourceId_RootDirectory) { 109 TEST(GDataRootDirectoryTest, GetEntryByResourceId_RootDirectory) {
75 GDataRootDirectory root; 110 GDataRootDirectory root;
76 // Look up the root directory by its resource ID. 111 // Look up the root directory by its resource ID.
77 GDataEntry* entry = root.GetEntryByResourceId(kGDataRootDirectoryResourceId); 112 GDataEntry* entry = root.GetEntryByResourceId(kGDataRootDirectoryResourceId);
78 ASSERT_TRUE(entry); 113 ASSERT_TRUE(entry);
79 EXPECT_TRUE(entry->AsGDataRootDirectory()); 114 EXPECT_TRUE(entry->AsGDataRootDirectory());
80 EXPECT_EQ(&root, entry->AsGDataRootDirectory()); 115 EXPECT_EQ(&root, entry->AsGDataRootDirectory());
81 } 116 }
82 117
83 } // namespace gdata 118 } // namespace gdata
OLDNEW
« chrome/browser/chromeos/gdata/gdata_files.h ('K') | « chrome/browser/chromeos/gdata/gdata_files.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698