Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 std::string error; | 71 std::string error; |
| 71 scoped_ptr<Value> document(LoadJSONFile("applist.json")); | 72 scoped_ptr<Value> document(LoadJSONFile("applist.json")); |
| 72 ASSERT_TRUE(document.get()); | 73 ASSERT_TRUE(document.get()); |
| 73 | 74 |
| 74 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); | 75 ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType()); |
| 75 scoped_ptr<AppList> applist(new AppList); | 76 scoped_ptr<AppList> applist(new AppList); |
| 76 EXPECT_TRUE(applist->Parse(*document)); | 77 EXPECT_TRUE(applist->Parse(*document)); |
| 77 | 78 |
| 78 EXPECT_EQ("\"Jm4BaSnCWNND-noZsHINRqj4ABC/tuqRBw0lvjUdPtc_2msA1tN4XYZ\"", | 79 EXPECT_EQ("\"Jm4BaSnCWNND-noZsHINRqj4ABC/tuqRBw0lvjUdPtc_2msA1tN4XYZ\"", |
| 79 applist->etag()); | 80 applist->etag()); |
| 80 IF_EXPECT_EQ(2U, applist->items().size()) { | 81 IF_EXPECT_EQ(2U, applist->items().size()) { |
|
satorux1
2012/07/30 16:34:33
ASSERT_EQ
kochi
2012/07/31 08:07:58
Done.
| |
| 81 // Check Drive app 1 | 82 // Check Drive app 1 |
| 82 const AppResource& app1 = *applist->items()[0]; | 83 const AppResource& app1 = *applist->items()[0]; |
| 83 EXPECT_EQ("123456788192", app1.id()); | 84 EXPECT_EQ("123456788192", app1.id()); |
| 84 EXPECT_EQ("Drive app 1", app1.name()); | 85 EXPECT_EQ("Drive app 1", app1.name()); |
| 85 EXPECT_EQ("", app1.object_type()); | 86 EXPECT_EQ("", app1.object_type()); |
| 86 EXPECT_EQ(true, app1.supports_create()); | 87 EXPECT_EQ(true, app1.supports_create()); |
| 87 EXPECT_EQ(true, app1.supports_import()); | 88 EXPECT_EQ(true, app1.supports_import()); |
| 88 EXPECT_EQ(true, app1.is_installed()); | 89 EXPECT_EQ(true, app1.is_installed()); |
| 89 EXPECT_EQ(false, app1.is_authorized()); | 90 EXPECT_EQ(false, app1.is_authorized()); |
| 90 EXPECT_EQ("https://chrome.google.com/webstore/detail/" | 91 EXPECT_EQ("https://chrome.google.com/webstore/detail/" |
| 91 "abcdefghabcdefghabcdefghabcdefgh", | 92 "abcdefghabcdefghabcdefghabcdefgh", |
| 92 app1.product_url().spec()); | 93 app1.product_url().spec()); |
| 93 | 94 |
| 94 IF_EXPECT_EQ(1U, app1.primary_mimetypes().size()) { | 95 IF_EXPECT_EQ(1U, app1.primary_mimetypes().size()) { |
|
satorux1
2012/07/30 16:34:33
ASSERT_EQ
kochi
2012/07/31 08:07:58
Done.
| |
| 95 EXPECT_EQ("application/vnd.google-apps.drive-sdk.123456788192", | 96 EXPECT_EQ("application/vnd.google-apps.drive-sdk.123456788192", |
| 96 *app1.primary_mimetypes()[0]); | 97 *app1.primary_mimetypes()[0]); |
| 97 } | 98 } |
| 98 | 99 |
| 99 IF_EXPECT_EQ(2U, app1.secondary_mimetypes().size()) { | 100 IF_EXPECT_EQ(2U, app1.secondary_mimetypes().size()) { |
| 100 EXPECT_EQ("text/html", *app1.secondary_mimetypes()[0]); | 101 EXPECT_EQ("text/html", *app1.secondary_mimetypes()[0]); |
| 101 EXPECT_EQ("text/plain", *app1.secondary_mimetypes()[1]); | 102 EXPECT_EQ("text/plain", *app1.secondary_mimetypes()[1]); |
| 102 } | 103 } |
| 103 | 104 |
| 104 IF_EXPECT_EQ(2U, app1.primary_file_extensions().size()) { | 105 IF_EXPECT_EQ(2U, app1.primary_file_extensions().size()) { |
| (...skipping 43 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 EXPECT_EQ("EAIaggELEgA6egpi96It9mH_____f_8AAP__AAD_okhU-cHLz83KzszMxsjMzs_Ry" | |
| 172 "NGJnridyrbHs7u9tv8AAP__AP7__n__AP8AokhU-cHLz83KzszMxsjMzs_RyNGJnr" | |
| 173 "idyrbHs7u9tv8A__4QZCEiXPTi_wtIgTkAAAAAngnSXUgCDEAAIgsJPgart10AAAA" | |
| 174 "ABC", filelist->next_page_token()); | |
| 175 EXPECT_EQ(GURL("https://www.googleapis.com/drive/v2/files?pageToken=EAIaggEL" | |
| 176 "EgA6egpi96It9mH_____f_8AAP__AAD_okhU-cHLz83KzszMxsjMzs_RyNGJ" | |
| 177 "nridyrbHs7u9tv8AAP__AP7__n__AP8AokhU-cHLz83KzszMxsjMzs_RyNGJ" | |
| 178 "nridyrbHs7u9tv8A__4QZCEiXPTi_wtIgTkAAAAAngnSXUgCDEAAIgsJPgar" | |
| 179 "t10AAAAABC"), filelist->next_link()); | |
| 180 | |
| 181 IF_EXPECT_EQ(3U, filelist->items().size()) { | |
|
satorux1
2012/07/30 16:34:33
ASSERT_EQ(3U, filelist->items().size());
IF_EXPEC
kochi
2012/07/31 08:07:58
Done.
I copied the macro from gdata_wapi_parser_u
satorux1
2012/08/01 04:35:45
Could you also remove these IF_ macros from gdata
| |
| 182 // Check file 1 (a file) | |
| 183 const FileResource& file1 = *filelist->items()[0]; | |
| 184 EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", file1.id()); | |
| 185 EXPECT_EQ("\"WtRjAPZWbDA7_fkFjc5ojsEvDEF/MTM0MzM2NzgwMDIXYZ\"", | |
| 186 file1.etag()); | |
| 187 EXPECT_EQ("My first file data", file1.title()); | |
| 188 EXPECT_EQ("application/octet-stream", file1.mime_type()); | |
| 189 | |
| 190 base::Time modified_time; | |
| 191 ASSERT_TRUE(gdata::util::GetTimeFromString("2012-07-27T05:43:20.269Z", | |
| 192 &modified_time)); | |
| 193 EXPECT_EQ(modified_time, file1.modified_by_me_date()); | |
| 194 EXPECT_EQ(GURL("https://www.example.com/download"), file1.download_url()); | |
| 195 EXPECT_EQ("ext", file1.file_extension()); | |
| 196 EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", file1.md5_checksum()); | |
| 197 EXPECT_EQ(1000U, file1.file_size()); | |
| 198 | |
| 199 // Check file 2 (a Google Document) | |
| 200 const FileResource& file2 = *filelist->items()[1]; | |
| 201 EXPECT_EQ("Test Google Document", file2.title()); | |
| 202 EXPECT_EQ("application/vnd.google-apps.document", file2.mime_type()); | |
| 203 EXPECT_EQ(0U, file2.file_size()); | |
| 204 | |
| 205 // Check file 3 (a folder) | |
| 206 const FileResource& file3 = *filelist->items()[2]; | |
| 207 EXPECT_EQ(0U, file3.file_size()); | |
| 208 EXPECT_EQ("TestFolder", file3.title()); | |
| 209 EXPECT_EQ("application/vnd.google-apps.folder", file3.mime_type()); | |
| 210 ASSERT_TRUE(file3.IsFolder()); | |
| 211 } | |
| 212 } | |
| 213 | |
| 158 } // namespace gdata | 214 } // namespace gdata |
| OLD | NEW |