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
3 // found in the LICENSE file.
5 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace google_apis
{
12 class GDataWapiUrlGeneratorTest
: public testing::Test
{
14 GDataWapiUrlGeneratorTest()
15 : url_generator_(GURL(GDataWapiUrlGenerator::kBaseUrlForProduction
)) {
19 GDataWapiUrlGenerator url_generator_
;
22 TEST_F(GDataWapiUrlGeneratorTest
, AddStandardUrlParams
) {
23 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true",
24 GDataWapiUrlGenerator::AddStandardUrlParams(
25 GURL("http://www.example.com")).spec());
28 TEST_F(GDataWapiUrlGeneratorTest
, AddInitiateUploadUrlParams
) {
29 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true",
30 GDataWapiUrlGenerator::AddInitiateUploadUrlParams(
31 GURL("http://www.example.com")).spec());
34 TEST_F(GDataWapiUrlGeneratorTest
, AddFeedUrlParams
) {
36 "http://www.example.com/?v=3&alt=json&showroot=true&"
38 "&include-shared=true"
40 "&include-installed-apps=true",
41 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
42 100, // num_items_to_fetch
44 std::string() // search_string
47 "http://www.example.com/?v=3&alt=json&showroot=true&"
49 "&include-shared=true"
51 "&include-installed-apps=true"
53 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
54 100, // num_items_to_fetch
56 std::string() // search_string
58 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
60 "&include-shared=true"
62 "&include-installed-apps=true"
65 GDataWapiUrlGenerator::AddFeedUrlParams(
66 GURL("http://www.example.com"),
67 100, // num_items_to_fetch
69 "\"foo bar\"" // search_string
73 TEST_F(GDataWapiUrlGeneratorTest
, GenerateResourceListUrl
) {
74 // This is the very basic URL for the GetResourceList operation.
75 EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
76 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
77 "&max-results=500&include-installed-apps=true",
78 url_generator_
.GenerateResourceListUrl(
79 GURL(), // override_url,
80 0, // start_changestamp,
81 std::string(), // search_string,
82 std::string() // directory resource ID
85 // With an override URL provided, the base URL is changed, but the default
86 // parameters remain as-is.
87 EXPECT_EQ("http://localhost/"
88 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
89 "&max-results=500&include-installed-apps=true",
90 url_generator_
.GenerateResourceListUrl(
91 GURL("http://localhost/"), // override_url,
92 0, // start_changestamp,
93 std::string(), // search_string,
94 std::string() // directory resource ID
97 // With a non-zero start_changestamp provided, the base URL is changed from
98 // "full" to "changes", and "start-index" parameter is added.
99 EXPECT_EQ("https://docs.google.com/feeds/default/private/changes"
100 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
101 "&max-results=500&include-installed-apps=true"
103 url_generator_
.GenerateResourceListUrl(
104 GURL(), // override_url,
105 100, // start_changestamp,
106 std::string(), // search_string,
107 std::string() // directory resource ID
110 // With a non-empty search string provided, "max-results" value is changed,
111 // and "q" parameter is added.
112 EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
113 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
114 "&max-results=50&include-installed-apps=true&q=foo",
115 url_generator_
.GenerateResourceListUrl(
116 GURL(), // override_url,
117 0, // start_changestamp,
118 "foo", // search_string,
119 std::string() // directory resource ID
122 // With a non-empty directory resource ID provided, the base URL is
123 // changed, but the default parameters remain.
125 "https://docs.google.com/feeds/default/private/full/XXX/contents"
126 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
127 "&max-results=500&include-installed-apps=true",
128 url_generator_
.GenerateResourceListUrl(GURL(), // override_url,
129 0, // start_changestamp,
130 std::string(), // search_string,
131 "XXX" // directory resource ID
134 // With a non-empty override_url provided, the base URL is changed, but
135 // the default parameters remain. Note that start-index should not be
137 EXPECT_EQ("http://example.com/"
138 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true"
139 "&include-shared=true&max-results=500&include-installed-apps=true",
140 url_generator_
.GenerateResourceListUrl(
141 GURL("http://example.com/?start-index=123"), // override_url,
142 100, // start_changestamp,
143 std::string(), // search_string,
144 "XXX" // directory resource ID
148 TEST_F(GDataWapiUrlGeneratorTest
, GenerateEditUrl
) {
150 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
152 url_generator_
.GenerateEditUrl("XXX").spec());
155 TEST_F(GDataWapiUrlGeneratorTest
, GenerateEditUrlWithoutParams
) {
157 "https://docs.google.com/feeds/default/private/full/XXX",
158 url_generator_
.GenerateEditUrlWithoutParams("XXX").spec());
161 TEST_F(GDataWapiUrlGeneratorTest
, GenerateContentUrl
) {
163 "https://docs.google.com/feeds/default/private/full/"
164 "folder%3Aroot/contents?v=3&alt=json&showroot=true",
165 url_generator_
.GenerateContentUrl("folder:root").spec());
168 TEST_F(GDataWapiUrlGeneratorTest
, GenerateResourceUrlForRemoval
) {
170 "https://docs.google.com/feeds/default/private/full/"
171 "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json&showroot=true",
172 url_generator_
.GenerateResourceUrlForRemoval(
173 "folder:root", "file:ABCDE").spec());
176 TEST_F(GDataWapiUrlGeneratorTest
, GenerateInitiateUploadNewFileUrl
) {
178 "https://docs.google.com/feeds/upload/create-session/default/private/"
179 "full/folder%3Aabcde/contents?convert=false&v=3&alt=json&showroot=true",
180 url_generator_
.GenerateInitiateUploadNewFileUrl("folder:abcde").spec());
183 TEST_F(GDataWapiUrlGeneratorTest
, GenerateInitiateUploadExistingFileUrl
) {
185 "https://docs.google.com/feeds/upload/create-session/default/private/"
186 "full/file%3Aresource_id?convert=false&v=3&alt=json&showroot=true",
187 url_generator_
.GenerateInitiateUploadExistingFileUrl(
188 "file:resource_id").spec());
191 TEST_F(GDataWapiUrlGeneratorTest
, GenerateResourceListRootUrl
) {
193 "https://docs.google.com/feeds/default/private/full?v=3&alt=json"
195 url_generator_
.GenerateResourceListRootUrl().spec());
198 TEST_F(GDataWapiUrlGeneratorTest
, GenerateAccountMetadataUrl
) {
199 // Include installed apps.
201 "https://docs.google.com/feeds/metadata/default"
202 "?v=3&alt=json&showroot=true&include-installed-apps=true",
203 url_generator_
.GenerateAccountMetadataUrl(true).spec());
205 // Exclude installed apps.
207 "https://docs.google.com/feeds/metadata/default?v=3&alt=json"
209 url_generator_
.GenerateAccountMetadataUrl(false).spec());
212 } // namespace google_apis