Mandoline: support IME for HTMLWidgetRootLocal & HTMLWidgetLocalRoot.
[chromium-blink-merge.git] / google_apis / drive / drive_api_parser_unittest.cc
blobe27425dc0c7a0b0aa789e101e9968311f48cf1b4
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
3 // found in the LICENSE file.
5 #include "google_apis/drive/drive_api_parser.h"
7 #include "base/time/time.h"
8 #include "base/values.h"
9 #include "google_apis/drive/test_util.h"
10 #include "google_apis/drive/time_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace google_apis {
15 // Test about resource parsing.
16 TEST(DriveAPIParserTest, AboutResourceParser) {
17 std::string error;
18 scoped_ptr<base::Value> document = test_util::LoadJSONFile(
19 "drive/about.json");
20 ASSERT_TRUE(document.get());
22 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType());
23 scoped_ptr<AboutResource> resource(new AboutResource());
24 EXPECT_TRUE(resource->Parse(*document));
26 EXPECT_EQ("0AIv7G8yEYAWHUk9123", resource->root_folder_id());
27 EXPECT_EQ(5368709120LL, resource->quota_bytes_total());
28 EXPECT_EQ(1073741824LL, resource->quota_bytes_used_aggregate());
29 EXPECT_EQ(8177LL, resource->largest_change_id());
32 // Test app list parsing.
33 TEST(DriveAPIParserTest, AppListParser) {
34 std::string error;
35 scoped_ptr<base::Value> document = test_util::LoadJSONFile(
36 "drive/applist.json");
37 ASSERT_TRUE(document.get());
39 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType());
40 scoped_ptr<AppList> applist(new AppList);
41 EXPECT_TRUE(applist->Parse(*document));
43 EXPECT_EQ("\"Jm4BaSnCWNND-noZsHINRqj4ABC/tuqRBw0lvjUdPtc_2msA1tN4XYZ\"",
44 applist->etag());
45 ASSERT_EQ(2U, applist->items().size());
46 // Check Drive app 1
47 const AppResource& app1 = *applist->items()[0];
48 EXPECT_EQ("123456788192", app1.application_id());
49 EXPECT_EQ("Drive app 1", app1.name());
50 EXPECT_EQ("", app1.object_type());
51 EXPECT_TRUE(app1.supports_create());
52 EXPECT_TRUE(app1.is_removable());
53 EXPECT_EQ("abcdefghabcdefghabcdefghabcdefgh", app1.product_id());
55 ASSERT_EQ(1U, app1.primary_mimetypes().size());
56 EXPECT_EQ("application/vnd.google-apps.drive-sdk.123456788192",
57 *app1.primary_mimetypes()[0]);
59 ASSERT_EQ(2U, app1.secondary_mimetypes().size());
60 EXPECT_EQ("text/html", *app1.secondary_mimetypes()[0]);
61 EXPECT_EQ("text/plain", *app1.secondary_mimetypes()[1]);
63 ASSERT_EQ(2U, app1.primary_file_extensions().size());
64 EXPECT_EQ("exe", *app1.primary_file_extensions()[0]);
65 EXPECT_EQ("com", *app1.primary_file_extensions()[1]);
67 EXPECT_EQ(0U, app1.secondary_file_extensions().size());
69 ASSERT_EQ(6U, app1.icons().size());
70 const DriveAppIcon& icon1 = *app1.icons()[0];
71 EXPECT_EQ(DriveAppIcon::APPLICATION, icon1.category());
72 EXPECT_EQ(10, icon1.icon_side_length());
73 EXPECT_EQ("http://www.example.com/10.png", icon1.icon_url().spec());
75 const DriveAppIcon& icon6 = *app1.icons()[5];
76 EXPECT_EQ(DriveAppIcon::SHARED_DOCUMENT, icon6.category());
77 EXPECT_EQ(16, icon6.icon_side_length());
78 EXPECT_EQ("http://www.example.com/ds16.png", icon6.icon_url().spec());
80 EXPECT_EQ("https://www.example.com/createForApp1", app1.create_url().spec());
82 // Check Drive app 2
83 const AppResource& app2 = *applist->items()[1];
84 EXPECT_EQ("876543210000", app2.application_id());
85 EXPECT_EQ("Drive app 2", app2.name());
86 EXPECT_EQ("", app2.object_type());
87 EXPECT_FALSE(app2.supports_create());
88 EXPECT_FALSE(app2.is_removable());
89 EXPECT_EQ("hgfedcbahgfedcbahgfedcbahgfedcba", app2.product_id());
91 ASSERT_EQ(3U, app2.primary_mimetypes().size());
92 EXPECT_EQ("image/jpeg", *app2.primary_mimetypes()[0]);
93 EXPECT_EQ("image/png", *app2.primary_mimetypes()[1]);
94 EXPECT_EQ("application/vnd.google-apps.drive-sdk.876543210000",
95 *app2.primary_mimetypes()[2]);
97 EXPECT_EQ(0U, app2.secondary_mimetypes().size());
98 EXPECT_EQ(0U, app2.primary_file_extensions().size());
99 EXPECT_EQ(0U, app2.secondary_file_extensions().size());
101 ASSERT_EQ(3U, app2.icons().size());
102 const DriveAppIcon& icon2 = *app2.icons()[1];
103 EXPECT_EQ(DriveAppIcon::DOCUMENT, icon2.category());
104 EXPECT_EQ(10, icon2.icon_side_length());
105 EXPECT_EQ("http://www.example.com/d10.png", icon2.icon_url().spec());
107 EXPECT_EQ("https://www.example.com/createForApp2", app2.create_url().spec());
110 // Test file list parsing.
111 TEST(DriveAPIParserTest, FileListParser) {
112 std::string error;
113 scoped_ptr<base::Value> document = test_util::LoadJSONFile(
114 "drive/filelist.json");
115 ASSERT_TRUE(document.get());
117 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType());
118 scoped_ptr<FileList> filelist(new FileList);
119 EXPECT_TRUE(filelist->Parse(*document));
121 EXPECT_EQ(GURL("https://www.googleapis.com/drive/v2/files?pageToken=EAIaggEL"
122 "EgA6egpi96It9mH_____f_8AAP__AAD_okhU-cHLz83KzszMxsjMzs_RyNGJ"
123 "nridyrbHs7u9tv8AAP__AP7__n__AP8AokhU-cHLz83KzszMxsjMzs_RyNGJ"
124 "nridyrbHs7u9tv8A__4QZCEiXPTi_wtIgTkAAAAAngnSXUgCDEAAIgsJPgar"
125 "t10AAAAABC"), filelist->next_link());
127 ASSERT_EQ(3U, filelist->items().size());
128 // Check file 1 (a regular file)
129 const FileResource& file1 = *filelist->items()[0];
130 EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", file1.file_id());
131 EXPECT_EQ("\"WtRjAPZWbDA7_fkFjc5ojsEvDEF/MTM0MzM2NzgwMDIXYZ\"",
132 file1.etag());
133 EXPECT_EQ("My first file data", file1.title());
134 EXPECT_EQ("application/octet-stream", file1.mime_type());
136 EXPECT_FALSE(file1.labels().is_trashed());
137 EXPECT_FALSE(file1.shared());
139 EXPECT_EQ(640, file1.image_media_metadata().width());
140 EXPECT_EQ(480, file1.image_media_metadata().height());
141 EXPECT_EQ(90, file1.image_media_metadata().rotation());
143 base::Time created_time;
144 ASSERT_TRUE(
145 util::GetTimeFromString("2012-07-24T08:51:16.570Z", &created_time));
146 EXPECT_EQ(created_time, file1.created_date());
148 base::Time modified_time;
149 ASSERT_TRUE(
150 util::GetTimeFromString("2012-07-27T05:43:20.269Z", &modified_time));
151 EXPECT_EQ(modified_time, file1.modified_date());
153 ASSERT_EQ(1U, file1.parents().size());
154 EXPECT_EQ("0B4v7G8yEYAWHYW1OcExsUVZLABC", file1.parents()[0].file_id());
155 EXPECT_EQ(GURL("https://www.googleapis.com/drive/v2/files/"
156 "0B4v7G8yEYAWHYW1OcExsUVZLABC"),
157 file1.parents()[0].parent_link());
159 EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", file1.md5_checksum());
160 EXPECT_EQ(1000U, file1.file_size());
161 EXPECT_FALSE(file1.IsHostedDocument());
163 EXPECT_EQ(GURL("https://docs.google.com/file/d/"
164 "0B4v7G8yEYAWHUmRrU2lMS2hLABC/edit"),
165 file1.alternate_link());
166 ASSERT_EQ(1U, file1.open_with_links().size());
167 EXPECT_EQ("1234567890", file1.open_with_links()[0].app_id);
168 EXPECT_EQ(GURL("http://open_with_link/url"),
169 file1.open_with_links()[0].open_url);
171 // Check file 2 (a Google Document)
172 const FileResource& file2 = *filelist->items()[1];
173 EXPECT_EQ("Test Google Document", file2.title());
174 EXPECT_EQ("application/vnd.google-apps.document", file2.mime_type());
176 EXPECT_TRUE(file2.labels().is_trashed());
177 EXPECT_TRUE(file2.shared());
179 EXPECT_EQ(-1, file2.image_media_metadata().width());
180 EXPECT_EQ(-1, file2.image_media_metadata().height());
181 EXPECT_EQ(-1, file2.image_media_metadata().rotation());
183 base::Time shared_with_me_time;
184 ASSERT_TRUE(util::GetTimeFromString("2012-07-27T04:54:11.030Z",
185 &shared_with_me_time));
186 EXPECT_EQ(shared_with_me_time, file2.shared_with_me_date());
188 EXPECT_EQ(-1, file2.file_size());
189 EXPECT_TRUE(file2.IsHostedDocument());
191 ASSERT_EQ(0U, file2.parents().size());
193 EXPECT_EQ(0U, file2.open_with_links().size());
194 EXPECT_EQ(GURL("https://drive.google.com/share"
195 "?id=1Pc8jzfU1ErbN_eucMMqdqzY3eBm0v8sxXm_1CtLxABC"
196 "&embedOrigin=chrome-extension://test&hl=ja"),
197 file2.share_link());
199 // Check file 3 (a folder)
200 const FileResource& file3 = *filelist->items()[2];
201 EXPECT_EQ(-1, file3.file_size());
202 EXPECT_FALSE(file3.IsHostedDocument());
203 EXPECT_EQ("TestFolder", file3.title());
204 EXPECT_EQ("application/vnd.google-apps.folder", file3.mime_type());
205 ASSERT_TRUE(file3.IsDirectory());
206 EXPECT_FALSE(file3.shared());
208 ASSERT_EQ(1U, file3.parents().size());
209 EXPECT_EQ("0AIv7G8yEYAWHUk9ABC", file3.parents()[0].file_id());
210 EXPECT_EQ(0U, file3.open_with_links().size());
213 // Test change list parsing.
214 TEST(DriveAPIParserTest, ChangeListParser) {
215 std::string error;
216 scoped_ptr<base::Value> document =
217 test_util::LoadJSONFile("drive/changelist.json");
218 ASSERT_TRUE(document.get());
220 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType());
221 scoped_ptr<ChangeList> changelist(new ChangeList);
222 EXPECT_TRUE(changelist->Parse(*document));
224 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes?pageToken=8929",
225 changelist->next_link().spec());
226 EXPECT_EQ(13664, changelist->largest_change_id());
228 ASSERT_EQ(4U, changelist->items().size());
230 const ChangeResource& change1 = *changelist->items()[0];
231 EXPECT_EQ(8421, change1.change_id());
232 EXPECT_FALSE(change1.is_deleted());
233 EXPECT_EQ("1Pc8jzfU1ErbN_eucMMqdqzY3eBm0v8sxXm_1CtLxABC", change1.file_id());
234 EXPECT_EQ(change1.file_id(), change1.file()->file_id());
235 EXPECT_FALSE(change1.file()->shared());
236 EXPECT_EQ(change1.file()->modified_date(), change1.modification_date());
238 const ChangeResource& change2 = *changelist->items()[1];
239 EXPECT_EQ(8424, change2.change_id());
240 EXPECT_FALSE(change2.is_deleted());
241 EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", change2.file_id());
242 EXPECT_EQ(change2.file_id(), change2.file()->file_id());
243 EXPECT_TRUE(change2.file()->shared());
244 EXPECT_EQ(change2.file()->modified_date(), change2.modification_date());
246 const ChangeResource& change3 = *changelist->items()[2];
247 EXPECT_EQ(8429, change3.change_id());
248 EXPECT_FALSE(change3.is_deleted());
249 EXPECT_EQ("0B4v7G8yEYAWHYW1OcExsUVZLABC", change3.file_id());
250 EXPECT_EQ(change3.file_id(), change3.file()->file_id());
251 EXPECT_FALSE(change3.file()->shared());
252 EXPECT_EQ(change3.file()->modified_date(), change3.modification_date());
254 // Deleted entry.
255 const ChangeResource& change4 = *changelist->items()[3];
256 EXPECT_EQ(8430, change4.change_id());
257 EXPECT_EQ("ABCv7G8yEYAWHc3Y5X0hMSkJYXYZ", change4.file_id());
258 EXPECT_TRUE(change4.is_deleted());
259 base::Time modification_time;
260 ASSERT_TRUE(util::GetTimeFromString("2012-07-27T12:34:56.789Z",
261 &modification_time));
262 EXPECT_EQ(modification_time, change4.modification_date());
265 TEST(DriveAPIParserTest, HasKind) {
266 scoped_ptr<base::Value> change_list_json(
267 test_util::LoadJSONFile("drive/changelist.json"));
268 scoped_ptr<base::Value> file_list_json(
269 test_util::LoadJSONFile("drive/filelist.json"));
271 EXPECT_TRUE(ChangeList::HasChangeListKind(*change_list_json));
272 EXPECT_FALSE(ChangeList::HasChangeListKind(*file_list_json));
274 EXPECT_FALSE(FileList::HasFileListKind(*change_list_json));
275 EXPECT_TRUE(FileList::HasFileListKind(*file_list_json));
278 } // namespace google_apis