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/google_apis/gdata_wapi_parser.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/google_apis/test_util.h" | 14 #include "chrome/browser/google_apis/test_util.h" |
15 #include "chrome/browser/google_apis/time_util.h" | 15 #include "chrome/browser/google_apis/time_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace google_apis { | 18 namespace google_apis { |
19 | 19 |
20 // TODO(nhiroki): Move json files to out of 'chromeos' directory | 20 // TODO(nhiroki): Move json files to out of 'chromeos' directory |
21 // (http://crbug.com/149788). | 21 // (http://crbug.com/149788). |
22 // Test document feed parsing. | 22 // Test document feed parsing. |
23 TEST(GDataWAPIParserTest, ResourceListJsonParser) { | 23 TEST(GDataWAPIParserTest, ResourceListJsonParser) { |
24 std::string error; | 24 std::string error; |
25 scoped_ptr<base::Value> document = | 25 scoped_ptr<base::Value> document = |
26 test_util::LoadJSONFile("chromeos/gdata/basic_feed.json"); | 26 test_util::LoadJSONFile("gdata/basic_feed.json"); |
27 ASSERT_TRUE(document.get()); | 27 ASSERT_TRUE(document.get()); |
28 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType()); | 28 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType()); |
29 scoped_ptr<ResourceList> feed(ResourceList::ExtractAndParse(*document)); | 29 scoped_ptr<ResourceList> feed(ResourceList::ExtractAndParse(*document)); |
30 ASSERT_TRUE(feed.get()); | 30 ASSERT_TRUE(feed.get()); |
31 | 31 |
32 base::Time update_time; | 32 base::Time update_time; |
33 ASSERT_TRUE(util::GetTimeFromString("2011-12-14T01:03:21.151Z", | 33 ASSERT_TRUE(util::GetTimeFromString("2011-12-14T01:03:21.151Z", |
34 &update_time)); | 34 &update_time)); |
35 | 35 |
36 EXPECT_EQ(1, feed->start_index()); | 36 EXPECT_EQ(1, feed->start_index()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_TRUE(app_entry->is_hosted_document()); | 145 EXPECT_TRUE(app_entry->is_hosted_document()); |
146 EXPECT_TRUE(app_entry->is_external_document()); | 146 EXPECT_TRUE(app_entry->is_external_document()); |
147 EXPECT_FALSE(app_entry->is_google_document()); | 147 EXPECT_FALSE(app_entry->is_google_document()); |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 // Test document feed parsing. | 151 // Test document feed parsing. |
152 TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { | 152 TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { |
153 std::string error; | 153 std::string error; |
154 scoped_ptr<base::Value> document = | 154 scoped_ptr<base::Value> document = |
155 test_util::LoadJSONFile("chromeos/gdata/file_entry.json"); | 155 test_util::LoadJSONFile("gdata/file_entry.json"); |
156 ASSERT_TRUE(document.get()); | 156 ASSERT_TRUE(document.get()); |
157 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType()); | 157 ASSERT_EQ(base::Value::TYPE_DICTIONARY, document->GetType()); |
158 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(*document)); | 158 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(*document)); |
159 ASSERT_TRUE(entry.get()); | 159 ASSERT_TRUE(entry.get()); |
160 | 160 |
161 EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); | 161 EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); |
162 EXPECT_EQ("\"HhMOFgxXHit7ImBr\"", entry->etag()); | 162 EXPECT_EQ("\"HhMOFgxXHit7ImBr\"", entry->etag()); |
163 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); | 163 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); |
164 EXPECT_EQ("2_file_id", entry->id()); | 164 EXPECT_EQ("2_file_id", entry->id()); |
165 EXPECT_EQ("File 1.mp3", entry->title()); | 165 EXPECT_EQ("File 1.mp3", entry->title()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Check a file properties. | 226 // Check a file properties. |
227 EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); | 227 EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); |
228 EXPECT_EQ("File 1.mp3", entry->filename()); | 228 EXPECT_EQ("File 1.mp3", entry->filename()); |
229 EXPECT_EQ("File 1.mp3", entry->suggested_filename()); | 229 EXPECT_EQ("File 1.mp3", entry->suggested_filename()); |
230 EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", entry->file_md5()); | 230 EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", entry->file_md5()); |
231 EXPECT_EQ(892721, entry->file_size()); | 231 EXPECT_EQ(892721, entry->file_size()); |
232 } | 232 } |
233 | 233 |
234 TEST(GDataWAPIParserTest, AccountMetadataParser) { | 234 TEST(GDataWAPIParserTest, AccountMetadataParser) { |
235 scoped_ptr<base::Value> document = | 235 scoped_ptr<base::Value> document = |
236 test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"); | 236 test_util::LoadJSONFile("gdata/account_metadata.json"); |
237 ASSERT_TRUE(document.get()); | 237 ASSERT_TRUE(document.get()); |
238 base::DictionaryValue* document_dict = NULL; | 238 base::DictionaryValue* document_dict = NULL; |
239 base::DictionaryValue* entry_value = NULL; | 239 base::DictionaryValue* entry_value = NULL; |
240 ASSERT_TRUE(document->GetAsDictionary(&document_dict)); | 240 ASSERT_TRUE(document->GetAsDictionary(&document_dict)); |
241 ASSERT_TRUE(document_dict->GetDictionary(std::string("entry"), &entry_value)); | 241 ASSERT_TRUE(document_dict->GetDictionary(std::string("entry"), &entry_value)); |
242 ASSERT_TRUE(entry_value); | 242 ASSERT_TRUE(entry_value); |
243 | 243 |
244 scoped_ptr<AccountMetadata> metadata( | 244 scoped_ptr<AccountMetadata> metadata( |
245 AccountMetadata::CreateFrom(*document)); | 245 AccountMetadata::CreateFrom(*document)); |
246 ASSERT_TRUE(metadata.get()); | 246 ASSERT_TRUE(metadata.get()); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_EXTERNAL_APP)); | 374 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_EXTERNAL_APP)); |
375 EXPECT_EQ(ResourceEntry::KIND_OF_FOLDER, | 375 EXPECT_EQ(ResourceEntry::KIND_OF_FOLDER, |
376 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FOLDER)); | 376 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FOLDER)); |
377 EXPECT_EQ(ResourceEntry::KIND_OF_FILE, | 377 EXPECT_EQ(ResourceEntry::KIND_OF_FILE, |
378 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FILE)); | 378 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_FILE)); |
379 EXPECT_EQ(ResourceEntry::KIND_OF_FILE, | 379 EXPECT_EQ(ResourceEntry::KIND_OF_FILE, |
380 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_PDF)); | 380 ResourceEntry::ClassifyEntryKind(ENTRY_KIND_PDF)); |
381 } | 381 } |
382 | 382 |
383 } // namespace google_apis | 383 } // namespace google_apis |
OLD | NEW |