Fix build break
[chromium-blink-merge.git] / chrome / browser / google_apis / drive_api_url_generator_unittest.cc
bloba8dbd340e612d6f07bbbb46f2d562997687dc2a8
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 "chrome/browser/google_apis/drive_api_url_generator.h"
7 #include "chrome/browser/google_apis/test_util.h"
8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace google_apis {
13 class DriveApiUrlGeneratorTest : public testing::Test {
14 public:
15 DriveApiUrlGeneratorTest()
16 : url_generator_(GURL(DriveApiUrlGenerator::kBaseUrlForProduction)),
17 test_url_generator_(test_util::GetBaseUrlForTesting(12345)) {
20 protected:
21 DriveApiUrlGenerator url_generator_;
22 DriveApiUrlGenerator test_url_generator_;
25 // Make sure the hard-coded urls are returned.
26 TEST_F(DriveApiUrlGeneratorTest, GetAboutUrl) {
27 EXPECT_EQ("https://www.googleapis.com/drive/v2/about",
28 url_generator_.GetAboutUrl().spec());
29 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/about",
30 test_url_generator_.GetAboutUrl().spec());
33 TEST_F(DriveApiUrlGeneratorTest, GetApplistUrl) {
34 EXPECT_EQ("https://www.googleapis.com/drive/v2/apps",
35 url_generator_.GetApplistUrl().spec());
36 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/apps",
37 test_url_generator_.GetApplistUrl().spec());
40 TEST_F(DriveApiUrlGeneratorTest, GetChangelistUrl) {
41 // Do not add startChangeId parameter if |start_changestamp| is 0.
42 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes",
43 url_generator_.GetChangelistUrl(true, 0).spec());
44 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/changes",
45 test_url_generator_.GetChangelistUrl(true, 0).spec());
47 // Set includeDeleted parameter if |include_deleted| is set to false.
48 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes?includeDeleted=false",
49 url_generator_.GetChangelistUrl(false, 0).spec());
50 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/changes?includeDeleted=false",
51 test_url_generator_.GetChangelistUrl(false, 0).spec());
53 // Set startChangeId parameter if |start_changestamp| is given.
54 EXPECT_EQ("https://www.googleapis.com/drive/v2/changes?startChangeId=100",
55 url_generator_.GetChangelistUrl(true, 100).spec());
56 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/changes?startChangeId=100",
57 test_url_generator_.GetChangelistUrl(true, 100).spec());
59 // includeDeleted and startChangeId parameter can be set at the same time.
60 EXPECT_EQ(
61 "https://www.googleapis.com/drive/v2/changes"
62 "?includeDeleted=false&startChangeId=100",
63 url_generator_.GetChangelistUrl(false, 100).spec());
64 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/changes?"
65 "includeDeleted=false&startChangeId=100",
66 test_url_generator_.GetChangelistUrl(false, 100).spec());
69 TEST_F(DriveApiUrlGeneratorTest, GetFilelistUrl) {
70 // Do not add q parameter if |search_string| is empty.
71 EXPECT_EQ("https://www.googleapis.com/drive/v2/files",
72 url_generator_.GetFilelistUrl(std::string()).spec());
73 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files",
74 test_url_generator_.GetFilelistUrl(std::string()).spec());
76 // Set q parameter if non-empty |search_string| is given.
77 EXPECT_EQ("https://www.googleapis.com/drive/v2/files?q=query",
78 url_generator_.GetFilelistUrl("query").spec());
79 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files?q=query",
80 test_url_generator_.GetFilelistUrl("query").spec());
83 TEST_F(DriveApiUrlGeneratorTest, GetFileUrl) {
84 // |file_id| should be embedded into the url.
85 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg",
86 url_generator_.GetFileUrl("0ADK06pfg").spec());
87 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074",
88 url_generator_.GetFileUrl("0Bz0bd074").spec());
89 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id",
90 url_generator_.GetFileUrl("file:file_id").spec());
92 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg",
93 test_url_generator_.GetFileUrl("0ADK06pfg").spec());
94 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074",
95 test_url_generator_.GetFileUrl("0Bz0bd074").spec());
96 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id",
97 test_url_generator_.GetFileUrl("file:file_id").spec());
100 TEST_F(DriveApiUrlGeneratorTest, GetFileCopyUrl) {
101 // |file_id| should be embedded into the url.
102 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/copy",
103 url_generator_.GetFileCopyUrl("0ADK06pfg").spec());
104 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/copy",
105 url_generator_.GetFileCopyUrl("0Bz0bd074").spec());
106 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id/copy",
107 url_generator_.GetFileCopyUrl("file:file_id").spec());
109 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/copy",
110 test_url_generator_.GetFileCopyUrl("0ADK06pfg").spec());
111 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/copy",
112 test_url_generator_.GetFileCopyUrl("0Bz0bd074").spec());
113 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id/copy",
114 test_url_generator_.GetFileCopyUrl("file:file_id").spec());
117 TEST_F(DriveApiUrlGeneratorTest, GetChildrenUrl) {
118 // |file_id| should be embedded into the url.
119 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/children",
120 url_generator_.GetChildrenUrl("0ADK06pfg").spec());
121 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/children",
122 url_generator_.GetChildrenUrl("0Bz0bd074").spec());
123 EXPECT_EQ(
124 "https://www.googleapis.com/drive/v2/files/file%3Afolder_id/children",
125 url_generator_.GetChildrenUrl("file:folder_id").spec());
127 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/children",
128 test_url_generator_.GetChildrenUrl("0ADK06pfg").spec());
129 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/children",
130 test_url_generator_.GetChildrenUrl("0Bz0bd074").spec());
131 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afolder_id/children",
132 test_url_generator_.GetChildrenUrl("file:folder_id").spec());
135 TEST_F(DriveApiUrlGeneratorTest, GetChildrenUrlForRemoval) {
136 // |file_id| should be embedded into the url.
137 EXPECT_EQ(
138 "https://www.googleapis.com/drive/v2/files/0ADK06pfg/children/0Bz0bd074",
139 url_generator_.GetChildrenUrlForRemoval(
140 "0ADK06pfg", "0Bz0bd074").spec());
141 EXPECT_EQ(
142 "https://www.googleapis.com/drive/v2/files/0Bz0bd074/children/0ADK06pfg",
143 url_generator_.GetChildrenUrlForRemoval(
144 "0Bz0bd074", "0ADK06pfg").spec());
145 EXPECT_EQ(
146 "https://www.googleapis.com/drive/v2/files/file%3Afolder_id/children"
147 "/file%3Achild_id",
148 url_generator_.GetChildrenUrlForRemoval(
149 "file:folder_id", "file:child_id").spec());
151 EXPECT_EQ(
152 "http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/children/0Bz0bd074",
153 test_url_generator_.GetChildrenUrlForRemoval(
154 "0ADK06pfg", "0Bz0bd074").spec());
155 EXPECT_EQ(
156 "http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/children/0ADK06pfg",
157 test_url_generator_.GetChildrenUrlForRemoval(
158 "0Bz0bd074", "0ADK06pfg").spec());
159 EXPECT_EQ(
160 "http://127.0.0.1:12345/drive/v2/files/file%3Afolder_id/children/"
161 "file%3Achild_id",
162 test_url_generator_.GetChildrenUrlForRemoval(
163 "file:folder_id", "file:child_id").spec());
166 TEST_F(DriveApiUrlGeneratorTest, GetFileTrashUrl) {
167 // |file_id| should be embedded into the url.
168 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0ADK06pfg/trash",
169 url_generator_.GetFileTrashUrl("0ADK06pfg").spec());
170 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074/trash",
171 url_generator_.GetFileTrashUrl("0Bz0bd074").spec());
172 EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id/trash",
173 url_generator_.GetFileTrashUrl("file:file_id").spec());
175 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg/trash",
176 test_url_generator_.GetFileTrashUrl("0ADK06pfg").spec());
177 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074/trash",
178 test_url_generator_.GetFileTrashUrl("0Bz0bd074").spec());
179 EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id/trash",
180 test_url_generator_.GetFileTrashUrl("file:file_id").spec());
183 TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadNewFileUrl) {
184 EXPECT_EQ(
185 "https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable",
186 url_generator_.GetInitiateUploadNewFileUrl().spec());
188 EXPECT_EQ(
189 "http://127.0.0.1:12345/upload/drive/v2/files?uploadType=resumable",
190 test_url_generator_.GetInitiateUploadNewFileUrl().spec());
193 TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadExistingFileUrl) {
194 // |resource_id| should be embedded into the url.
195 EXPECT_EQ(
196 "https://www.googleapis.com/upload/drive/v2/files/0ADK06pfg"
197 "?uploadType=resumable",
198 url_generator_.GetInitiateUploadExistingFileUrl("0ADK06pfg").spec());
199 EXPECT_EQ(
200 "https://www.googleapis.com/upload/drive/v2/files/0Bz0bd074"
201 "?uploadType=resumable",
202 url_generator_.GetInitiateUploadExistingFileUrl("0Bz0bd074").spec());
203 EXPECT_EQ(
204 "https://www.googleapis.com/upload/drive/v2/files/file%3Afile_id"
205 "?uploadType=resumable",
206 url_generator_.GetInitiateUploadExistingFileUrl("file:file_id").spec());
208 EXPECT_EQ(
209 "http://127.0.0.1:12345/upload/drive/v2/files/0ADK06pfg"
210 "?uploadType=resumable",
211 test_url_generator_.GetInitiateUploadExistingFileUrl(
212 "0ADK06pfg").spec());
213 EXPECT_EQ(
214 "http://127.0.0.1:12345/upload/drive/v2/files/0Bz0bd074"
215 "?uploadType=resumable",
216 test_url_generator_.GetInitiateUploadExistingFileUrl(
217 "0Bz0bd074").spec());
218 EXPECT_EQ(
219 "http://127.0.0.1:12345/upload/drive/v2/files/file%3Afile_id"
220 "?uploadType=resumable",
221 test_url_generator_.GetInitiateUploadExistingFileUrl(
222 "file:file_id").spec());
225 } // namespace google_apis