Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "google_apis/drive/drive_api_url_generator.h" | 5 #include "google_apis/drive/drive_api_url_generator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "google_apis/drive/test_util.h" | 11 #include "google_apis/drive/test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 #include "url/url_util.h" | 14 #include "url/url_util.h" |
| 15 | 15 |
| 16 namespace google_apis { | 16 namespace google_apis { |
| 17 namespace { | 17 namespace { |
| 18 // The URLs used for production may be different for Chromium OS and Chrome | 18 // The URLs used for production may be different for Chromium OS and Chrome |
| 19 // OS, so use testing base urls. | 19 // OS, so use testing base urls. |
| 20 const char kBaseUrlForTesting[] = "https://www.example.com"; | 20 const char kBaseUrlForTesting[] = "https://www.example.com"; |
| 21 const char kBaseThumbnailUrlForTesting[] = "https://thumbnail.example.com"; | 21 const char kBaseThumbnailUrlForTesting[] = "https://thumbnail.example.com"; |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 class DriveApiUrlGeneratorTest : public testing::Test { | 24 class DriveApiUrlGeneratorTest : public testing::Test { |
| 25 public: | 25 public: |
| 26 DriveApiUrlGeneratorTest() | 26 DriveApiUrlGeneratorTest() |
| 27 : url_generator_(GURL(kBaseUrlForTesting), | 27 : url_generator_(GURL(kBaseUrlForTesting), |
| 28 GURL(kBaseThumbnailUrlForTesting)) {} | 28 GURL(kBaseThumbnailUrlForTesting), false), |
| 29 team_drives_url_generator_(GURL(kBaseUrlForTesting), | |
| 30 GURL(kBaseThumbnailUrlForTesting), true) {} | |
| 29 | 31 |
| 30 protected: | 32 protected: |
| 31 DriveApiUrlGenerator url_generator_; | 33 DriveApiUrlGenerator url_generator_; |
| 34 DriveApiUrlGenerator team_drives_url_generator_; | |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 // Make sure the hard-coded urls are returned. | 37 // Make sure the hard-coded urls are returned. |
| 35 TEST_F(DriveApiUrlGeneratorTest, GetAboutGetUrl) { | 38 TEST_F(DriveApiUrlGeneratorTest, GetAboutGetUrl) { |
| 36 EXPECT_EQ("https://www.example.com/drive/v2/about", | 39 EXPECT_EQ("https://www.example.com/drive/v2/about", |
| 37 url_generator_.GetAboutGetUrl().spec()); | 40 url_generator_.GetAboutGetUrl().spec()); |
| 38 } | 41 } |
| 39 | 42 |
| 40 TEST_F(DriveApiUrlGeneratorTest, GetAppsListUrl) { | 43 TEST_F(DriveApiUrlGeneratorTest, GetAppsListUrl) { |
| 41 const bool use_internal_url = true; | 44 const bool use_internal_url = true; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 52 | 55 |
| 53 TEST_F(DriveApiUrlGeneratorTest, GetFilesGetUrl) { | 56 TEST_F(DriveApiUrlGeneratorTest, GetFilesGetUrl) { |
| 54 // |file_id| should be embedded into the url. | 57 // |file_id| should be embedded into the url. |
| 55 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg", | 58 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg", |
| 56 url_generator_.GetFilesGetUrl("0ADK06pfg", false, GURL()).spec()); | 59 url_generator_.GetFilesGetUrl("0ADK06pfg", false, GURL()).spec()); |
| 57 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074", | 60 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074", |
| 58 url_generator_.GetFilesGetUrl("0Bz0bd074", false, GURL()).spec()); | 61 url_generator_.GetFilesGetUrl("0Bz0bd074", false, GURL()).spec()); |
| 59 EXPECT_EQ( | 62 EXPECT_EQ( |
| 60 "https://www.example.com/drive/v2/files/file%3Afile_id", | 63 "https://www.example.com/drive/v2/files/file%3Afile_id", |
| 61 url_generator_.GetFilesGetUrl("file:file_id", false, GURL()).spec()); | 64 url_generator_.GetFilesGetUrl("file:file_id", false, GURL()).spec()); |
| 65 EXPECT_EQ("https://www.example.com/drive/v2beta/files/0Bz0bd074" | |
| 66 "?supportsTeamDrives=true", | |
| 67 team_drives_url_generator_.GetFilesGetUrl( | |
| 68 "0Bz0bd074", false, GURL()).spec()); | |
| 62 | 69 |
| 63 // If |use_internal_endpoint| is true, the generated url should point to the | 70 // If |use_internal_endpoint| is true, the generated url should point to the |
| 64 // v2internal. | 71 // v2internal. |
| 65 EXPECT_EQ("https://www.example.com/drive/v2internal/files/0ADK06pfg", | 72 EXPECT_EQ("https://www.example.com/drive/v2internal/files/0ADK06pfg", |
| 66 url_generator_.GetFilesGetUrl("0ADK06pfg", true, GURL()).spec()); | 73 url_generator_.GetFilesGetUrl("0ADK06pfg", true, GURL()).spec()); |
| 67 | 74 |
| 68 // If |embed_origin| is not empty, it should be added as a query parameter. | 75 // If |embed_origin| is not empty, it should be added as a query parameter. |
| 69 url::AddStandardScheme("chrome-extension", url::SCHEME_WITHOUT_PORT); | 76 url::AddStandardScheme("chrome-extension", url::SCHEME_WITHOUT_PORT); |
| 70 EXPECT_EQ( | 77 EXPECT_EQ( |
| 71 "https://www.example.com/drive/v2/files/0ADK06pfg" | 78 "https://www.example.com/drive/v2/files/0ADK06pfg" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 156 |
| 150 TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) { | 157 TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) { |
| 151 struct TestPattern { | 158 struct TestPattern { |
| 152 int max_results; | 159 int max_results; |
| 153 const std::string page_token; | 160 const std::string page_token; |
| 154 const std::string q; | 161 const std::string q; |
| 155 const std::string expected_query; | 162 const std::string expected_query; |
| 156 }; | 163 }; |
| 157 const TestPattern kTestPatterns[] = { | 164 const TestPattern kTestPatterns[] = { |
| 158 { 100, "", "", "" }, | 165 { 100, "", "", "" }, |
| 159 { 150, "", "", "?maxResults=150" }, | 166 { 150, "", "", "maxResults=150" }, |
| 160 { 10, "", "", "?maxResults=10" }, | 167 { 10, "", "", "maxResults=10" }, |
| 161 { 100, "token", "", "?pageToken=token" }, | 168 { 100, "token", "", "pageToken=token" }, |
| 162 { 150, "token", "", "?maxResults=150&pageToken=token" }, | 169 { 150, "token", "", "maxResults=150&pageToken=token" }, |
| 163 { 10, "token", "", "?maxResults=10&pageToken=token" }, | 170 { 10, "token", "", "maxResults=10&pageToken=token" }, |
| 164 { 100, "", "query", "?q=query" }, | 171 { 100, "", "query", "q=query" }, |
| 165 { 150, "", "query", "?maxResults=150&q=query" }, | 172 { 150, "", "query", "maxResults=150&q=query" }, |
| 166 { 10, "", "query", "?maxResults=10&q=query" }, | 173 { 10, "", "query", "maxResults=10&q=query" }, |
| 167 { 100, "token", "query", "?pageToken=token&q=query" }, | 174 { 100, "token", "query", "pageToken=token&q=query" }, |
| 168 { 150, "token", "query", "?maxResults=150&pageToken=token&q=query" }, | 175 { 150, "token", "query", "maxResults=150&pageToken=token&q=query" }, |
| 169 { 10, "token", "query", "?maxResults=10&pageToken=token&q=query" }, | 176 { 10, "token", "query", "maxResults=10&pageToken=token&q=query" }, |
| 170 }; | 177 }; |
| 178 const std::string& kV2FilesUrlPrefix = | |
|
hashimoto
2017/02/22 07:04:51
This shouldn't be a reference.
constexpr char[] or
yamaguchi
2017/02/22 08:41:54
Done.
| |
| 179 "https://www.example.com/drive/v2/files"; | |
| 180 const std::string& kV2BetaFilesUrlPrefix = | |
|
hashimoto
2017/02/22 07:04:51
ditto.
yamaguchi
2017/02/22 08:41:54
Done.
| |
| 181 "https://www.example.com/drive/v2beta/files?" | |
| 182 "supportsTeamDrives=true&includeTeamDriveItems=true"; | |
| 171 | 183 |
| 172 for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { | 184 for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { |
| 173 EXPECT_EQ("https://www.example.com/drive/v2/files" + | 185 EXPECT_EQ(kV2FilesUrlPrefix + |
| 186 (kTestPatterns[i].expected_query.empty() ? "" : "?") + | |
| 174 kTestPatterns[i].expected_query, | 187 kTestPatterns[i].expected_query, |
| 175 url_generator_.GetFilesListUrl(kTestPatterns[i].max_results, | 188 url_generator_.GetFilesListUrl(kTestPatterns[i].max_results, |
| 176 kTestPatterns[i].page_token, | 189 kTestPatterns[i].page_token, |
| 177 kTestPatterns[i].q).spec()); | 190 kTestPatterns[i].q).spec()); |
| 191 EXPECT_EQ(kV2BetaFilesUrlPrefix + | |
| 192 (kTestPatterns[i].expected_query.empty() ? "" : "&") + | |
| 193 kTestPatterns[i].expected_query, | |
| 194 team_drives_url_generator_.GetFilesListUrl( | |
| 195 kTestPatterns[i].max_results, | |
| 196 kTestPatterns[i].page_token, | |
| 197 kTestPatterns[i].q).spec()); | |
| 178 } | 198 } |
| 179 } | 199 } |
| 180 | 200 |
| 181 TEST_F(DriveApiUrlGeneratorTest, GetFilesDeleteUrl) { | 201 TEST_F(DriveApiUrlGeneratorTest, GetFilesDeleteUrl) { |
| 182 // |file_id| should be embedded into the url. | 202 // |file_id| should be embedded into the url. |
| 183 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg", | 203 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg", |
| 184 url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec()); | 204 url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec()); |
| 185 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074", | 205 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074", |
| 186 url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec()); | 206 url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec()); |
| 187 EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id", | 207 EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id", |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 201 TEST_F(DriveApiUrlGeneratorTest, GetChangesListUrl) { | 221 TEST_F(DriveApiUrlGeneratorTest, GetChangesListUrl) { |
| 202 struct TestPattern { | 222 struct TestPattern { |
| 203 bool include_deleted; | 223 bool include_deleted; |
| 204 int max_results; | 224 int max_results; |
| 205 const std::string page_token; | 225 const std::string page_token; |
| 206 int64_t start_change_id; | 226 int64_t start_change_id; |
| 207 const std::string expected_query; | 227 const std::string expected_query; |
| 208 }; | 228 }; |
| 209 const TestPattern kTestPatterns[] = { | 229 const TestPattern kTestPatterns[] = { |
| 210 { true, 100, "", 0, "" }, | 230 { true, 100, "", 0, "" }, |
| 211 { false, 100, "", 0, "?includeDeleted=false" }, | 231 { false, 100, "", 0, "includeDeleted=false" }, |
| 212 { true, 150, "", 0, "?maxResults=150" }, | 232 { true, 150, "", 0, "maxResults=150" }, |
| 213 { false, 150, "", 0, "?includeDeleted=false&maxResults=150" }, | 233 { false, 150, "", 0, "includeDeleted=false&maxResults=150" }, |
| 214 { true, 10, "", 0, "?maxResults=10" }, | 234 { true, 10, "", 0, "maxResults=10" }, |
| 215 { false, 10, "", 0, "?includeDeleted=false&maxResults=10" }, | 235 { false, 10, "", 0, "includeDeleted=false&maxResults=10" }, |
| 216 | 236 |
| 217 { true, 100, "token", 0, "?pageToken=token" }, | 237 { true, 100, "token", 0, "pageToken=token" }, |
| 218 { false, 100, "token", 0, "?includeDeleted=false&pageToken=token" }, | 238 { false, 100, "token", 0, "includeDeleted=false&pageToken=token" }, |
| 219 { true, 150, "token", 0, "?maxResults=150&pageToken=token" }, | 239 { true, 150, "token", 0, "maxResults=150&pageToken=token" }, |
| 220 { false, 150, "token", 0, | 240 { false, 150, "token", 0, |
| 221 "?includeDeleted=false&maxResults=150&pageToken=token" }, | 241 "includeDeleted=false&maxResults=150&pageToken=token" }, |
| 222 { true, 10, "token", 0, "?maxResults=10&pageToken=token" }, | 242 { true, 10, "token", 0, "maxResults=10&pageToken=token" }, |
| 223 { false, 10, "token", 0, | 243 { false, 10, "token", 0, |
| 224 "?includeDeleted=false&maxResults=10&pageToken=token" }, | 244 "includeDeleted=false&maxResults=10&pageToken=token" }, |
| 225 | 245 |
| 226 { true, 100, "", 12345, "?startChangeId=12345" }, | 246 { true, 100, "", 12345, "startChangeId=12345" }, |
| 227 { false, 100, "", 12345, "?includeDeleted=false&startChangeId=12345" }, | 247 { false, 100, "", 12345, "includeDeleted=false&startChangeId=12345" }, |
| 228 { true, 150, "", 12345, "?maxResults=150&startChangeId=12345" }, | 248 { true, 150, "", 12345, "maxResults=150&startChangeId=12345" }, |
| 229 { false, 150, "", 12345, | 249 { false, 150, "", 12345, |
| 230 "?includeDeleted=false&maxResults=150&startChangeId=12345" }, | 250 "includeDeleted=false&maxResults=150&startChangeId=12345" }, |
| 231 { true, 10, "", 12345, "?maxResults=10&startChangeId=12345" }, | 251 { true, 10, "", 12345, "maxResults=10&startChangeId=12345" }, |
| 232 { false, 10, "", 12345, | 252 { false, 10, "", 12345, |
| 233 "?includeDeleted=false&maxResults=10&startChangeId=12345" }, | 253 "includeDeleted=false&maxResults=10&startChangeId=12345" }, |
| 234 | 254 |
| 235 { true, 100, "token", 12345, "?pageToken=token&startChangeId=12345" }, | 255 { true, 100, "token", 12345, "pageToken=token&startChangeId=12345" }, |
| 236 { false, 100, "token", 12345, | 256 { false, 100, "token", 12345, |
| 237 "?includeDeleted=false&pageToken=token&startChangeId=12345" }, | 257 "includeDeleted=false&pageToken=token&startChangeId=12345" }, |
| 238 { true, 150, "token", 12345, | 258 { true, 150, "token", 12345, |
| 239 "?maxResults=150&pageToken=token&startChangeId=12345" }, | 259 "maxResults=150&pageToken=token&startChangeId=12345" }, |
| 240 { false, 150, "token", 12345, | 260 { false, 150, "token", 12345, |
| 241 "?includeDeleted=false&maxResults=150&pageToken=token" | 261 "includeDeleted=false&maxResults=150&pageToken=token" |
| 242 "&startChangeId=12345" }, | 262 "&startChangeId=12345" }, |
| 243 { true, 10, "token", 12345, | 263 { true, 10, "token", 12345, |
| 244 "?maxResults=10&pageToken=token&startChangeId=12345" }, | 264 "maxResults=10&pageToken=token&startChangeId=12345" }, |
| 245 { false, 10, "token", 12345, | 265 { false, 10, "token", 12345, |
| 246 "?includeDeleted=false&maxResults=10&pageToken=token" | 266 "includeDeleted=false&maxResults=10&pageToken=token" |
| 247 "&startChangeId=12345" }, | 267 "&startChangeId=12345" }, |
| 248 }; | 268 }; |
| 249 | 269 |
| 270 const std::string& kV2ChangesUrlPrefix = | |
|
hashimoto
2017/02/22 07:04:51
ditto.
yamaguchi
2017/02/22 08:41:54
Done.
| |
| 271 "https://www.example.com/drive/v2/changes"; | |
| 272 const std::string& kV2BetaChangesUrlPrefix = | |
|
hashimoto
2017/02/22 07:04:51
ditto.
yamaguchi
2017/02/22 08:41:54
Done.
| |
| 273 "https://www.example.com/drive/v2beta/changes?" | |
| 274 "supportsTeamDrives=true&includeTeamDriveItems=true"; | |
| 250 for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { | 275 for (size_t i = 0; i < arraysize(kTestPatterns); ++i) { |
| 251 EXPECT_EQ("https://www.example.com/drive/v2/changes" + | 276 EXPECT_EQ(kV2ChangesUrlPrefix + |
| 277 (kTestPatterns[i].expected_query.empty() ? "" : "?") + | |
| 252 kTestPatterns[i].expected_query, | 278 kTestPatterns[i].expected_query, |
| 253 url_generator_.GetChangesListUrl(kTestPatterns[i].include_deleted, | 279 url_generator_.GetChangesListUrl(kTestPatterns[i].include_deleted, |
| 254 kTestPatterns[i].max_results, | 280 kTestPatterns[i].max_results, |
| 255 kTestPatterns[i].page_token, | 281 kTestPatterns[i].page_token, |
| 256 kTestPatterns[i].start_change_id) | 282 kTestPatterns[i].start_change_id) |
| 257 .spec()); | 283 .spec()); |
| 284 EXPECT_EQ(kV2BetaChangesUrlPrefix + | |
| 285 (kTestPatterns[i].expected_query.empty() ? "" : "&") + | |
| 286 kTestPatterns[i].expected_query, | |
| 287 team_drives_url_generator_.GetChangesListUrl( | |
| 288 kTestPatterns[i].include_deleted, | |
| 289 kTestPatterns[i].max_results, | |
| 290 kTestPatterns[i].page_token, | |
| 291 kTestPatterns[i].start_change_id) | |
| 292 .spec()); | |
| 258 } | 293 } |
| 259 } | 294 } |
| 260 | 295 |
| 261 TEST_F(DriveApiUrlGeneratorTest, GetChildrenInsertUrl) { | 296 TEST_F(DriveApiUrlGeneratorTest, GetChildrenInsertUrl) { |
| 262 // |file_id| should be embedded into the url. | 297 // |file_id| should be embedded into the url. |
| 263 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg/children", | 298 EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg/children", |
| 264 url_generator_.GetChildrenInsertUrl("0ADK06pfg").spec()); | 299 url_generator_.GetChildrenInsertUrl("0ADK06pfg").spec()); |
| 265 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074/children", | 300 EXPECT_EQ("https://www.example.com/drive/v2/files/0Bz0bd074/children", |
| 266 url_generator_.GetChildrenInsertUrl("0Bz0bd074").spec()); | 301 url_generator_.GetChildrenInsertUrl("0Bz0bd074").spec()); |
| 267 EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afolder_id/children", | 302 EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afolder_id/children", |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 "https://thumbnail.example.com/d/0ADK06pfg=w360-h380-c", | 417 "https://thumbnail.example.com/d/0ADK06pfg=w360-h380-c", |
| 383 url_generator_.GetThumbnailUrl("0ADK06pfg", 360, 380, true).spec()); | 418 url_generator_.GetThumbnailUrl("0ADK06pfg", 360, 380, true).spec()); |
| 384 } | 419 } |
| 385 | 420 |
| 386 TEST_F(DriveApiUrlGeneratorTest, BatchUploadUrl) { | 421 TEST_F(DriveApiUrlGeneratorTest, BatchUploadUrl) { |
| 387 EXPECT_EQ("https://www.example.com/upload/drive", | 422 EXPECT_EQ("https://www.example.com/upload/drive", |
| 388 url_generator_.GetBatchUploadUrl().spec()); | 423 url_generator_.GetBatchUploadUrl().spec()); |
| 389 } | 424 } |
| 390 | 425 |
| 391 } // namespace google_apis | 426 } // namespace google_apis |
| OLD | NEW |