Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/google_apis/gdata_wapi_url_generator_unittest.cc

Issue 12585003: drive: Add showroot=true to WAPI feed URLs and ignore "no parent" entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 5 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
6 6
7 #include "googleurl/src/gurl.h" 7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace google_apis { 10 namespace google_apis {
11 11
12 class GDataWapiUrlGeneratorTest : public testing::Test { 12 class GDataWapiUrlGeneratorTest : public testing::Test {
13 public: 13 public:
14 GDataWapiUrlGeneratorTest() 14 GDataWapiUrlGeneratorTest()
15 : url_generator_(GURL(GDataWapiUrlGenerator::kBaseUrlForProduction)) { 15 : url_generator_(GURL(GDataWapiUrlGenerator::kBaseUrlForProduction)) {
16 } 16 }
17 17
18 protected: 18 protected:
19 GDataWapiUrlGenerator url_generator_; 19 GDataWapiUrlGenerator url_generator_;
20 }; 20 };
21 21
22 TEST_F(GDataWapiUrlGeneratorTest, AddStandardUrlParams) { 22 TEST_F(GDataWapiUrlGeneratorTest, AddStandardUrlParams) {
23 EXPECT_EQ("http://www.example.com/?v=3&alt=json", 23 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true",
24 GDataWapiUrlGenerator::AddStandardUrlParams( 24 GDataWapiUrlGenerator::AddStandardUrlParams(
25 GURL("http://www.example.com")).spec()); 25 GURL("http://www.example.com")).spec());
26 } 26 }
27 27
28 TEST_F(GDataWapiUrlGeneratorTest, AddInitiateUploadUrlParams) { 28 TEST_F(GDataWapiUrlGeneratorTest, AddInitiateUploadUrlParams) {
29 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json", 29 EXPECT_EQ("http://www.example.com/?convert=false&v=3&alt=json&showroot=true",
30 GDataWapiUrlGenerator::AddInitiateUploadUrlParams( 30 GDataWapiUrlGenerator::AddInitiateUploadUrlParams(
31 GURL("http://www.example.com")).spec()); 31 GURL("http://www.example.com")).spec());
32 } 32 }
33 33
34 TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) { 34 TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
35 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" 35 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
36 "showfolders=true"
36 "&max-results=100" 37 "&max-results=100"
37 "&include-installed-apps=true", 38 "&include-installed-apps=true",
38 GDataWapiUrlGenerator::AddFeedUrlParams( 39 GDataWapiUrlGenerator::AddFeedUrlParams(
39 GURL("http://www.example.com"), 40 GURL("http://www.example.com"),
40 100, // num_items_to_fetch 41 100, // num_items_to_fetch
41 0, // changestamp 42 0, // changestamp
42 "" // search_string 43 "" // search_string
43 ).spec()); 44 ).spec());
44 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" 45 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
46 "showfolders=true"
45 "&max-results=100" 47 "&max-results=100"
46 "&include-installed-apps=true" 48 "&include-installed-apps=true"
47 "&start-index=123", 49 "&start-index=123",
48 GDataWapiUrlGenerator::AddFeedUrlParams( 50 GDataWapiUrlGenerator::AddFeedUrlParams(
49 GURL("http://www.example.com"), 51 GURL("http://www.example.com"),
50 100, // num_items_to_fetch 52 100, // num_items_to_fetch
51 123, // changestamp 53 123, // changestamp
52 "" // search_string 54 "" // search_string
53 ).spec()); 55 ).spec());
54 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showfolders=true" 56 EXPECT_EQ("http://www.example.com/?v=3&alt=json&showroot=true&"
57 "showfolders=true"
55 "&max-results=100" 58 "&max-results=100"
56 "&include-installed-apps=true" 59 "&include-installed-apps=true"
57 "&start-index=123" 60 "&start-index=123"
58 "&q=%22foo+bar%22", 61 "&q=%22foo+bar%22",
59 GDataWapiUrlGenerator::AddFeedUrlParams( 62 GDataWapiUrlGenerator::AddFeedUrlParams(
60 GURL("http://www.example.com"), 63 GURL("http://www.example.com"),
61 100, // num_items_to_fetch 64 100, // num_items_to_fetch
62 123, // changestamp 65 123, // changestamp
63 "\"foo bar\"" // search_string 66 "\"foo bar\"" // search_string
64 ).spec()); 67 ).spec());
65 } 68 }
66 69
67 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) { 70 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
68 // This is the very basic URL for the GetResourceList operation. 71 // This is the very basic URL for the GetResourceList operation.
69 EXPECT_EQ( 72 EXPECT_EQ(
70 "https://docs.google.com/feeds/default/private/full/-/mine" 73 "https://docs.google.com/feeds/default/private/full/-/mine"
71 "?v=3&alt=json&showfolders=true&max-results=500" 74 "?v=3&alt=json&showroot=true&showfolders=true&max-results=500"
72 "&include-installed-apps=true", 75 "&include-installed-apps=true",
73 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 76 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
74 0, // start_changestamp, 77 0, // start_changestamp,
75 "", // search_string, 78 "", // search_string,
76 false, // shared_with_me, 79 false, // shared_with_me,
77 "" // directory resource ID 80 "" // directory resource ID
78 ).spec()); 81 ).spec());
79 82
80 // With an override URL provided, the base URL is changed, but the default 83 // With an override URL provided, the base URL is changed, but the default
81 // parameters remain as-is. 84 // parameters remain as-is.
82 EXPECT_EQ( 85 EXPECT_EQ(
83 "http://localhost/" 86 "http://localhost/"
84 "?v=3&alt=json&showfolders=true&max-results=500" 87 "?v=3&alt=json&showroot=true&showfolders=true&max-results=500"
85 "&include-installed-apps=true", 88 "&include-installed-apps=true",
86 url_generator_.GenerateResourceListUrl( 89 url_generator_.GenerateResourceListUrl(
87 GURL("http://localhost/"), // override_url, 90 GURL("http://localhost/"), // override_url,
88 0, // start_changestamp, 91 0, // start_changestamp,
89 "", // search_string, 92 "", // search_string,
90 false, // shared_with_me, 93 false, // shared_with_me,
91 "" // directory resource ID 94 "" // directory resource ID
92 ).spec()); 95 ).spec());
93 96
94 // With a non-zero start_changestamp provided, the base URL is changed from 97 // With a non-zero start_changestamp provided, the base URL is changed from
95 // "full/-/mine" to "changes", and "start-index" parameter is added. 98 // "full/-/mine" to "changes", and "start-index" parameter is added.
96 EXPECT_EQ( 99 EXPECT_EQ(
97 "https://docs.google.com/feeds/default/private/changes" 100 "https://docs.google.com/feeds/default/private/changes"
98 "?v=3&alt=json&showfolders=true&max-results=500" 101 "?v=3&alt=json&showroot=true&showfolders=true&max-results=500"
99 "&include-installed-apps=true" 102 "&include-installed-apps=true"
100 "&start-index=100", 103 "&start-index=100",
101 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 104 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
102 100, // start_changestamp, 105 100, // start_changestamp,
103 "", // search_string, 106 "", // search_string,
104 false, // shared_with_me, 107 false, // shared_with_me,
105 "" // directory resource ID 108 "" // directory resource ID
106 ).spec()); 109 ).spec());
107 110
108 // With a non-empty search string provided, "max-results" value is changed, 111 // With a non-empty search string provided, "max-results" value is changed,
109 // and "q" parameter is added. 112 // and "q" parameter is added.
110 EXPECT_EQ( 113 EXPECT_EQ(
111 "https://docs.google.com/feeds/default/private/full/-/mine" 114 "https://docs.google.com/feeds/default/private/full/-/mine"
112 "?v=3&alt=json&showfolders=true&max-results=50" 115 "?v=3&alt=json&showroot=true&showfolders=true&max-results=50"
113 "&include-installed-apps=true&q=foo", 116 "&include-installed-apps=true&q=foo",
114 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 117 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
115 0, // start_changestamp, 118 0, // start_changestamp,
116 "foo", // search_string, 119 "foo", // search_string,
117 false, // shared_with_me, 120 false, // shared_with_me,
118 "" // directory resource ID 121 "" // directory resource ID
119 ).spec()); 122 ).spec());
120 123
121 // With shared_with_me parameter set to true, the base URL is changed, but 124 // With shared_with_me parameter set to true, the base URL is changed, but
122 // the default parameters remain. 125 // the default parameters remain.
123 EXPECT_EQ( 126 EXPECT_EQ(
124 "https://docs.google.com/feeds/default/private/full/-/shared-with-me" 127 "https://docs.google.com/feeds/default/private/full/-/shared-with-me"
125 "?v=3&alt=json&showfolders=true&max-results=500" 128 "?v=3&alt=json&showroot=true&showfolders=true&max-results=500"
126 "&include-installed-apps=true", 129 "&include-installed-apps=true",
127 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 130 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
128 0, // start_changestamp, 131 0, // start_changestamp,
129 "", // search_string, 132 "", // search_string,
130 true, // shared_with_me, 133 true, // shared_with_me,
131 "" // directory resource ID 134 "" // directory resource ID
132 ).spec()); 135 ).spec());
133 136
134 // With a non-empty directory resource ID provided, the base URL is 137 // With a non-empty directory resource ID provided, the base URL is
135 // changed, but the default parameters remain. 138 // changed, but the default parameters remain.
136 EXPECT_EQ( 139 EXPECT_EQ(
137 "https://docs.google.com/feeds/default/private/full/XXX/contents/-/mine" 140 "https://docs.google.com/feeds/default/private/full/XXX/contents/-/mine"
138 "?v=3&alt=json&showfolders=true&max-results=500" 141 "?v=3&alt=json&showroot=true&showfolders=true&max-results=500"
139 "&include-installed-apps=true", 142 "&include-installed-apps=true",
140 url_generator_.GenerateResourceListUrl(GURL(), // override_url, 143 url_generator_.GenerateResourceListUrl(GURL(), // override_url,
141 0, // start_changestamp, 144 0, // start_changestamp,
142 "", // search_string, 145 "", // search_string,
143 false, // shared_with_me, 146 false, // shared_with_me,
144 "XXX" // directory resource ID 147 "XXX" // directory resource ID
145 ).spec()); 148 ).spec());
146 149
147 // With a non-empty override_url provided, the base URL is changed, but 150 // With a non-empty override_url provided, the base URL is changed, but
148 // the default parameters remain. Note that start-index should not be 151 // the default parameters remain. Note that start-index should not be
149 // overridden. 152 // overridden.
150 EXPECT_EQ( 153 EXPECT_EQ(
151 "http://example.com/" 154 "http://example.com/"
152 "?start-index=123&v=3&alt=json&showfolders=true&max-results=500" 155 "?start-index=123&v=3&alt=json&showroot=true&showfolders=true"
153 "&include-installed-apps=true", 156 "&max-results=500&include-installed-apps=true",
154 url_generator_.GenerateResourceListUrl( 157 url_generator_.GenerateResourceListUrl(
155 GURL("http://example.com/?start-index=123"), // override_url, 158 GURL("http://example.com/?start-index=123"), // override_url,
156 100, // start_changestamp, 159 100, // start_changestamp,
157 "", // search_string, 160 "", // search_string,
158 false, // shared_with_me, 161 false, // shared_with_me,
159 "XXX" // directory resource ID 162 "XXX" // directory resource ID
160 ).spec()); 163 ).spec());
161 } 164 }
162 165
163 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) { 166 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrl) {
164 EXPECT_EQ( 167 EXPECT_EQ(
165 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json", 168 "https://docs.google.com/feeds/default/private/full/XXX?v=3&alt=json"
169 "&showroot=true",
166 url_generator_.GenerateEditUrl("XXX").spec()); 170 url_generator_.GenerateEditUrl("XXX").spec());
167 } 171 }
168 172
169 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) { 173 TEST_F(GDataWapiUrlGeneratorTest, GenerateEditUrlWithoutParams) {
170 EXPECT_EQ( 174 EXPECT_EQ(
171 "https://docs.google.com/feeds/default/private/full/XXX", 175 "https://docs.google.com/feeds/default/private/full/XXX",
172 url_generator_.GenerateEditUrlWithoutParams("XXX").spec()); 176 url_generator_.GenerateEditUrlWithoutParams("XXX").spec());
173 } 177 }
174 178
175 TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) { 179 TEST_F(GDataWapiUrlGeneratorTest, GenerateContentUrl) {
176 EXPECT_EQ( 180 EXPECT_EQ(
177 "https://docs.google.com/feeds/default/private/full/" 181 "https://docs.google.com/feeds/default/private/full/"
178 "folder%3Aroot/contents?v=3&alt=json", 182 "folder%3Aroot/contents?v=3&alt=json&showroot=true",
179 url_generator_.GenerateContentUrl("folder:root").spec()); 183 url_generator_.GenerateContentUrl("folder:root").spec());
180 } 184 }
181 185
182 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) { 186 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceUrlForRemoval) {
183 EXPECT_EQ( 187 EXPECT_EQ(
184 "https://docs.google.com/feeds/default/private/full/" 188 "https://docs.google.com/feeds/default/private/full/"
185 "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json", 189 "folder%3Aroot/contents/file%3AABCDE?v=3&alt=json&showroot=true",
186 url_generator_.GenerateResourceUrlForRemoval( 190 url_generator_.GenerateResourceUrlForRemoval(
187 "folder:root", "file:ABCDE").spec()); 191 "folder:root", "file:ABCDE").spec());
188 } 192 }
189 193
190 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadNewFileUrl) { 194 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadNewFileUrl) {
191 EXPECT_EQ( 195 EXPECT_EQ(
192 "https://docs.google.com/feeds/upload/create-session/default/private/" 196 "https://docs.google.com/feeds/upload/create-session/default/private/"
193 "full/folder%3Aabcde/contents?convert=false&v=3&alt=json", 197 "full/folder%3Aabcde/contents?convert=false&v=3&alt=json&showroot=true",
194 url_generator_.GenerateInitiateUploadNewFileUrl("folder:abcde").spec()); 198 url_generator_.GenerateInitiateUploadNewFileUrl("folder:abcde").spec());
195 } 199 }
196 200
197 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadExistingFileUrl) { 201 TEST_F(GDataWapiUrlGeneratorTest, GenerateInitiateUploadExistingFileUrl) {
198 EXPECT_EQ( 202 EXPECT_EQ(
199 "https://docs.google.com/feeds/upload/create-session/default/private/" 203 "https://docs.google.com/feeds/upload/create-session/default/private/"
200 "full/file%3Aresource_id?convert=false&v=3&alt=json", 204 "full/file%3Aresource_id?convert=false&v=3&alt=json&showroot=true",
201 url_generator_.GenerateInitiateUploadExistingFileUrl( 205 url_generator_.GenerateInitiateUploadExistingFileUrl(
202 "file:resource_id").spec()); 206 "file:resource_id").spec());
203 } 207 }
204 208
205 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) { 209 TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListRootUrl) {
206 EXPECT_EQ( 210 EXPECT_EQ(
207 "https://docs.google.com/feeds/default/private/full?v=3&alt=json", 211 "https://docs.google.com/feeds/default/private/full?v=3&alt=json"
212 "&showroot=true",
208 url_generator_.GenerateResourceListRootUrl().spec()); 213 url_generator_.GenerateResourceListRootUrl().spec());
209 } 214 }
210 215
211 TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) { 216 TEST_F(GDataWapiUrlGeneratorTest, GenerateAccountMetadataUrl) {
212 // Include installed apps. 217 // Include installed apps.
213 EXPECT_EQ( 218 EXPECT_EQ(
214 "https://docs.google.com/feeds/metadata/default" 219 "https://docs.google.com/feeds/metadata/default"
215 "?v=3&alt=json&include-installed-apps=true", 220 "?v=3&alt=json&showroot=true&include-installed-apps=true",
216 url_generator_.GenerateAccountMetadataUrl(true).spec()); 221 url_generator_.GenerateAccountMetadataUrl(true).spec());
217 222
218 // Exclude installed apps. 223 // Exclude installed apps.
219 EXPECT_EQ( 224 EXPECT_EQ(
220 "https://docs.google.com/feeds/metadata/default?v=3&alt=json", 225 "https://docs.google.com/feeds/metadata/default?v=3&alt=json"
226 "&showroot=true",
221 url_generator_.GenerateAccountMetadataUrl(false).spec()); 227 url_generator_.GenerateAccountMetadataUrl(false).spec());
222 } 228 }
223 229
224 } // namespace google_apis 230 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698