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.resoruce_id() should be unchanged. | |
achuithb
2012/05/18 17:42:56
resource_id
satorux1
2012/05/18 17:55:28
Done.
| |
99 ASSERT_FALSE(root.ParseFromString(serialized_proto)); | |
achuithb
2012/05/18 17:42:56
I think EXPECT_FALSE is better here. I feel like A
satorux1
2012/05/18 17:55:28
Won't crash but we don't want to continue if this
| |
100 ASSERT_EQ(kGDataRootDirectoryResourceId, root.resource_id()); | |
achuithb
2012/05/18 17:42:56
EXPECT_EQ
satorux1
2012/05/18 17:55:28
Done.
| |
101 | |
102 // Set the correct resource ID. | |
103 mutable_entry->set_resource_id(kGDataRootDirectoryResourceId); | |
104 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); | |
achuithb
2012/05/18 17:42:56
EXPECT_TRUE
satorux1
2012/05/18 17:55:28
likewise, we don't want to continue if this failed
| |
105 | |
106 // This should succeed as the resource ID is correct. | |
107 ASSERT_TRUE(root.ParseFromString(serialized_proto)); | |
achuithb
2012/05/18 17:42:56
EXPECT_TRUE?
satorux1
2012/05/18 17:55:28
ditto.
| |
108 ASSERT_EQ(kGDataRootDirectoryResourceId, root.resource_id()); | |
achuithb
2012/05/18 17:42:56
EXPECT_EQ
satorux1
2012/05/18 17:55:28
Done.
| |
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 ASSERT_TRUE(entry->AsGDataRootDirectory()); | |
achuithb
2012/05/18 17:42:56
EXPECT_TRUE
satorux1
2012/05/18 17:55:28
Done.
| |
117 EXPECT_EQ(&root, entry->AsGDataRootDirectory()); | |
83 } | 118 } |
84 | 119 |
85 } // namespace gdata | 120 } // namespace gdata |
OLD | NEW |