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