Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / google_apis / drive / drive_api_url_generator_unittest.cc
blob557a0af3f821197a3dec29ad3fe54dc12e427a1e
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
3 // found in the LICENSE file.
5 #include "google_apis/drive/drive_api_url_generator.h"
7 #include "google_apis/drive/test_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
11 namespace google_apis {
13 class DriveApiUrlGeneratorTest : public testing::Test {
14 public:
15 DriveApiUrlGeneratorTest()
16 : url_generator_(
17 GURL(DriveApiUrlGenerator::kBaseUrlForProduction),
18 GURL(DriveApiUrlGenerator::kBaseDownloadUrlForProduction)),
19 test_url_generator_(
20 test_util::GetBaseUrlForTesting(12345),
21 test_util::GetBaseUrlForTesting(12345).Resolve("download/")) {
24 protected:
25 DriveApiUrlGenerator url_generator_;
26 DriveApiUrlGenerator test_url_generator_;
29 // Make sure the hard-coded urls are returned.
30 TEST_F(DriveApiUrlGeneratorTest, GetAboutGetUrl) {
31 EXPECT_EQ("https://www.googleapis.com/drive/v2/about",
32 url_generator_.GetAboutGetUrl().spec());
33 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/about",
34 test_url_generator_.GetAboutGetUrl().spec());
37 TEST_F(DriveApiUrlGeneratorTest, GetAppsListUrl) {
38 const bool use_internal_url = true;
39 EXPECT_EQ("https://www.googleapis.com/drive/v2internal/apps",
40 url_generator_.GetAppsListUrl(use_internal_url).spec());
41 EXPECT_EQ("https://www.googleapis.com/drive/v2/apps",
42 url_generator_.GetAppsListUrl(!use_internal_url).spec());
43 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/apps",
44 test_url_generator_.GetAppsListUrl(!use_internal_url).spec());
47 TEST_F(DriveApiUrlGeneratorTest, GetAppsDeleteUrl) {
48 EXPECT_EQ("https://www.googleapis.com/drive/v2internal/apps/0ADK06pfg",
49 url_generator_.GetAppsDeleteUrl("0ADK06pfg").spec());
50 EXPECT_EQ("http://127.0.0.1:12345/drive/v2internal/apps/0ADK06pfg",
51 test_url_generator_.GetAppsDeleteUrl("0ADK06pfg").spec());
54 TEST_F(DriveApiUrlGeneratorTest, GetFilesGetUrl) {
55 // |file_id| should be embedded into the url.
56 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg",
57 url_generator_.GetFilesGetUrl("0ADK06pfg").spec());
58 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074",
59 url_generator_.GetFilesGetUrl("0Bz0bd074").spec());
60 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id",
61 url_generator_.GetFilesGetUrl("file:file_id").spec());
63 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg",
64 test_url_generator_.GetFilesGetUrl("0ADK06pfg").spec());
65 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074",
66 test_url_generator_.GetFilesGetUrl("0Bz0bd074").spec());
67 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id",
68 test_url_generator_.GetFilesGetUrl("file:file_id").spec());
71 TEST_F(DriveApiUrlGeneratorTest, GetFilesAuthorizeUrl) {
72 EXPECT_EQ(
73 "https://www.googleapis.com/drive/v2internal/files/aa/authorize?appId=bb",
74 url_generator_.GetFilesAuthorizeUrl("aa", "bb").spec());
75 EXPECT_EQ(
76 "http://127.0.0.1:12345/drive/v2internal/files/foo/authorize?appId=bar",
77 test_url_generator_.GetFilesAuthorizeUrl("foo", "bar").spec());
80 TEST_F(DriveApiUrlGeneratorTest, GetFilesInsertUrl) {
81 EXPECT_EQ("https://www.googleapis.com/drive/v2/files",
82 url_generator_.GetFilesInsertUrl().spec());
83 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files",
84 test_url_generator_.GetFilesInsertUrl().spec());
87 TEST_F(DriveApiUrlGeneratorTest, GetFilePatchUrl) {
88 struct TestPattern {
89 bool set_modified_date;
90 bool update_viewed_date;
91 const std::string expected_query;
93 const TestPattern kTestPatterns[] = {
94 { false, true, "" },
95 { true, true, "?setModifiedDate=true" },
96 { false, false, "?updateViewedDate=false" },
97 { true, false, "?setModifiedDate=true&updateViewedDate=false" },
100 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) {
101 EXPECT_EQ(
102 "https://www.googleapis.com/drive/v2/files/0ADK06pfg" +
103 kTestPatterns[i].expected_query,
104 url_generator_.GetFilesPatchUrl(
105 "0ADK06pfg",
106 kTestPatterns[i].set_modified_date,
107 kTestPatterns[i].update_viewed_date).spec());
109 EXPECT_EQ(
110 "https://www.googleapis.com/drive/v2/files/0Bz0bd074" +
111 kTestPatterns[i].expected_query,
112 url_generator_.GetFilesPatchUrl(
113 "0Bz0bd074",
114 kTestPatterns[i].set_modified_date,
115 kTestPatterns[i].update_viewed_date).spec());
117 EXPECT_EQ(
118 "https://www.googleapis.com/drive/v2/files/file%3Afile_id" +
119 kTestPatterns[i].expected_query,
120 url_generator_.GetFilesPatchUrl(
121 "file:file_id",
122 kTestPatterns[i].set_modified_date,
123 kTestPatterns[i].update_viewed_date).spec());
126 EXPECT_EQ(
127 "http://127.0.0.1:12345/drive/v2/files/0ADK06pfg" +
128 kTestPatterns[i].expected_query,
129 test_url_generator_.GetFilesPatchUrl(
130 "0ADK06pfg",
131 kTestPatterns[i].set_modified_date,
132 kTestPatterns[i].update_viewed_date).spec());
134 EXPECT_EQ(
135 "http://127.0.0.1:12345/drive/v2/files/0Bz0bd074" +
136 kTestPatterns[i].expected_query,
137 test_url_generator_.GetFilesPatchUrl(
138 "0Bz0bd074",
139 kTestPatterns[i].set_modified_date,
140 kTestPatterns[i].update_viewed_date).spec());
142 EXPECT_EQ(
143 "http://127.0.0.1:12345/drive/v2/files/file%3Afile_id" +
144 kTestPatterns[i].expected_query,
145 test_url_generator_.GetFilesPatchUrl(
146 "file:file_id",
147 kTestPatterns[i].set_modified_date,
148 kTestPatterns[i].update_viewed_date).spec());
152 TEST_F(DriveApiUrlGeneratorTest, GetFilesCopyUrl) {
153 // |file_id| should be embedded into the url.
154 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/copy",
155 url_generator_.GetFilesCopyUrl("0ADK06pfg").spec());
156 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/copy",
157 url_generator_.GetFilesCopyUrl("0Bz0bd074").spec());
158 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id/copy",
159 url_generator_.GetFilesCopyUrl("file:file_id").spec());
161 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/copy",
162 test_url_generator_.GetFilesCopyUrl("0ADK06pfg").spec());
163 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/copy",
164 test_url_generator_.GetFilesCopyUrl("0Bz0bd074").spec());
165 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id/copy",
166 test_url_generator_.GetFilesCopyUrl("file:file_id").spec());
169 TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) {
170 struct TestPattern {
171 int max_results;
172 const std::string page_token;
173 const std::string q;
174 const std::string expected_query;
176 const TestPattern kTestPatterns[] = {
177 { 100, "", "", "" },
178 { 150, "", "", "?maxResults=150" },
179 { 10, "", "", "?maxResults=10" },
180 { 100, "token", "", "?pageToken=token" },
181 { 150, "token", "", "?maxResults=150&pageToken=token" },
182 { 10, "token", "", "?maxResults=10&pageToken=token" },
183 { 100, "", "query", "?q=query" },
184 { 150, "", "query", "?maxResults=150&q=query" },
185 { 10, "", "query", "?maxResults=10&q=query" },
186 { 100, "token", "query", "?pageToken=token&q=query" },
187 { 150, "token", "query", "?maxResults=150&pageToken=token&q=query" },
188 { 10, "token", "query", "?maxResults=10&pageToken=token&q=query" },
191 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) {
192 EXPECT_EQ(
193 "https://www.googleapis.com/drive/v2/files" +
194 kTestPatterns[i].expected_query,
195 url_generator_.GetFilesListUrl(
196 kTestPatterns[i].max_results, kTestPatterns[i].page_token,
197 kTestPatterns[i].q).spec());
199 EXPECT_EQ(
200 "http://127.0.0.1:12345/drive/v2/files" +
201 kTestPatterns[i].expected_query,
202 test_url_generator_.GetFilesListUrl(
203 kTestPatterns[i].max_results, kTestPatterns[i].page_token,
204 kTestPatterns[i].q).spec());
208 TEST_F(DriveApiUrlGeneratorTest, GetFilesDeleteUrl) {
209 // |file_id| should be embedded into the url.
210 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg",
211 url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec());
212 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074",
213 url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec());
214 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id",
215 url_generator_.GetFilesDeleteUrl("file:file_id").spec());
217 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg",
218 test_url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec());
219 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074",
220 test_url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec());
221 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id",
222 test_url_generator_.GetFilesDeleteUrl("file:file_id").spec());
225 TEST_F(DriveApiUrlGeneratorTest, GetFilesTrashUrl) {
226 // |file_id| should be embedded into the url.
227 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/trash",
228 url_generator_.GetFilesTrashUrl("0ADK06pfg").spec());
229 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/trash",
230 url_generator_.GetFilesTrashUrl("0Bz0bd074").spec());
231 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id/trash",
232 url_generator_.GetFilesTrashUrl("file:file_id").spec());
234 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/trash",
235 test_url_generator_.GetFilesTrashUrl("0ADK06pfg").spec());
236 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/trash",
237 test_url_generator_.GetFilesTrashUrl("0Bz0bd074").spec());
238 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id/trash",
239 test_url_generator_.GetFilesTrashUrl("file:file_id").spec());
242 TEST_F(DriveApiUrlGeneratorTest, GetChangesListUrl) {
243 struct TestPattern {
244 bool include_deleted;
245 int max_results;
246 const std::string page_token;
247 int64 start_change_id;
248 const std::string expected_query;
250 const TestPattern kTestPatterns[] = {
251 { true, 100, "", 0, "" },
252 { false, 100, "", 0, "?includeDeleted=false" },
253 { true, 150, "", 0, "?maxResults=150" },
254 { false, 150, "", 0, "?includeDeleted=false&maxResults=150" },
255 { true, 10, "", 0, "?maxResults=10" },
256 { false, 10, "", 0, "?includeDeleted=false&maxResults=10" },
258 { true, 100, "token", 0, "?pageToken=token" },
259 { false, 100, "token", 0, "?includeDeleted=false&pageToken=token" },
260 { true, 150, "token", 0, "?maxResults=150&pageToken=token" },
261 { false, 150, "token", 0,
262 "?includeDeleted=false&maxResults=150&pageToken=token" },
263 { true, 10, "token", 0, "?maxResults=10&pageToken=token" },
264 { false, 10, "token", 0,
265 "?includeDeleted=false&maxResults=10&pageToken=token" },
267 { true, 100, "", 12345, "?startChangeId=12345" },
268 { false, 100, "", 12345, "?includeDeleted=false&startChangeId=12345" },
269 { true, 150, "", 12345, "?maxResults=150&startChangeId=12345" },
270 { false, 150, "", 12345,
271 "?includeDeleted=false&maxResults=150&startChangeId=12345" },
272 { true, 10, "", 12345, "?maxResults=10&startChangeId=12345" },
273 { false, 10, "", 12345,
274 "?includeDeleted=false&maxResults=10&startChangeId=12345" },
276 { true, 100, "token", 12345, "?pageToken=token&startChangeId=12345" },
277 { false, 100, "token", 12345,
278 "?includeDeleted=false&pageToken=token&startChangeId=12345" },
279 { true, 150, "token", 12345,
280 "?maxResults=150&pageToken=token&startChangeId=12345" },
281 { false, 150, "token", 12345,
282 "?includeDeleted=false&maxResults=150&pageToken=token"
283 "&startChangeId=12345" },
284 { true, 10, "token", 12345,
285 "?maxResults=10&pageToken=token&startChangeId=12345" },
286 { false, 10, "token", 12345,
287 "?includeDeleted=false&maxResults=10&pageToken=token"
288 "&startChangeId=12345" },
291 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestPatterns); ++i) {
292 EXPECT_EQ(
293 "https://www.googleapis.com/drive/v2/changes" +
294 kTestPatterns[i].expected_query,
295 url_generator_.GetChangesListUrl(
296 kTestPatterns[i].include_deleted,
297 kTestPatterns[i].max_results,
298 kTestPatterns[i].page_token,
299 kTestPatterns[i].start_change_id).spec());
301 EXPECT_EQ(
302 "http://127.0.0.1:12345/drive/v2/changes" +
303 kTestPatterns[i].expected_query,
304 test_url_generator_.GetChangesListUrl(
305 kTestPatterns[i].include_deleted,
306 kTestPatterns[i].max_results,
307 kTestPatterns[i].page_token,
308 kTestPatterns[i].start_change_id).spec());
312 TEST_F(DriveApiUrlGeneratorTest, GetChildrenInsertUrl) {
313 // |file_id| should be embedded into the url.
314 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/children",
315 url_generator_.GetChildrenInsertUrl("0ADK06pfg").spec());
316 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/children",
317 url_generator_.GetChildrenInsertUrl("0Bz0bd074").spec());
318 EXPECT_EQ(
319 "https://www.googleapis.com/drive/v2/files/file%3Afolder_id/children",
320 url_generator_.GetChildrenInsertUrl("file:folder_id").spec());
322 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/children",
323 test_url_generator_.GetChildrenInsertUrl("0ADK06pfg").spec());
324 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/children",
325 test_url_generator_.GetChildrenInsertUrl("0Bz0bd074").spec());
326 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afolder_id/children",
327 test_url_generator_.GetChildrenInsertUrl("file:folder_id").spec());
330 TEST_F(DriveApiUrlGeneratorTest, GetChildrenDeleteUrl) {
331 // |file_id| should be embedded into the url.
332 EXPECT_EQ(
333 "https://www.googleapis.com/drive/v2/files/0ADK06pfg/children/0Bz0bd074",
334 url_generator_.GetChildrenDeleteUrl("0Bz0bd074", "0ADK06pfg").spec());
335 EXPECT_EQ(
336 "https://www.googleapis.com/drive/v2/files/0Bz0bd074/children/0ADK06pfg",
337 url_generator_.GetChildrenDeleteUrl("0ADK06pfg", "0Bz0bd074").spec());
338 EXPECT_EQ(
339 "https://www.googleapis.com/drive/v2/files/file%3Afolder_id/children"
340 "/file%3Achild_id",
341 url_generator_.GetChildrenDeleteUrl(
342 "file:child_id", "file:folder_id").spec());
344 EXPECT_EQ(
345 "http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/children/0Bz0bd074",
346 test_url_generator_.GetChildrenDeleteUrl(
347 "0Bz0bd074", "0ADK06pfg").spec());
348 EXPECT_EQ(
349 "http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/children/0ADK06pfg",
350 test_url_generator_.GetChildrenDeleteUrl(
351 "0ADK06pfg", "0Bz0bd074").spec());
352 EXPECT_EQ(
353 "http://127.0.0.1:12345/drive/v2/files/file%3Afolder_id/children/"
354 "file%3Achild_id",
355 test_url_generator_.GetChildrenDeleteUrl(
356 "file:child_id", "file:folder_id").spec());
359 TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadNewFileUrl) {
360 const bool kSetModifiedDate = true;
362 EXPECT_EQ(
363 "https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable",
364 url_generator_.GetInitiateUploadNewFileUrl(!kSetModifiedDate).spec());
366 EXPECT_EQ(
367 "http://127.0.0.1:12345/upload/drive/v2/files?uploadType=resumable",
368 test_url_generator_.GetInitiateUploadNewFileUrl(
369 !kSetModifiedDate).spec());
371 EXPECT_EQ(
372 "http://127.0.0.1:12345/upload/drive/v2/files?uploadType=resumable&"
373 "setModifiedDate=true",
374 test_url_generator_.GetInitiateUploadNewFileUrl(
375 kSetModifiedDate).spec());
378 TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadExistingFileUrl) {
379 const bool kSetModifiedDate = true;
381 // |resource_id| should be embedded into the url.
382 EXPECT_EQ(
383 "https://www.googleapis.com/upload/drive/v2/files/0ADK06pfg"
384 "?uploadType=resumable",
385 url_generator_.GetInitiateUploadExistingFileUrl(
386 "0ADK06pfg", !kSetModifiedDate).spec());
387 EXPECT_EQ(
388 "https://www.googleapis.com/upload/drive/v2/files/0Bz0bd074"
389 "?uploadType=resumable",
390 url_generator_.GetInitiateUploadExistingFileUrl(
391 "0Bz0bd074", !kSetModifiedDate).spec());
392 EXPECT_EQ(
393 "https://www.googleapis.com/upload/drive/v2/files/file%3Afile_id"
394 "?uploadType=resumable",
395 url_generator_.GetInitiateUploadExistingFileUrl(
396 "file:file_id", !kSetModifiedDate).spec());
397 EXPECT_EQ(
398 "https://www.googleapis.com/upload/drive/v2/files/file%3Afile_id"
399 "?uploadType=resumable&setModifiedDate=true",
400 url_generator_.GetInitiateUploadExistingFileUrl(
401 "file:file_id", kSetModifiedDate).spec());
403 EXPECT_EQ(
404 "http://127.0.0.1:12345/upload/drive/v2/files/0ADK06pfg"
405 "?uploadType=resumable",
406 test_url_generator_.GetInitiateUploadExistingFileUrl(
407 "0ADK06pfg", !kSetModifiedDate).spec());
408 EXPECT_EQ(
409 "http://127.0.0.1:12345/upload/drive/v2/files/0Bz0bd074"
410 "?uploadType=resumable",
411 test_url_generator_.GetInitiateUploadExistingFileUrl(
412 "0Bz0bd074", !kSetModifiedDate).spec());
413 EXPECT_EQ(
414 "http://127.0.0.1:12345/upload/drive/v2/files/file%3Afile_id"
415 "?uploadType=resumable",
416 test_url_generator_.GetInitiateUploadExistingFileUrl(
417 "file:file_id", !kSetModifiedDate).spec());
418 EXPECT_EQ(
419 "http://127.0.0.1:12345/upload/drive/v2/files/file%3Afile_id"
420 "?uploadType=resumable&setModifiedDate=true",
421 test_url_generator_.GetInitiateUploadExistingFileUrl(
422 "file:file_id", kSetModifiedDate).spec());
425 TEST_F(DriveApiUrlGeneratorTest, GenerateDownloadFileUrl) {
426 EXPECT_EQ(
427 "https://www.googledrive.com/host/resourceId",
428 url_generator_.GenerateDownloadFileUrl("resourceId").spec());
429 EXPECT_EQ(
430 "https://www.googledrive.com/host/file%3AresourceId",
431 url_generator_.GenerateDownloadFileUrl("file:resourceId").spec());
432 EXPECT_EQ(
433 "http://127.0.0.1:12345/download/resourceId",
434 test_url_generator_.GenerateDownloadFileUrl("resourceId").spec());
437 TEST_F(DriveApiUrlGeneratorTest, GeneratePermissionsInsertUrl) {
438 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/permissions",
439 url_generator_.GetPermissionsInsertUrl("0ADK06pfg").spec());
440 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Aabc/permissions",
441 test_url_generator_.GetPermissionsInsertUrl("file:abc").spec());
444 } // namespace google_apis