summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/gdata/gdata_files_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/gdata/gdata_files_unittest.cc')
-rw-r--r--chrome/browser/chromeos/gdata/gdata_files_unittest.cc85
1 files changed, 85 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_files_unittest.cc b/chrome/browser/chromeos/gdata/gdata_files_unittest.cc
index d7c6fdf..bbfb1c9 100644
--- a/chrome/browser/chromeos/gdata/gdata_files_unittest.cc
+++ b/chrome/browser/chromeos/gdata/gdata_files_unittest.cc
@@ -12,6 +12,28 @@
namespace gdata {
+namespace {
+
+const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
+
+} // namespace
+
+TEST(GDataFileTest, FromProto_DetectBadUploadUrl) {
+ GDataFileProto proto;
+ proto.mutable_gdata_entry()->set_title("test.txt");
+
+ GDataFile file(NULL, NULL);
+ // This should fail as the upload URL is empty.
+ ASSERT_FALSE(file.FromProto(proto));
+
+ // Set a upload URL.
+ proto.set_upload_url(kResumableEditMediaUrl);
+
+ // This should succeed as the resource ID is correct.
+ ASSERT_TRUE(file.FromProto(proto));
+ EXPECT_EQ(kResumableEditMediaUrl, file.upload_url().spec());
+}
+
TEST(GDataRootDirectoryTest, ParseFromString_DetectBadTitle) {
GDataRootDirectoryProto proto;
GDataEntryProto* mutable_entry =
@@ -71,6 +93,69 @@ TEST(GDataRootDirectoryTest, ParseFromString_DetectBadResourceID) {
EXPECT_EQ(kGDataRootDirectoryResourceId, root.resource_id());
}
+// We have a similar test in FromProto_DetectBadUploadUrl, but the test here
+// is to ensure that an error in GDataFile::FromProto() is properly
+// propagated to GDataRootDirectory::ParseFromString().
+TEST(GDataRootDirectoryTest, ParseFromString_DetectNoUploadUrl) {
+ // Set up the root directory properly.
+ GDataRootDirectoryProto root_directory_proto;
+ GDataEntryProto* mutable_entry =
+ root_directory_proto.mutable_gdata_directory()->mutable_gdata_entry();
+ mutable_entry->mutable_file_info()->set_is_directory(true);
+ mutable_entry->set_title(kGDataRootDirectory);
+ mutable_entry->set_resource_id(kGDataRootDirectoryResourceId);
+ // Set the origin to the server.
+ root_directory_proto.mutable_gdata_directory()->set_origin(FROM_SERVER);
+
+ // Add an empty sub directory under the root directory. This directory is
+ // added to ensure that nothing is left when the parsing failed.
+ GDataDirectoryProto* sub_directory_proto =
+ root_directory_proto.mutable_gdata_directory()->add_child_directories();
+ sub_directory_proto->mutable_gdata_entry()->mutable_file_info()->
+ set_is_directory(true);
+ sub_directory_proto->mutable_gdata_entry()->set_title("empty");
+
+ // Add a sub directory under the root directory.
+ sub_directory_proto =
+ root_directory_proto.mutable_gdata_directory()->add_child_directories();
+ sub_directory_proto->mutable_gdata_entry()->mutable_file_info()->
+ set_is_directory(true);
+ sub_directory_proto->mutable_gdata_entry()->set_title("dir");
+
+ // Add a new file under the sub directory "dir".
+ GDataFileProto* file_proto =
+ sub_directory_proto->add_child_files();
+ file_proto->mutable_gdata_entry()->set_title("test.txt");
+
+ GDataRootDirectory root;
+ // The origin is set to UNINITIALIZED by default.
+ ASSERT_EQ(UNINITIALIZED, root.origin());
+ std::string serialized_proto;
+ // Serialize the proto and check if it's loaded.
+ // This should fail as the upload URL is not set for |file_proto|.
+ ASSERT_TRUE(root_directory_proto.SerializeToString(&serialized_proto));
+ ASSERT_FALSE(root.ParseFromString(serialized_proto));
+ // Nothing should be added to the root directory if the parse failed.
+ ASSERT_TRUE(root.child_files().empty());
+ ASSERT_TRUE(root.child_directories().empty());
+ // The origin should remain UNINITIALIZED because the loading failed.
+ ASSERT_EQ(UNINITIALIZED, root.origin());
+
+ // Set an upload URL.
+ file_proto->set_upload_url(kResumableEditMediaUrl);
+
+ // Serialize the proto and check if it's loaded.
+ // This should succeed as the upload URL is set for |file_proto|.
+ ASSERT_TRUE(root_directory_proto.SerializeToString(&serialized_proto));
+ ASSERT_TRUE(root.ParseFromString(serialized_proto));
+ // No file should be added to the root directory.
+ ASSERT_TRUE(root.child_files().empty());
+ // Two directories ("empty", "dir") should be added to the root directory.
+ ASSERT_EQ(2U, root.child_directories().size());
+ // The origin should change to FROM_CACHE because we loaded from the cache.
+ ASSERT_EQ(FROM_CACHE, root.origin());
+}
+
TEST(GDataRootDirectoryTest, RefreshFile) {
GDataRootDirectory root;
// Add a directory to the file system.