Fix build break
[chromium-blink-merge.git] / chrome / browser / google_apis / gdata_wapi_url_generator_unittest.cc
blobde806990457a328c1de0f8ececc5ba530c646cbf
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 {
13 public:
14 GDataWapiUrlGeneratorTest()
15 : url_generator_(GURL(GDataWapiUrlGenerator::kBaseUrlForProduction)) {
18 protected:
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) {
35 EXPECT_EQ(
36 "http://www.example.com/?v=3&alt=json&showroot=true&"
37 "showfolders=true"
38 "&include-shared=true"
39 "&max-results=100"
40 "&include-installed-apps=true",
41 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
42 100, // num_items_to_fetch
43 0, // changestamp
44 std::string() // search_string
45 ).spec());
46 EXPECT_EQ(
47 "http://www.example.com/?v=3&alt=json&showroot=true&"
48 "showfolders=true"
49 "&include-shared=true"
50 "&max-results=100"
51 "&include-installed-apps=true"
52 "&start-index=123",
53 GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
54 100, // num_items_to_fetch
55 123, // changestamp
56 std::string() // search_string
57 ).spec());
58 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
59 "showfolders=true"
60 "&include-shared=true"
61 "&max-results=100"
62 "&include-installed-apps=true"
63 "&start-index=123"
64 "&q=%22foo+bar%22",
65 GDataWapiUrlGenerator::AddFeedUrlParams(
66 GURL("http://www.example.com"),
67 100, // num_items_to_fetch
68 123, // changestamp
69 "\"foo bar\"" // search_string
70 ).spec());
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
83 ).spec());
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
95 ).spec());
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"
102 "&start-index=100",
103 url_generator_.GenerateResourceListUrl(
104 GURL(), // override_url,
105 100, // start_changestamp,
106 std::string(), // search_string,
107 std::string() // directory resource ID
108 ).spec());
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
120 ).spec());
122 // With a non-empty directory resource ID provided, the base URL is
123 // changed, but the default parameters remain.
124 EXPECT_EQ(
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
132 ).spec());
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
136 // overridden.
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
145 ).spec());
148 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) {
149 EXPECT_EQ(
150 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
151 "&showroot=true",
152 url_generator_.GenerateEditUrl("XXX").spec());
155 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) {
156 EXPECT_EQ(
157 "https://docs.google.com/feeds/default/private/full/XXX",
158 url_generator_.GenerateEditUrlWithoutParams("XXX").spec());
161 TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) {
162 EXPECT_EQ(
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) {
169 EXPECT_EQ(
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) {
177 EXPECT_EQ(
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) {
184 EXPECT_EQ(
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) {
192 EXPECT_EQ(
193 "https://docs.google.com/feeds/default/private/full?v=3&alt=json"
194 "&showroot=true",
195 url_generator_.GenerateResourceListRootUrl().spec());
198 TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) {
199 // Include installed apps.
200 EXPECT_EQ(
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.
206 EXPECT_EQ(
207 "https://docs.google.com/feeds/metadata/default?v=3&alt=json"
208 "&showroot=true",
209 url_generator_.GenerateAccountMetadataUrl(false).spec());
212 } // namespace google_apis