diff options
author | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-18 07:53:34 +0000 |
---|---|---|
committer | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-18 07:53:34 +0000 |
commit | 14689653b022e1ad8943578165ca74eb5e56aefa (patch) | |
tree | 2d5993bb5daf8ccb5ca8488ebc8c01ba6722f6b5 /chrome/browser/google_apis/gdata_wapi_parser_unittest.cc | |
parent | 1f2155cb43a884398c27d1c5a3ece1adc1c88a36 (diff) | |
download | chromium_src-14689653b022e1ad8943578165ca74eb5e56aefa.zip chromium_src-14689653b022e1ad8943578165ca74eb5e56aefa.tar.gz chromium_src-14689653b022e1ad8943578165ca74eb5e56aefa.tar.bz2 |
Remove code parsing XML from gdata_wapi_parser.cc.
All responses from Drive API are in JSON, so we do not need support for parsing XML anymore.
BUG=165582
Review URL: https://codereview.chromium.org/11573005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google_apis/gdata_wapi_parser_unittest.cc')
-rw-r--r-- | chrome/browser/google_apis/gdata_wapi_parser_unittest.cc | 102 |
1 files changed, 36 insertions, 66 deletions
diff --git a/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc b/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc index b34f97e..0ac4245 100644 --- a/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc +++ b/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc @@ -17,7 +17,6 @@ #include "chrome/browser/google_apis/time_util.h" #include "chrome/common/chrome_paths.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/libxml/chromium/libxml_utils.h" using base::Value; using base::DictionaryValue; @@ -25,39 +24,10 @@ using base::ListValue; namespace google_apis { -class GDataWAPIParserTest : public testing::Test { - protected: - static ResourceEntry* LoadResourceEntryFromXml(const std::string& filename) { - FilePath path; - std::string error; - PathService::Get(chrome::DIR_TEST_DATA, &path); - path = path.AppendASCII("chromeos") - .AppendASCII("gdata") - .AppendASCII(filename.c_str()); - EXPECT_TRUE(file_util::PathExists(path)) << - "Couldn't find " << path.value(); - std::string contents; - EXPECT_TRUE(file_util::ReadFileToString(path, &contents)); - XmlReader reader; - if (!reader.Load(contents)) { - NOTREACHED() << "Invalid xml:\n" << contents; - return NULL; - } - scoped_ptr<ResourceEntry> entry; - while (reader.Read()) { - if (reader.NodeName() == "entry") { - entry = ResourceEntry::CreateFromXml(&reader); - break; - } - } - return entry.release(); - } -}; - // TODO(nhiroki): Move json files to out of 'chromeos' directory // (http://crbug.com/149788). // Test document feed parsing. -TEST_F(GDataWAPIParserTest, ResourceListJsonParser) { +TEST(GDataWAPIParserTest, ResourceListJsonParser) { std::string error; scoped_ptr<Value> document = test_util::LoadJSONFile("gdata/basic_feed.json"); @@ -86,7 +56,6 @@ TEST_F(GDataWAPIParserTest, ResourceListJsonParser) { EXPECT_EQ("https://self_link/", self_link->href().spec()); EXPECT_EQ("application/atom+xml", self_link->mime_type()); - const Link* resumable_link = feed->GetLinkByType(Link::LINK_RESUMABLE_CREATE_MEDIA); ASSERT_TRUE(resumable_link); @@ -188,60 +157,61 @@ TEST_F(GDataWAPIParserTest, ResourceListJsonParser) { // Test document feed parsing. -TEST_F(GDataWAPIParserTest, ResourceEntryXmlParser) { - scoped_ptr<ResourceEntry> entry(LoadResourceEntryFromXml("entry.xml")); +TEST(GDataWAPIParserTest, ResourceEntryJsonParser) { + std::string error; + scoped_ptr<Value> document = + test_util::LoadJSONFile("gdata/file_entry.json"); + ASSERT_TRUE(document.get()); + ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); + scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(*document)); ASSERT_TRUE(entry.get()); EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); - EXPECT_EQ("\"HhMOFgcNHSt7ImBr\"", entry->etag()); - EXPECT_EQ("file:xml_file_resource_id", entry->resource_id()); - EXPECT_EQ("https://xml_file_id", entry->id()); - EXPECT_EQ(ASCIIToUTF16("Xml Entry File Title.tar"), entry->title()); + EXPECT_EQ("\"HhMOFgxXHit7ImBr\"", entry->etag()); + EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); + EXPECT_EQ("2_file_id", entry->id()); + EXPECT_EQ(ASCIIToUTF16("File 1.mp3"), entry->title()); base::Time entry1_update_time; base::Time entry1_publish_time; - ASSERT_TRUE(util::GetTimeFromString("2011-04-01T18:34:08.234Z", - &entry1_update_time)); - ASSERT_TRUE(util::GetTimeFromString("2010-11-07T05:03:54.719Z", - &entry1_publish_time)); + ASSERT_TRUE(util::GetTimeFromString("2011-12-14T00:40:47.330Z", + &entry1_update_time)); + ASSERT_TRUE(util::GetTimeFromString("2011-12-13T00:40:47.330Z", + &entry1_publish_time)); EXPECT_EQ(entry1_update_time, entry->updated_time()); EXPECT_EQ(entry1_publish_time, entry->published_time()); EXPECT_EQ(1U, entry->authors().size()); - EXPECT_EQ(ASCIIToUTF16("entry_tester"), entry->authors()[0]->name()); - EXPECT_EQ("entry_tester@testing.com", entry->authors()[0]->email()); - EXPECT_EQ("https://1_xml_file_entry_content_url/", + EXPECT_EQ(ASCIIToUTF16("tester"), entry->authors()[0]->name()); + EXPECT_EQ("tester@testing.com", entry->authors()[0]->email()); + EXPECT_EQ("https://file_content_url/", entry->content_url().spec()); - EXPECT_EQ("application/x-tar", + EXPECT_EQ("audio/mpeg", entry->content_mime_type()); // Check feed links. - ASSERT_EQ(2U, entry->feed_links().size()); + ASSERT_EQ(1U, entry->feed_links().size()); const FeedLink* feed_link_1 = entry->feed_links()[0]; ASSERT_TRUE(feed_link_1); - EXPECT_EQ(FeedLink::FEED_LINK_ACL, feed_link_1->type()); - - const FeedLink* feed_link_2 = entry->feed_links()[1]; - ASSERT_TRUE(feed_link_2); - EXPECT_EQ(FeedLink::FEED_LINK_REVISIONS, feed_link_2->type()); + EXPECT_EQ(FeedLink::FEED_LINK_REVISIONS, feed_link_1->type()); // Check links. - ASSERT_EQ(9U, entry->links().size()); + ASSERT_EQ(8U, entry->links().size()); const Link* entry1_alternate_link = entry->GetLinkByType(Link::LINK_ALTERNATE); ASSERT_TRUE(entry1_alternate_link); - EXPECT_EQ("https://xml_file_entry_id_alternate_link/", + EXPECT_EQ("https://file_link_alternate/", entry1_alternate_link->href().spec()); EXPECT_EQ("text/html", entry1_alternate_link->mime_type()); const Link* entry1_edit_link = entry->GetLinkByType(Link::LINK_EDIT_MEDIA); ASSERT_TRUE(entry1_edit_link); - EXPECT_EQ("https://xml_file_entry_id_edit_media_link/", + EXPECT_EQ("https://file_edit_media/", entry1_edit_link->href().spec()); - EXPECT_EQ("application/x-tar", entry1_edit_link->mime_type()); + EXPECT_EQ("audio/mpeg", entry1_edit_link->mime_type()); const Link* entry1_self_link = entry->GetLinkByType(Link::LINK_SELF); ASSERT_TRUE(entry1_self_link); - EXPECT_EQ("https://xml_file_entry_id_self_link/", + EXPECT_EQ("https://file1_link_self/file:2_file_resource_id", entry1_self_link->href().spec()); EXPECT_EQ("application/atom+xml", entry1_self_link->mime_type()); EXPECT_EQ("", entry1_self_link->app_id()); @@ -249,28 +219,28 @@ TEST_F(GDataWAPIParserTest, ResourceEntryXmlParser) { const Link* entry1_open_with_link = entry->GetLinkByType(Link::LINK_OPEN_WITH); ASSERT_TRUE(entry1_open_with_link); - EXPECT_EQ("https://xml_file_entry_open_with_link/", + EXPECT_EQ("https://entry1_open_with_link/", entry1_open_with_link->href().spec()); EXPECT_EQ("application/atom+xml", entry1_open_with_link->mime_type()); EXPECT_EQ("the_app_id", entry1_open_with_link->app_id()); const Link* entry1_unknown_link = entry->GetLinkByType(Link::LINK_UNKNOWN); ASSERT_TRUE(entry1_unknown_link); - EXPECT_EQ("https://xml_file_fake_entry_open_with_link/", + EXPECT_EQ("https://entry1_fake_entry_open_with_link/", entry1_unknown_link->href().spec()); EXPECT_EQ("application/atom+xml", entry1_unknown_link->mime_type()); EXPECT_EQ("", entry1_unknown_link->app_id()); // Check a file properties. EXPECT_EQ(ENTRY_KIND_FILE, entry->kind()); - EXPECT_EQ(ASCIIToUTF16("Xml Entry File Name.tar"), entry->filename()); - EXPECT_EQ(ASCIIToUTF16("Xml Entry Suggested File Name.tar"), + EXPECT_EQ(ASCIIToUTF16("File 1.mp3"), entry->filename()); + EXPECT_EQ(ASCIIToUTF16("File 1.mp3"), entry->suggested_filename()); - EXPECT_EQ("e48f4d5c46a778de263e0e3f4b3d2a7d", entry->file_md5()); - EXPECT_EQ(26562560, entry->file_size()); + EXPECT_EQ("3b4382ebefec6e743578c76bbd0575ce", entry->file_md5()); + EXPECT_EQ(892721, entry->file_size()); } -TEST_F(GDataWAPIParserTest, AccountMetadataFeedParser) { +TEST(GDataWAPIParserTest, AccountMetadataFeedParser) { scoped_ptr<Value> document = test_util::LoadJSONFile("gdata/account_metadata.json"); ASSERT_TRUE(document.get()); @@ -338,7 +308,7 @@ TEST_F(GDataWAPIParserTest, AccountMetadataFeedParser) { } // Test file extension checking in ResourceEntry::HasDocumentExtension(). -TEST_F(GDataWAPIParserTest, ResourceEntryHasDocumentExtension) { +TEST(GDataWAPIParserTest, ResourceEntryHasDocumentExtension) { EXPECT_TRUE(ResourceEntry::HasHostedDocumentExtension( FilePath(FILE_PATH_LITERAL("Test.gdoc")))); EXPECT_TRUE(ResourceEntry::HasHostedDocumentExtension( @@ -359,7 +329,7 @@ TEST_F(GDataWAPIParserTest, ResourceEntryHasDocumentExtension) { FilePath(FILE_PATH_LITERAL("")))); } -TEST_F(GDataWAPIParserTest, ResourceEntryClassifyEntryKind) { +TEST(GDataWAPIParserTest, ResourceEntryClassifyEntryKind) { EXPECT_EQ(ResourceEntry::KIND_OF_NONE, ResourceEntry::ClassifyEntryKind(ENTRY_KIND_UNKNOWN)); EXPECT_EQ(ResourceEntry::KIND_OF_NONE, |