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 "testing/gtest/include/gtest/gtest.h"
10 namespace google_apis {
12 class GDataWapiUrlGeneratorTest : public testing::Test {
14 GDataWapiUrlGeneratorTest()
16 GURL(GDataWapiUrlGenerator::kBaseUrlForProduction),
17 GURL(GDataWapiUrlGenerator::kBaseDownloadUrlForProduction)) {
21 GDataWapiUrlGenerator url_generator_;
24 TEST_F(GDataWapiUrlGeneratorTest, AddStandardUrlParams) {
25 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true",
26 GDataWapiUrlGenerator::AddStandardUrlParams(
27 GURL("http://www.example.com")).spec());
30 TEST_F(GDataWapiUrlGeneratorTest, AddInitiateUploadUrlParams) {
31 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true",
32 GDataWapiUrlGenerator::AddInitiateUploadUrlParams(
33 GURL("http://www.example.com")).spec());
36 TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
38 "http://www.example.com/?v=3&alt=json&showroot=true&"
40 "&include-shared=true"
42 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
43 100 // num_items_to_fetch
47 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
48 // This is the very basic URL for the GetResourceList request.
49 EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
50 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
52 url_generator_.GenerateResourceListUrl(
53 GURL(), // override_url,
54 0, // start_changestamp,
55 std::string(), // search_string,
56 std::string() // directory resource ID
59 // With an override URL provided, the base URL is changed, but the default
60 // parameters remain as-is.
61 EXPECT_EQ("http://localhost/"
62 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
64 url_generator_.GenerateResourceListUrl(
65 GURL("http://localhost/"), // override_url,
66 0, // start_changestamp,
67 std::string(), // search_string,
68 std::string() // directory resource ID
71 // With a non-zero start_changestamp provided, the base URL is changed from
72 // "full" to "changes", and "start-index" parameter is added.
73 EXPECT_EQ("https://docs.google.com/feeds/default/private/changes"
74 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
75 "&max-results=500&start-index=100",
76 url_generator_.GenerateResourceListUrl(
77 GURL(), // override_url,
78 100, // start_changestamp,
79 std::string(), // search_string,
80 std::string() // directory resource ID
83 // With a non-empty search string provided, "max-results" value is changed,
84 // and "q" parameter is added.
85 EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
86 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
87 "&max-results=50&q=foo",
88 url_generator_.GenerateResourceListUrl(
89 GURL(), // override_url,
90 0, // start_changestamp,
91 "foo", // search_string,
92 std::string() // directory resource ID
95 // With a non-empty directory resource ID provided, the base URL is
96 // changed, but the default parameters remain.
98 "https://docs.google.com/feeds/default/private/full/XXX/contents"
99 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
101 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
102 0, // start_changestamp,
103 std::string(), // search_string,
104 "XXX" // directory resource ID
107 // With a non-empty override_url provided, the base URL is changed, but
108 // the default parameters remain. Note that start-index should not be
110 EXPECT_EQ("http://example.com/"
111 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true"
112 "&include-shared=true&max-results=500",
113 url_generator_.GenerateResourceListUrl(
114 GURL("http://example.com/?start-index=123"), // override_url,
115 100, // start_changestamp,
116 std::string(), // search_string,
117 "XXX" // directory resource ID
121 TEST_F(GDataWapiUrlGeneratorTest, GenerateSearchByTitleUrl) {
123 "https://docs.google.com/feeds/default/private/full"
124 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
125 "&max-results=500&title=search-title&title-exact=true",
126 url_generator_.GenerateSearchByTitleUrl(
127 "search-title", std::string()).spec());
130 "https://docs.google.com/feeds/default/private/full/XXX/contents"
131 "?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
132 "&max-results=500&title=search-title&title-exact=true",
133 url_generator_.GenerateSearchByTitleUrl(
134 "search-title", "XXX").spec());
137 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) {
139 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
141 url_generator_.GenerateEditUrl("XXX").spec());
144 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) {
146 "https://docs.google.com/feeds/default/private/full/XXX",
147 url_generator_.GenerateEditUrlWithoutParams("XXX").spec());
150 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithEmbedOrigin) {
152 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
153 "&showroot=true&embedOrigin=chrome-extension%3A%2F%2Ftest",
154 url_generator_.GenerateEditUrlWithEmbedOrigin(
156 GURL("chrome-extension://test")).spec());
158 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
160 url_generator_.GenerateEditUrlWithEmbedOrigin(
165 TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) {
167 "https://docs.google.com/feeds/default/private/full/"
168 "folder%3Aroot/contents?v=3&alt=json&showroot=true",
169 url_generator_.GenerateContentUrl("folder:root").spec());
172 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) {
174 "https://docs.google.com/feeds/default/private/full/"
175 "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json&showroot=true",
176 url_generator_.GenerateResourceUrlForRemoval(
177 "folder:root", "file:ABCDE").spec());
180 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadNewFileUrl) {
182 "https://docs.google.com/feeds/upload/create-session/default/private/"
183 "full/folder%3Aabcde/contents?convert=false&v=3&alt=json&showroot=true",
184 url_generator_.GenerateInitiateUploadNewFileUrl("folder:abcde").spec());
187 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadExistingFileUrl) {
189 "https://docs.google.com/feeds/upload/create-session/default/private/"
190 "full/file%3Aresource_id?convert=false&v=3&alt=json&showroot=true",
191 url_generator_.GenerateInitiateUploadExistingFileUrl(
192 "file:resource_id").spec());
195 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) {
197 "https://docs.google.com/feeds/default/private/full?v=3&alt=json"
199 url_generator_.GenerateResourceListRootUrl().spec());
202 TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) {
203 // Include installed apps.
205 "https://docs.google.com/feeds/metadata/default"
206 "?v=3&alt=json&showroot=true&include-installed-apps=true",
207 url_generator_.GenerateAccountMetadataUrl(true).spec());
209 // Exclude installed apps.
211 "https://docs.google.com/feeds/metadata/default?v=3&alt=json"
213 url_generator_.GenerateAccountMetadataUrl(false).spec());
216 TEST_F(GDataWapiUrlGeneratorTest, GenerateDownloadFileUrl) {
218 "https://www.googledrive.com/host/resourceId",
219 url_generator_.GenerateDownloadFileUrl("file:resourceId").spec());
222 } // namespace google_apis