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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" | 13 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using base::Value; | 18 using base::Value; |
18 using base::DictionaryValue; | 19 using base::DictionaryValue; |
19 using base::ListValue; | 20 using base::ListValue; |
20 | 21 |
21 #define IF_EXPECT_EQ(arg1, arg2) \ | 22 #define IF_EXPECT_EQ(arg1, arg2) \ |
22 EXPECT_EQ(arg1, arg2); \ | 23 EXPECT_EQ(arg1, arg2); \ |
23 if (arg1 == arg2) | 24 if (arg1 == arg2) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 IF_EXPECT_EQ(3U, app2.icons().size()) { | 150 IF_EXPECT_EQ(3U, app2.icons().size()) { |
150 const DriveAppIcon& icon2 = *app2.icons()[1]; | 151 const DriveAppIcon& icon2 = *app2.icons()[1]; |
151 EXPECT_EQ(DriveAppIcon::DOCUMENT, icon2.category()); | 152 EXPECT_EQ(DriveAppIcon::DOCUMENT, icon2.category()); |
152 EXPECT_EQ(10, icon2.icon_side_length()); | 153 EXPECT_EQ(10, icon2.icon_side_length()); |
153 EXPECT_EQ("http://www.example.com/d10.png", icon2.icon_url().spec()); | 154 EXPECT_EQ("http://www.example.com/d10.png", icon2.icon_url().spec()); |
154 } | 155 } |
155 } | 156 } |
156 } | 157 } |
157 | 158 |
| 159 // Test file list parsing. |
| 160 TEST_F(DriveAPIParserTest, FileListParser) { |
| 161 std::string error; |
| 162 scoped_ptr<Value> document(LoadJSONFile("filelist.json")); |
| 163 ASSERT_TRUE(document.get()); |
| 164 |
| 165 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); |
| 166 scoped_ptr<FileList> filelist(new FileList); |
| 167 EXPECT_TRUE(filelist->Parse(*document)); |
| 168 |
| 169 EXPECT_EQ("\"WtRjAPZWbDA7_fkFjc5ojsEvDEF/zyHTfoHpnRHovyi8bWpwK0DXABC\"", |
| 170 filelist->etag()); |
| 171 |
| 172 // TODO(kochi): Test next_page_token() and next_link() after figuring out |
| 173 // how they look like. |
| 174 |
| 175 IF_EXPECT_EQ(3U, filelist->items().size()) { |
| 176 // Check file 1 (a file) |
| 177 const FileResource& file1 = *filelist->items()[0]; |
| 178 EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", file1.id()); |
| 179 EXPECT_EQ("\"WtRjAPZWbDA7_fkFjc5ojsEvDEF/MTM0MzM2NzgwMDIXYZ\"", |
| 180 file1.etag()); |
| 181 EXPECT_EQ("My first file data", file1.title()); |
| 182 EXPECT_EQ("application/octet-stream", file1.mime_type()); |
| 183 |
| 184 base::Time modified_time; |
| 185 ASSERT_TRUE(gdata::util::GetTimeFromString("2012-07-27T05:43:20.269Z", |
| 186 &modified_time)); |
| 187 EXPECT_EQ(modified_time, file1.modified_by_me_date()); |
| 188 EXPECT_EQ(GURL("https://www.example.com/download"), file1.download_url()); |
| 189 EXPECT_EQ("ext", file1.file_extension()); |
| 190 EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", file1.md5_checksum()); |
| 191 EXPECT_EQ(1000U, file1.file_size()); |
| 192 |
| 193 // Check file 2 (a Google Document) |
| 194 const FileResource& file2 = *filelist->items()[1]; |
| 195 EXPECT_EQ("Test Google Document", file2.title()); |
| 196 EXPECT_EQ("application/vnd.google-apps.document", file2.mime_type()); |
| 197 EXPECT_EQ(0U, file2.file_size()); |
| 198 |
| 199 // Check file 3 (a folder) |
| 200 const FileResource& file3 = *filelist->items()[2]; |
| 201 EXPECT_EQ(0U, file3.file_size()); |
| 202 EXPECT_EQ("TestFolder", file3.title()); |
| 203 EXPECT_EQ("application/vnd.google-apps.folder", file3.mime_type()); |
| 204 ASSERT_TRUE(file3.IsFolder()); |
| 205 } |
| 206 } |
| 207 |
158 } // namespace gdata | 208 } // namespace gdata |
OLD | NEW |