summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/gdata/gdata_files_unittest.cc
diff options
context:
space:
mode:
authorgspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 21:07:24 +0000
committergspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 21:07:24 +0000
commiteaab7a3cc36ce7b3def0244a24d2823ec8baff91 (patch)
treead7bda7001c65de74e0b7d72b05483fa4305f391 /chrome/browser/chromeos/gdata/gdata_files_unittest.cc
parent3e4d15aad961909fd541ea553bf9382dcfd016ea (diff)
downloadchromium_src-eaab7a3cc36ce7b3def0244a24d2823ec8baff91.zip
chromium_src-eaab7a3cc36ce7b3def0244a24d2823ec8baff91.tar.gz
chromium_src-eaab7a3cc36ce7b3def0244a24d2823ec8baff91.tar.bz2
Merge 142912 - gdata: Add upload_url() to GDataFile.
Per "Updating document or file content with the resumable protocol" section in the Google Documents List API version 3.0 [1], we should use "resumable-edit-media" URLs for updating existing files. Since we did not store the resumable-edit-media URLs in the existing protobuf files, we need to reject these files at the loading time. [1] https://developers.google.com/google-apps/documents-list/ BUG=127080 TEST=added some unit tests; open google drive with older protobuf. confirm that loading of the protobuf failed (error from gdata_files.cc is emitted) but everything works just fine as we fetch the feeds from the server Review URL: https://chromiumcodereview.appspot.com/10583006 TBR=satorux@chromium.org Review URL: https://chromiumcodereview.appspot.com/10696017 git-svn-id: svn://svn.chromium.org/chrome/branches/1180/src@144553 0039d316-1c4b-4281-b951-d872f2087c98
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.