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

Side by Side Diff: chrome/browser/chromeos/drive/document_entry_conversion_unittest.cc

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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/drive/document_entry_conversion.h" 5 #include "chrome/browser/chromeos/drive/document_entry_conversion.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chromeos/drive/drive.pb.h" 9 #include "chrome/browser/chromeos/drive/drive.pb.h"
10 #include "chrome/browser/chromeos/drive/drive_test_util.h" 10 #include "chrome/browser/chromeos/drive/drive_test_util.h"
11 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 11 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace gdata { 15 namespace drive {
16 16
17 TEST(DocumentEntryConversionTest, ConvertDocumentEntryToDriveEntryProto_File) { 17 TEST(DocumentEntryConversionTest, ConvertDocumentEntryToDriveEntryProto_File) {
18 scoped_ptr<base::Value> value = 18 scoped_ptr<base::Value> value =
19 test_util::LoadJSONFile("gdata/file_entry.json"); 19 gdata::test_util::LoadJSONFile("gdata/file_entry.json");
20 ASSERT_TRUE(value.get()); 20 ASSERT_TRUE(value.get());
21 21
22 scoped_ptr<DocumentEntry> document_entry( 22 scoped_ptr<gdata::DocumentEntry> document_entry(
23 DocumentEntry::ExtractAndParse(*value)); 23 gdata::DocumentEntry::ExtractAndParse(*value));
24 ASSERT_TRUE(document_entry.get()); 24 ASSERT_TRUE(document_entry.get());
25 25
26 DriveEntryProto entry_proto = 26 DriveEntryProto entry_proto =
27 ConvertDocumentEntryToDriveEntryProto(*document_entry); 27 ConvertDocumentEntryToDriveEntryProto(*document_entry);
28 28
29 EXPECT_EQ("File 1.mp3", entry_proto.title()); 29 EXPECT_EQ("File 1.mp3", entry_proto.title());
30 EXPECT_EQ("File 1.mp3", entry_proto.base_name()); 30 EXPECT_EQ("File 1.mp3", entry_proto.base_name());
31 EXPECT_EQ("file:2_file_resource_id", entry_proto.resource_id()); 31 EXPECT_EQ("file:2_file_resource_id", entry_proto.resource_id());
32 EXPECT_EQ("https://file_content_url/", entry_proto.content_url()); 32 EXPECT_EQ("https://file_content_url/", entry_proto.content_url());
33 EXPECT_EQ("https://file1_link_self/file:2_file_resource_id", 33 EXPECT_EQ("https://file1_link_self/file:2_file_resource_id",
34 entry_proto.edit_url()); 34 entry_proto.edit_url());
35 EXPECT_EQ("", entry_proto.parent_resource_id()); 35 EXPECT_EQ("", entry_proto.parent_resource_id());
36 36
37 EXPECT_FALSE(entry_proto.deleted()); 37 EXPECT_FALSE(entry_proto.deleted());
38 EXPECT_EQ(ENTRY_KIND_FILE, entry_proto.kind()); 38 EXPECT_EQ(gdata::ENTRY_KIND_FILE, entry_proto.kind());
39 39
40 // 2011-12-14T00:40:47.330Z 40 // 2011-12-14T00:40:47.330Z
41 base::Time::Exploded exploded; 41 base::Time::Exploded exploded;
42 exploded.year = 2011; 42 exploded.year = 2011;
43 exploded.month = 12; 43 exploded.month = 12;
44 exploded.day_of_month = 14; 44 exploded.day_of_month = 14;
45 exploded.day_of_week = 3; // Wednesday 45 exploded.day_of_week = 3; // Wednesday
46 exploded.hour = 0; 46 exploded.hour = 0;
47 exploded.minute = 40; 47 exploded.minute = 40;
48 exploded.second = 47; 48 exploded.second = 47;
(...skipping 19 matching lines...) Expand all
68 EXPECT_EQ(892721, entry_proto.file_info().size()); 68 EXPECT_EQ(892721, entry_proto.file_info().size());
69 EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", 69 EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce",
70 entry_proto.file_specific_info().file_md5()); 70 entry_proto.file_specific_info().file_md5());
71 EXPECT_EQ("https://file_link_resumable_edit_media/", 71 EXPECT_EQ("https://file_link_resumable_edit_media/",
72 entry_proto.upload_url()); 72 entry_proto.upload_url());
73 } 73 }
74 74
75 TEST(DocumentEntryConversionTest, 75 TEST(DocumentEntryConversionTest,
76 ConvertDocumentEntryToDriveEntryProto_HostedDocument) { 76 ConvertDocumentEntryToDriveEntryProto_HostedDocument) {
77 scoped_ptr<base::Value> value = 77 scoped_ptr<base::Value> value =
78 test_util::LoadJSONFile("gdata/hosted_document_entry.json"); 78 gdata::test_util::LoadJSONFile("gdata/hosted_document_entry.json");
79 ASSERT_TRUE(value.get()); 79 ASSERT_TRUE(value.get());
80 80
81 scoped_ptr<DocumentEntry> document_entry( 81 scoped_ptr<gdata::DocumentEntry> document_entry(
82 DocumentEntry::ExtractAndParse(*value)); 82 gdata::DocumentEntry::ExtractAndParse(*value));
83 ASSERT_TRUE(document_entry.get()); 83 ASSERT_TRUE(document_entry.get());
84 84
85 DriveEntryProto entry_proto = 85 DriveEntryProto entry_proto =
86 ConvertDocumentEntryToDriveEntryProto(*document_entry); 86 ConvertDocumentEntryToDriveEntryProto(*document_entry);
87 87
88 EXPECT_EQ("Document 1", entry_proto.title()); 88 EXPECT_EQ("Document 1", entry_proto.title());
89 EXPECT_EQ("Document 1.gdoc", entry_proto.base_name()); // The suffix added. 89 EXPECT_EQ("Document 1.gdoc", entry_proto.base_name()); // The suffix added.
90 EXPECT_EQ("document:5_document_resource_id", entry_proto.resource_id()); 90 EXPECT_EQ("document:5_document_resource_id", entry_proto.resource_id());
91 EXPECT_EQ("https://3_document_content/", entry_proto.content_url()); 91 EXPECT_EQ("https://3_document_content/", entry_proto.content_url());
92 EXPECT_EQ("https://3_document_self_link/document:5_document_resource_id", 92 EXPECT_EQ("https://3_document_self_link/document:5_document_resource_id",
93 entry_proto.edit_url()); 93 entry_proto.edit_url());
94 EXPECT_EQ("", entry_proto.parent_resource_id()); 94 EXPECT_EQ("", entry_proto.parent_resource_id());
95 95
96 EXPECT_FALSE(entry_proto.deleted()); 96 EXPECT_FALSE(entry_proto.deleted());
97 EXPECT_EQ(ENTRY_KIND_DOCUMENT, entry_proto.kind()); 97 EXPECT_EQ(gdata::ENTRY_KIND_DOCUMENT, entry_proto.kind());
98 98
99 // 2011-12-12T23:28:52.783Z 99 // 2011-12-12T23:28:52.783Z
100 base::Time::Exploded exploded; 100 base::Time::Exploded exploded;
101 exploded.year = 2011; 101 exploded.year = 2011;
102 exploded.month = 12; 102 exploded.month = 12;
103 exploded.day_of_month = 12; 103 exploded.day_of_month = 12;
104 exploded.day_of_week = 1; // Monday 104 exploded.day_of_week = 1; // Monday
105 exploded.hour = 23; 105 exploded.hour = 23;
106 exploded.minute = 28; 106 exploded.minute = 28;
107 exploded.second = 52; 107 exploded.second = 52;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EXPECT_EQ("https://3_document_alternate_link/", 148 EXPECT_EQ("https://3_document_alternate_link/",
149 entry_proto.file_specific_info().alternate_url()); 149 entry_proto.file_specific_info().alternate_url());
150 150
151 // The size should be 0 for a hosted document. 151 // The size should be 0 for a hosted document.
152 EXPECT_EQ(0, entry_proto.file_info().size()); 152 EXPECT_EQ(0, entry_proto.file_info().size());
153 } 153 }
154 154
155 TEST(DocumentEntryConversionTest, 155 TEST(DocumentEntryConversionTest,
156 ConvertDocumentEntryToDriveEntryProto_Directory) { 156 ConvertDocumentEntryToDriveEntryProto_Directory) {
157 scoped_ptr<base::Value> value = 157 scoped_ptr<base::Value> value =
158 test_util::LoadJSONFile("gdata/directory_entry.json"); 158 gdata::test_util::LoadJSONFile("gdata/directory_entry.json");
159 ASSERT_TRUE(value.get()); 159 ASSERT_TRUE(value.get());
160 160
161 scoped_ptr<DocumentEntry> document_entry( 161 scoped_ptr<gdata::DocumentEntry> document_entry(
162 DocumentEntry::ExtractAndParse(*value)); 162 gdata::DocumentEntry::ExtractAndParse(*value));
163 ASSERT_TRUE(document_entry.get()); 163 ASSERT_TRUE(document_entry.get());
164 164
165 DriveEntryProto entry_proto = 165 DriveEntryProto entry_proto =
166 ConvertDocumentEntryToDriveEntryProto(*document_entry); 166 ConvertDocumentEntryToDriveEntryProto(*document_entry);
167 167
168 EXPECT_EQ("Sub Directory Folder", entry_proto.title()); 168 EXPECT_EQ("Sub Directory Folder", entry_proto.title());
169 EXPECT_EQ("Sub Directory Folder", entry_proto.base_name()); 169 EXPECT_EQ("Sub Directory Folder", entry_proto.base_name());
170 EXPECT_EQ("folder:sub_dir_folder_resource_id", entry_proto.resource_id()); 170 EXPECT_EQ("folder:sub_dir_folder_resource_id", entry_proto.resource_id());
171 EXPECT_EQ("https://1_folder_content_url/", entry_proto.content_url()); 171 EXPECT_EQ("https://1_folder_content_url/", entry_proto.content_url());
172 EXPECT_EQ("https://dir2_sub_self_link/folder:sub_dir_folder_resource_id", 172 EXPECT_EQ("https://dir2_sub_self_link/folder:sub_dir_folder_resource_id",
173 entry_proto.edit_url()); 173 entry_proto.edit_url());
174 // The parent resource ID should be obtained as this is a sub directory 174 // The parent resource ID should be obtained as this is a sub directory
175 // under a non-root directory. 175 // under a non-root directory.
176 EXPECT_EQ("folder:1_folder_resource_id", entry_proto.parent_resource_id()); 176 EXPECT_EQ("folder:1_folder_resource_id", entry_proto.parent_resource_id());
177 177
178 EXPECT_FALSE(entry_proto.deleted()); 178 EXPECT_FALSE(entry_proto.deleted());
179 EXPECT_EQ(ENTRY_KIND_FOLDER, entry_proto.kind()); 179 EXPECT_EQ(gdata::ENTRY_KIND_FOLDER, entry_proto.kind());
180 180
181 // 2011-04-01T18:34:08.234Z 181 // 2011-04-01T18:34:08.234Z
182 base::Time::Exploded exploded; 182 base::Time::Exploded exploded;
183 exploded.year = 2011; 183 exploded.year = 2011;
184 exploded.month = 04; 184 exploded.month = 04;
185 exploded.day_of_month = 01; 185 exploded.day_of_month = 01;
186 exploded.day_of_week = 5; // Friday 186 exploded.day_of_week = 5; // Friday
187 exploded.hour = 18; 187 exploded.hour = 18;
188 exploded.minute = 34; 188 exploded.minute = 34;
189 exploded.second = 8; 189 exploded.second = 8;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 entry_proto.file_info().creation_time()); 223 entry_proto.file_info().creation_time());
224 224
225 // Directory should have this. 225 // Directory should have this.
226 EXPECT_EQ("https://2_folder_resumable_create_media_link/", 226 EXPECT_EQ("https://2_folder_resumable_create_media_link/",
227 entry_proto.upload_url()); 227 entry_proto.upload_url());
228 } 228 }
229 229
230 TEST(DocumentEntryConversionTest, 230 TEST(DocumentEntryConversionTest,
231 ConvertDocumentEntryToDriveEntryProto_DeletedHostedDocument) { 231 ConvertDocumentEntryToDriveEntryProto_DeletedHostedDocument) {
232 scoped_ptr<base::Value> value = 232 scoped_ptr<base::Value> value =
233 test_util::LoadJSONFile("gdata/deleted_hosted_document_entry.json"); 233 gdata::test_util::LoadJSONFile(
234 "gdata/deleted_hosted_document_entry.json");
234 ASSERT_TRUE(value.get()); 235 ASSERT_TRUE(value.get());
235 236
236 scoped_ptr<DocumentEntry> document_entry( 237 scoped_ptr<gdata::DocumentEntry> document_entry(
237 DocumentEntry::ExtractAndParse(*value)); 238 gdata::DocumentEntry::ExtractAndParse(*value));
238 ASSERT_TRUE(document_entry.get()); 239 ASSERT_TRUE(document_entry.get());
239 240
240 DriveEntryProto entry_proto = 241 DriveEntryProto entry_proto =
241 ConvertDocumentEntryToDriveEntryProto(*document_entry); 242 ConvertDocumentEntryToDriveEntryProto(*document_entry);
242 243
243 EXPECT_EQ("Deleted document", entry_proto.title()); 244 EXPECT_EQ("Deleted document", entry_proto.title());
244 EXPECT_EQ("Deleted document.gdoc", entry_proto.base_name()); 245 EXPECT_EQ("Deleted document.gdoc", entry_proto.base_name());
245 EXPECT_EQ("document:deleted_in_root_id", entry_proto.resource_id()); 246 EXPECT_EQ("document:deleted_in_root_id", entry_proto.resource_id());
246 EXPECT_EQ("https://content_url/", entry_proto.content_url()); 247 EXPECT_EQ("https://content_url/", entry_proto.content_url());
247 EXPECT_EQ("https://edit_url/document%3Adeleted_in_root_id", 248 EXPECT_EQ("https://edit_url/document%3Adeleted_in_root_id",
248 entry_proto.edit_url()); 249 entry_proto.edit_url());
249 EXPECT_EQ("", entry_proto.parent_resource_id()); 250 EXPECT_EQ("", entry_proto.parent_resource_id());
250 251
251 EXPECT_TRUE(entry_proto.deleted()); // The document was deleted. 252 EXPECT_TRUE(entry_proto.deleted()); // The document was deleted.
252 EXPECT_EQ(ENTRY_KIND_DOCUMENT, entry_proto.kind()); 253 EXPECT_EQ(gdata::ENTRY_KIND_DOCUMENT, entry_proto.kind());
253 254
254 // 2012-04-10T22:50:55.797Z 255 // 2012-04-10T22:50:55.797Z
255 base::Time::Exploded exploded; 256 base::Time::Exploded exploded;
256 exploded.year = 2012; 257 exploded.year = 2012;
257 exploded.month = 04; 258 exploded.month = 04;
258 exploded.day_of_month = 10; 259 exploded.day_of_month = 10;
259 exploded.day_of_week = 2; // Tuesday 260 exploded.day_of_week = 2; // Tuesday
260 exploded.hour = 22; 261 exploded.hour = 22;
261 exploded.minute = 50; 262 exploded.minute = 50;
262 exploded.second = 55; 263 exploded.second = 55;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EXPECT_TRUE(entry_proto.file_specific_info().is_hosted_document()); 301 EXPECT_TRUE(entry_proto.file_specific_info().is_hosted_document());
301 EXPECT_EQ("", 302 EXPECT_EQ("",
302 entry_proto.file_specific_info().thumbnail_url()); 303 entry_proto.file_specific_info().thumbnail_url());
303 EXPECT_EQ("https://alternate/document%3Adeleted_in_root_id/edit", 304 EXPECT_EQ("https://alternate/document%3Adeleted_in_root_id/edit",
304 entry_proto.file_specific_info().alternate_url()); 305 entry_proto.file_specific_info().alternate_url());
305 306
306 // The size should be 0 for a hosted document. 307 // The size should be 0 for a hosted document.
307 EXPECT_EQ(0, entry_proto.file_info().size()); 308 EXPECT_EQ(0, entry_proto.file_info().size());
308 } 309 }
309 310
310 } // namespace gdata 311 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/document_entry_conversion.cc ('k') | chrome/browser/chromeos/drive/drive.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698