OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ASSERT_TRUE(root->GetCacheEntry("<resource_id_3>", "") != NULL); | 47 ASSERT_TRUE(root->GetCacheEntry("<resource_id_3>", "") != NULL); |
48 ASSERT_TRUE(root->GetCacheEntry("<resource_id_4>", "") == NULL); | 48 ASSERT_TRUE(root->GetCacheEntry("<resource_id_4>", "") == NULL); |
49 | 49 |
50 } | 50 } |
51 | 51 |
52 TEST(GDataRootDirectoryTest, ParseFromString_DetectBadTitle) { | 52 TEST(GDataRootDirectoryTest, ParseFromString_DetectBadTitle) { |
53 GDataRootDirectoryProto proto; | 53 GDataRootDirectoryProto proto; |
54 GDataEntryProto* mutable_entry = | 54 GDataEntryProto* mutable_entry = |
55 proto.mutable_gdata_directory()->mutable_gdata_entry(); | 55 proto.mutable_gdata_directory()->mutable_gdata_entry(); |
56 mutable_entry->mutable_file_info()->set_is_directory(true); | 56 mutable_entry->mutable_file_info()->set_is_directory(true); |
| 57 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); |
57 | 58 |
58 std::string serialized_proto; | 59 std::string serialized_proto; |
59 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); | 60 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
60 | 61 |
61 GDataRootDirectory root; | 62 GDataRootDirectory root; |
62 // This should fail as the title is empty. | 63 // This should fail as the title is empty. |
63 // root.title() should be unchanged. | 64 // root.title() should be unchanged. |
64 ASSERT_FALSE(root.ParseFromString(serialized_proto)); | 65 ASSERT_FALSE(root.ParseFromString(serialized_proto)); |
65 ASSERT_EQ("drive", root.title()); | 66 ASSERT_EQ(kGDataRootDirectory, root.title()); |
66 | 67 |
67 // Setting the title to "gdata". | 68 // Setting the title to "gdata". |
68 mutable_entry->set_title("gdata"); | 69 mutable_entry->set_title("gdata"); |
69 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); | 70 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
70 | 71 |
71 // This should fail as the title is not "drive". | 72 // This should fail as the title is not kGDataRootDirectory. |
72 // root.title() should be unchanged. | 73 // root.title() should be unchanged. |
73 ASSERT_FALSE(root.ParseFromString(serialized_proto)); | 74 ASSERT_FALSE(root.ParseFromString(serialized_proto)); |
74 ASSERT_EQ("drive", root.title()); | 75 ASSERT_EQ(kGDataRootDirectory, root.title()); |
75 | 76 |
76 // Setting the title to "drive". | 77 // Setting the title to kGDataRootDirectory. |
77 mutable_entry->set_title("drive"); | 78 mutable_entry->set_title(kGDataRootDirectory); |
78 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); | 79 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
79 | 80 |
80 // This should succeed as the title is "drive". | 81 // This should succeed as the title is kGDataRootDirectory. |
81 ASSERT_TRUE(root.ParseFromString(serialized_proto)); | 82 ASSERT_TRUE(root.ParseFromString(serialized_proto)); |
82 ASSERT_EQ("drive", root.title()); | 83 ASSERT_EQ(kGDataRootDirectory, root.title()); |
| 84 } |
| 85 |
| 86 TEST(GDataRootDirectoryTest, ParseFromString_DetectBadResourceID) { |
| 87 GDataRootDirectoryProto proto; |
| 88 GDataEntryProto* mutable_entry = |
| 89 proto.mutable_gdata_directory()->mutable_gdata_entry(); |
| 90 mutable_entry->mutable_file_info()->set_is_directory(true); |
| 91 mutable_entry->set_title(kGDataRootDirectory); |
| 92 |
| 93 std::string serialized_proto; |
| 94 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 95 |
| 96 GDataRootDirectory root; |
| 97 // This should fail as the resource ID is empty. |
| 98 // root.resource_id() should be unchanged. |
| 99 ASSERT_FALSE(root.ParseFromString(serialized_proto)); |
| 100 EXPECT_EQ(kGDataRootDirectoryResourceId, root.resource_id()); |
| 101 |
| 102 // Set the correct resource ID. |
| 103 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); |
| 104 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 105 |
| 106 // This should succeed as the resource ID is correct. |
| 107 ASSERT_TRUE(root.ParseFromString(serialized_proto)); |
| 108 EXPECT_EQ(kGDataRootDirectoryResourceId, root.resource_id()); |
| 109 } |
| 110 |
| 111 TEST(GDataRootDirectoryTest, GetEntryByResourceId_RootDirectory) { |
| 112 GDataRootDirectory root; |
| 113 // Look up the root directory by its resource ID. |
| 114 GDataEntry* entry = root.GetEntryByResourceId(kGDataRootDirectoryResourceId); |
| 115 ASSERT_TRUE(entry); |
| 116 EXPECT_TRUE(entry->AsGDataRootDirectory()); |
| 117 EXPECT_EQ(&root, entry->AsGDataRootDirectory()); |
83 } | 118 } |
84 | 119 |
85 } // namespace gdata | 120 } // namespace gdata |
OLD | NEW |