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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc

Issue 10692152: Rename gdata_parser to gdata_wapi_parser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_wapi_parser.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/gdata_parser.h" 13 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
14 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/libxml/chromium/libxml_utils.h" 16 #include "third_party/libxml/chromium/libxml_utils.h"
17 17
18 using base::Value; 18 using base::Value;
19 using base::DictionaryValue; 19 using base::DictionaryValue;
20 using base::ListValue; 20 using base::ListValue;
21 21
22 #define IF_EXPECT_EQ(arg1, arg2) \ 22 #define IF_EXPECT_EQ(arg1, arg2) \
23 EXPECT_EQ(arg1, arg2); \ 23 EXPECT_EQ(arg1, arg2); \
24 if (arg1 == arg2) 24 if (arg1 == arg2)
25 25
26 #define IF_EXPECT_TRUE(arg) \ 26 #define IF_EXPECT_TRUE(arg) \
27 EXPECT_TRUE(arg); \ 27 EXPECT_TRUE(arg); \
28 if (arg) 28 if (arg)
29 29
30 namespace gdata { 30 namespace gdata {
31 31
32 class GDataParserTest : public testing::Test { 32 class GDataWAPIParserTest : public testing::Test {
33 protected: 33 protected:
34 static Value* LoadJSONFile(const std::string& filename) { 34 static Value* LoadJSONFile(const std::string& filename) {
35 FilePath path; 35 FilePath path;
36 std::string error; 36 std::string error;
37 // Test files for this unit test are located in 37 // Test files for this unit test are located in
38 // src/chrome/test/data/chromeos/gdata/* 38 // src/chrome/test/data/chromeos/gdata/*
39 PathService::Get(chrome::DIR_TEST_DATA, &path); 39 PathService::Get(chrome::DIR_TEST_DATA, &path);
40 path = path.AppendASCII("chromeos") 40 path = path.AppendASCII("chromeos")
41 .AppendASCII("gdata") 41 .AppendASCII("gdata")
42 .AppendASCII(filename.c_str()); 42 .AppendASCII(filename.c_str());
(...skipping 28 matching lines...) Expand all
71 if (reader.NodeName() == "entry") { 71 if (reader.NodeName() == "entry") {
72 entry.reset(DocumentEntry::CreateFromXml(&reader)); 72 entry.reset(DocumentEntry::CreateFromXml(&reader));
73 break; 73 break;
74 } 74 }
75 } 75 }
76 return entry.release(); 76 return entry.release();
77 } 77 }
78 }; 78 };
79 79
80 // Test document feed parsing. 80 // Test document feed parsing.
81 TEST_F(GDataParserTest, DocumentFeedJsonParser) { 81 TEST_F(GDataWAPIParserTest, DocumentFeedJsonParser) {
82 std::string error; 82 std::string error;
83 scoped_ptr<Value> document(LoadJSONFile("basic_feed.json")); 83 scoped_ptr<Value> document(LoadJSONFile("basic_feed.json"));
84 ASSERT_TRUE(document.get()); 84 ASSERT_TRUE(document.get());
85 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); 85 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
86 scoped_ptr<DocumentFeed> feed(DocumentFeed::ExtractAndParse(*document)); 86 scoped_ptr<DocumentFeed> feed(DocumentFeed::ExtractAndParse(*document));
87 ASSERT_TRUE(feed.get()); 87 ASSERT_TRUE(feed.get());
88 88
89 base::Time update_time; 89 base::Time update_time;
90 ASSERT_TRUE(FeedEntry::GetTimeFromString("2011-12-14T01:03:21.151Z", 90 ASSERT_TRUE(FeedEntry::GetTimeFromString("2011-12-14T01:03:21.151Z",
91 &update_time)); 91 &update_time));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 IF_EXPECT_TRUE(app_entry) { 213 IF_EXPECT_TRUE(app_entry) {
214 EXPECT_EQ(DocumentEntry::EXTERNAL_APP, app_entry->kind()); 214 EXPECT_EQ(DocumentEntry::EXTERNAL_APP, app_entry->kind());
215 EXPECT_TRUE(app_entry->is_hosted_document()); 215 EXPECT_TRUE(app_entry->is_hosted_document());
216 EXPECT_TRUE(app_entry->is_external_document()); 216 EXPECT_TRUE(app_entry->is_external_document());
217 EXPECT_FALSE(app_entry->is_google_document()); 217 EXPECT_FALSE(app_entry->is_google_document());
218 } 218 }
219 } 219 }
220 220
221 221
222 // Test document feed parsing. 222 // Test document feed parsing.
223 TEST_F(GDataParserTest, DocumentEntryXmlParser) { 223 TEST_F(GDataWAPIParserTest, DocumentEntryXmlParser) {
224 scoped_ptr<DocumentEntry> entry(LoadDocumentEntryFromXml("entry.xml")); 224 scoped_ptr<DocumentEntry> entry(LoadDocumentEntryFromXml("entry.xml"));
225 ASSERT_TRUE(entry.get()); 225 ASSERT_TRUE(entry.get());
226 226
227 EXPECT_EQ(DocumentEntry::FILE, entry->kind()); 227 EXPECT_EQ(DocumentEntry::FILE, entry->kind());
228 EXPECT_EQ("\"HhMOFgcNHSt7ImBr\"", entry->etag()); 228 EXPECT_EQ("\"HhMOFgcNHSt7ImBr\"", entry->etag());
229 EXPECT_EQ("file:xml_file_resouce_id", entry->resource_id()); 229 EXPECT_EQ("file:xml_file_resouce_id", entry->resource_id());
230 EXPECT_EQ("https://xml_file_id", entry->id()); 230 EXPECT_EQ("https://xml_file_id", entry->id());
231 EXPECT_EQ(ASCIIToUTF16("Xml Entry File Title.tar"), entry->title()); 231 EXPECT_EQ(ASCIIToUTF16("Xml Entry File Title.tar"), entry->title());
232 base::Time entry1_update_time; 232 base::Time entry1_update_time;
233 base::Time entry1_publish_time; 233 base::Time entry1_publish_time;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 // Check a file properties. 302 // Check a file properties.
303 EXPECT_EQ(DocumentEntry::FILE, entry->kind()); 303 EXPECT_EQ(DocumentEntry::FILE, entry->kind());
304 EXPECT_EQ(ASCIIToUTF16("Xml Entry File Name.tar"), entry->filename()); 304 EXPECT_EQ(ASCIIToUTF16("Xml Entry File Name.tar"), entry->filename());
305 EXPECT_EQ(ASCIIToUTF16("Xml Entry Suggested File Name.tar"), 305 EXPECT_EQ(ASCIIToUTF16("Xml Entry Suggested File Name.tar"),
306 entry->suggested_filename()); 306 entry->suggested_filename());
307 EXPECT_EQ("e48f4d5c46a778de263e0e3f4b3d2a7d", entry->file_md5()); 307 EXPECT_EQ("e48f4d5c46a778de263e0e3f4b3d2a7d", entry->file_md5());
308 EXPECT_EQ(26562560, entry->file_size()); 308 EXPECT_EQ(26562560, entry->file_size());
309 } 309 }
310 310
311 TEST_F(GDataParserTest, AccountMetadataFeedParser) { 311 TEST_F(GDataWAPIParserTest, AccountMetadataFeedParser) {
312 scoped_ptr<Value> document(LoadJSONFile("account_metadata.json")); 312 scoped_ptr<Value> document(LoadJSONFile("account_metadata.json"));
313 ASSERT_TRUE(document.get()); 313 ASSERT_TRUE(document.get());
314 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); 314 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
315 DictionaryValue* entry_value = NULL; 315 DictionaryValue* entry_value = NULL;
316 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary( 316 ASSERT_TRUE(reinterpret_cast<DictionaryValue*>(document.get())->GetDictionary(
317 std::string("entry"), &entry_value)); 317 std::string("entry"), &entry_value));
318 ASSERT_TRUE(entry_value); 318 ASSERT_TRUE(entry_value);
319 319
320 scoped_ptr<AccountMetadataFeed> feed( 320 scoped_ptr<AccountMetadataFeed> feed(
321 AccountMetadataFeed::CreateFrom(*document)); 321 AccountMetadataFeed::CreateFrom(*document));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 second_app->GetProductUrl().spec()); 371 second_app->GetProductUrl().spec());
372 EXPECT_FALSE(second_app->supports_create()); 372 EXPECT_FALSE(second_app->supports_create());
373 EXPECT_EQ(2U, second_app->primary_mimetypes().size()); 373 EXPECT_EQ(2U, second_app->primary_mimetypes().size());
374 EXPECT_EQ(0U, second_app->secondary_mimetypes().size()); 374 EXPECT_EQ(0U, second_app->secondary_mimetypes().size());
375 EXPECT_EQ(1U, second_app->primary_extensions().size()); 375 EXPECT_EQ(1U, second_app->primary_extensions().size());
376 EXPECT_EQ(0U, second_app->secondary_extensions().size()); 376 EXPECT_EQ(0U, second_app->secondary_extensions().size());
377 } 377 }
378 } 378 }
379 379
380 // Test file extension checking in DocumentEntry::HasDocumentExtension(). 380 // Test file extension checking in DocumentEntry::HasDocumentExtension().
381 TEST_F(GDataParserTest, DocumentEntryHasDocumentExtension) { 381 TEST_F(GDataWAPIParserTest, DocumentEntryHasDocumentExtension) {
382 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension( 382 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension(
383 FilePath(FILE_PATH_LITERAL("Test.gdoc")))); 383 FilePath(FILE_PATH_LITERAL("Test.gdoc"))));
384 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension( 384 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension(
385 FilePath(FILE_PATH_LITERAL("Test.gsheet")))); 385 FilePath(FILE_PATH_LITERAL("Test.gsheet"))));
386 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension( 386 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension(
387 FilePath(FILE_PATH_LITERAL("Test.gslides")))); 387 FilePath(FILE_PATH_LITERAL("Test.gslides"))));
388 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension( 388 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension(
389 FilePath(FILE_PATH_LITERAL("Test.gdraw")))); 389 FilePath(FILE_PATH_LITERAL("Test.gdraw"))));
390 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension( 390 EXPECT_TRUE(DocumentEntry::HasHostedDocumentExtension(
391 FilePath(FILE_PATH_LITERAL("Test.gtable")))); 391 FilePath(FILE_PATH_LITERAL("Test.gtable"))));
392 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension( 392 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension(
393 FilePath(FILE_PATH_LITERAL("Test.tar.gz")))); 393 FilePath(FILE_PATH_LITERAL("Test.tar.gz"))));
394 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension( 394 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension(
395 FilePath(FILE_PATH_LITERAL("Test.txt")))); 395 FilePath(FILE_PATH_LITERAL("Test.txt"))));
396 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension( 396 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension(
397 FilePath(FILE_PATH_LITERAL("Test")))); 397 FilePath(FILE_PATH_LITERAL("Test"))));
398 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension( 398 EXPECT_FALSE(DocumentEntry::HasHostedDocumentExtension(
399 FilePath(FILE_PATH_LITERAL("")))); 399 FilePath(FILE_PATH_LITERAL(""))));
400 } 400 }
401 401
402 } // namespace gdata 402 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_wapi_parser.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698